@aspan/sdk 0.4.3 → 0.4.5
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.d.mts +130 -7
- package/dist/index.d.ts +130 -7
- package/dist/index.js +322 -9
- package/dist/index.mjs +322 -9
- package/package.json +1 -1
- package/src/__tests__/read-client.test.ts +212 -0
- package/src/abi/diamond.ts +45 -3
- package/src/abi/sApUSD.ts +36 -0
- package/src/client.ts +182 -6
- package/src/index.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -463,6 +463,13 @@ var DiamondABI = [
|
|
|
463
463
|
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
464
464
|
stateMutability: "view"
|
|
465
465
|
},
|
|
466
|
+
{
|
|
467
|
+
type: "function",
|
|
468
|
+
name: "setSApUSD",
|
|
469
|
+
inputs: [{ name: "_sApUSD", type: "address", internalType: "address" }],
|
|
470
|
+
outputs: [],
|
|
471
|
+
stateMutability: "nonpayable"
|
|
472
|
+
},
|
|
466
473
|
{
|
|
467
474
|
type: "function",
|
|
468
475
|
name: "getStabilityPool",
|
|
@@ -484,6 +491,25 @@ var DiamondABI = [
|
|
|
484
491
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
485
492
|
stateMutability: "view"
|
|
486
493
|
},
|
|
494
|
+
{
|
|
495
|
+
type: "function",
|
|
496
|
+
name: "getAllFeeTiers",
|
|
497
|
+
inputs: [],
|
|
498
|
+
outputs: [{
|
|
499
|
+
name: "",
|
|
500
|
+
type: "tuple[]",
|
|
501
|
+
internalType: "struct LibAppStorage.FeeTier[]",
|
|
502
|
+
components: [
|
|
503
|
+
{ name: "minCR", type: "uint256", internalType: "uint256" },
|
|
504
|
+
{ name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
|
|
505
|
+
{ name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
|
|
506
|
+
{ name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
|
|
507
|
+
{ name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
|
|
508
|
+
{ name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
|
|
509
|
+
]
|
|
510
|
+
}],
|
|
511
|
+
stateMutability: "view"
|
|
512
|
+
},
|
|
487
513
|
{
|
|
488
514
|
type: "function",
|
|
489
515
|
name: "getFeeTier",
|
|
@@ -592,11 +618,27 @@ var DiamondABI = [
|
|
|
592
618
|
},
|
|
593
619
|
{
|
|
594
620
|
type: "function",
|
|
595
|
-
name: "
|
|
596
|
-
inputs: [
|
|
597
|
-
|
|
621
|
+
name: "cleanVaultXBNB",
|
|
622
|
+
inputs: [
|
|
623
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" },
|
|
624
|
+
{ name: "_minApUSDOut", type: "uint256", internalType: "uint256" }
|
|
625
|
+
],
|
|
626
|
+
outputs: [
|
|
627
|
+
{ name: "apUSDMinted", type: "uint256", internalType: "uint256" }
|
|
628
|
+
],
|
|
598
629
|
stateMutability: "nonpayable"
|
|
599
630
|
},
|
|
631
|
+
{
|
|
632
|
+
type: "function",
|
|
633
|
+
name: "previewCleanVaultXBNB",
|
|
634
|
+
inputs: [
|
|
635
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" }
|
|
636
|
+
],
|
|
637
|
+
outputs: [
|
|
638
|
+
{ name: "apUSDOut", type: "uint256", internalType: "uint256" }
|
|
639
|
+
],
|
|
640
|
+
stateMutability: "view"
|
|
641
|
+
},
|
|
600
642
|
// ============ StabilityModeFacet Events ============
|
|
601
643
|
{
|
|
602
644
|
type: "event",
|
|
@@ -661,6 +703,138 @@ var DiamondABI = [
|
|
|
661
703
|
}
|
|
662
704
|
];
|
|
663
705
|
|
|
706
|
+
// src/abi/sApUSD.ts
|
|
707
|
+
var SApUSDABI = [
|
|
708
|
+
// ============ View Functions ============
|
|
709
|
+
{
|
|
710
|
+
type: "function",
|
|
711
|
+
name: "totalAssets",
|
|
712
|
+
inputs: [],
|
|
713
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
714
|
+
stateMutability: "view"
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
type: "function",
|
|
718
|
+
name: "totalSupply",
|
|
719
|
+
inputs: [],
|
|
720
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
721
|
+
stateMutability: "view"
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
type: "function",
|
|
725
|
+
name: "balanceOf",
|
|
726
|
+
inputs: [{ name: "account", type: "address", internalType: "address" }],
|
|
727
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
728
|
+
stateMutability: "view"
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
type: "function",
|
|
732
|
+
name: "previewRedeemMulti",
|
|
733
|
+
inputs: [
|
|
734
|
+
{ name: "shares", type: "uint256", internalType: "uint256" }
|
|
735
|
+
],
|
|
736
|
+
outputs: [
|
|
737
|
+
{ name: "assets", type: "address[]", internalType: "address[]" },
|
|
738
|
+
{ name: "amounts", type: "uint256[]", internalType: "uint256[]" }
|
|
739
|
+
],
|
|
740
|
+
stateMutability: "view"
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
type: "function",
|
|
744
|
+
name: "hasStabilityConversion",
|
|
745
|
+
inputs: [],
|
|
746
|
+
outputs: [
|
|
747
|
+
{ name: "hasXBNB", type: "bool", internalType: "bool" },
|
|
748
|
+
{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }
|
|
749
|
+
],
|
|
750
|
+
stateMutability: "view"
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
type: "function",
|
|
754
|
+
name: "totalValue",
|
|
755
|
+
inputs: [],
|
|
756
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
757
|
+
stateMutability: "view"
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
type: "function",
|
|
761
|
+
name: "underlyingBalances",
|
|
762
|
+
inputs: [{ name: "_user", type: "address", internalType: "address" }],
|
|
763
|
+
outputs: [
|
|
764
|
+
{ name: "apUSDBalance", type: "uint256", internalType: "uint256" },
|
|
765
|
+
{ name: "xBNBBalance", type: "uint256", internalType: "uint256" }
|
|
766
|
+
],
|
|
767
|
+
stateMutability: "view"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
type: "function",
|
|
771
|
+
name: "xBNBToApUSDRate",
|
|
772
|
+
inputs: [],
|
|
773
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
774
|
+
stateMutability: "view"
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
type: "function",
|
|
778
|
+
name: "exchangeRate",
|
|
779
|
+
inputs: [],
|
|
780
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
781
|
+
stateMutability: "view"
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
type: "function",
|
|
785
|
+
name: "previewCleanXBNB",
|
|
786
|
+
inputs: [
|
|
787
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" },
|
|
788
|
+
{ name: "_router", type: "address", internalType: "address" },
|
|
789
|
+
{ name: "_path", type: "address[]", internalType: "address[]" }
|
|
790
|
+
],
|
|
791
|
+
outputs: [{ name: "expectedApUSD", type: "uint256", internalType: "uint256" }],
|
|
792
|
+
stateMutability: "view"
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
type: "function",
|
|
796
|
+
name: "KEEPER_ROLE",
|
|
797
|
+
inputs: [],
|
|
798
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
799
|
+
stateMutability: "view"
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
type: "function",
|
|
803
|
+
name: "hasRole",
|
|
804
|
+
inputs: [
|
|
805
|
+
{ name: "role", type: "bytes32", internalType: "bytes32" },
|
|
806
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
807
|
+
],
|
|
808
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
809
|
+
stateMutability: "view"
|
|
810
|
+
},
|
|
811
|
+
// ============ Keeper Functions ============
|
|
812
|
+
{
|
|
813
|
+
type: "function",
|
|
814
|
+
name: "cleanXBNB",
|
|
815
|
+
inputs: [
|
|
816
|
+
{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" },
|
|
817
|
+
{ name: "_minApUSDOut", type: "uint256", internalType: "uint256" },
|
|
818
|
+
{ name: "_router", type: "address", internalType: "address" },
|
|
819
|
+
{ name: "_path", type: "address[]", internalType: "address[]" },
|
|
820
|
+
{ name: "_deadline", type: "uint256", internalType: "uint256" }
|
|
821
|
+
],
|
|
822
|
+
outputs: [{ name: "apUSDReceived", type: "uint256", internalType: "uint256" }],
|
|
823
|
+
stateMutability: "nonpayable"
|
|
824
|
+
},
|
|
825
|
+
// ============ Events ============
|
|
826
|
+
{
|
|
827
|
+
type: "event",
|
|
828
|
+
name: "VaultCleaned",
|
|
829
|
+
inputs: [
|
|
830
|
+
{ name: "xBNBSold", type: "uint256", indexed: false, internalType: "uint256" },
|
|
831
|
+
{ name: "apUSDReceived", type: "uint256", indexed: false, internalType: "uint256" },
|
|
832
|
+
{ name: "keeper", type: "address", indexed: true, internalType: "address" }
|
|
833
|
+
],
|
|
834
|
+
anonymous: false
|
|
835
|
+
}
|
|
836
|
+
];
|
|
837
|
+
|
|
664
838
|
// src/client.ts
|
|
665
839
|
var pharosTestnet = {
|
|
666
840
|
id: 688689,
|
|
@@ -1054,6 +1228,19 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1054
1228
|
args: [user]
|
|
1055
1229
|
});
|
|
1056
1230
|
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Get user's underlying balances (apUSD + xBNB) from sApUSD vault
|
|
1233
|
+
*/
|
|
1234
|
+
async getBalanceMulti(user) {
|
|
1235
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
1236
|
+
const [apUSDBalance, xBNBBalance] = await this.publicClient.readContract({
|
|
1237
|
+
address: sApUSDAddress,
|
|
1238
|
+
abi: SApUSDABI,
|
|
1239
|
+
functionName: "underlyingBalances",
|
|
1240
|
+
args: [user]
|
|
1241
|
+
});
|
|
1242
|
+
return { apUSDBalance, xBNBBalance };
|
|
1243
|
+
}
|
|
1057
1244
|
async getUserStabilityPoolPosition(user) {
|
|
1058
1245
|
const [shares, balance] = await Promise.all([
|
|
1059
1246
|
this.getShares(user),
|
|
@@ -1119,6 +1306,32 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1119
1306
|
throw error;
|
|
1120
1307
|
}
|
|
1121
1308
|
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
1311
|
+
* @param shares Amount of sApUSD shares to redeem
|
|
1312
|
+
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
1313
|
+
*/
|
|
1314
|
+
async previewRedeemMulti(shares) {
|
|
1315
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
1316
|
+
const [result, conversion] = await Promise.all([
|
|
1317
|
+
this.publicClient.readContract({
|
|
1318
|
+
address: sApUSDAddress,
|
|
1319
|
+
abi: SApUSDABI,
|
|
1320
|
+
functionName: "previewRedeemMulti",
|
|
1321
|
+
args: [shares]
|
|
1322
|
+
}),
|
|
1323
|
+
this.publicClient.readContract({
|
|
1324
|
+
address: sApUSDAddress,
|
|
1325
|
+
abi: SApUSDABI,
|
|
1326
|
+
functionName: "hasStabilityConversion"
|
|
1327
|
+
})
|
|
1328
|
+
]);
|
|
1329
|
+
return {
|
|
1330
|
+
apUSD: result[1][0],
|
|
1331
|
+
xBNB: result[1][1],
|
|
1332
|
+
hasXBNB: conversion[0]
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1122
1335
|
async getPendingYield() {
|
|
1123
1336
|
try {
|
|
1124
1337
|
return await this.publicClient.readContract({
|
|
@@ -1272,6 +1485,93 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1272
1485
|
apUSDMintDisabled: result[5]
|
|
1273
1486
|
};
|
|
1274
1487
|
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Get all fee tiers
|
|
1490
|
+
* @returns Array of fee tiers sorted by minCR descending
|
|
1491
|
+
*/
|
|
1492
|
+
async getAllFeeTiers() {
|
|
1493
|
+
const result = await this.publicClient.readContract({
|
|
1494
|
+
address: this.diamondAddress,
|
|
1495
|
+
abi: DiamondABI,
|
|
1496
|
+
functionName: "getAllFeeTiers"
|
|
1497
|
+
});
|
|
1498
|
+
return result.map((tier) => ({
|
|
1499
|
+
minCR: tier.minCR,
|
|
1500
|
+
apUSDMintFee: tier.apUSDMintFee,
|
|
1501
|
+
apUSDRedeemFee: tier.apUSDRedeemFee,
|
|
1502
|
+
xBNBMintFee: tier.xBNBMintFee,
|
|
1503
|
+
xBNBRedeemFee: tier.xBNBRedeemFee,
|
|
1504
|
+
apUSDMintDisabled: tier.apUSDMintDisabled
|
|
1505
|
+
}));
|
|
1506
|
+
}
|
|
1507
|
+
/**
|
|
1508
|
+
* Get comprehensive vault (sApUSD) info for frontend display
|
|
1509
|
+
* @returns Vault state including TVL, exchange rate, xBNB status
|
|
1510
|
+
*/
|
|
1511
|
+
async getVaultInfo() {
|
|
1512
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
1513
|
+
const [totalSupply, totalAssets, exchangeRate, conversion] = await Promise.all([
|
|
1514
|
+
this.publicClient.readContract({
|
|
1515
|
+
address: sApUSDAddress,
|
|
1516
|
+
abi: SApUSDABI,
|
|
1517
|
+
functionName: "totalSupply"
|
|
1518
|
+
}),
|
|
1519
|
+
this.publicClient.readContract({
|
|
1520
|
+
address: sApUSDAddress,
|
|
1521
|
+
abi: SApUSDABI,
|
|
1522
|
+
functionName: "totalAssets"
|
|
1523
|
+
}),
|
|
1524
|
+
this.publicClient.readContract({
|
|
1525
|
+
address: sApUSDAddress,
|
|
1526
|
+
abi: SApUSDABI,
|
|
1527
|
+
functionName: "exchangeRate"
|
|
1528
|
+
}),
|
|
1529
|
+
this.publicClient.readContract({
|
|
1530
|
+
address: sApUSDAddress,
|
|
1531
|
+
abi: SApUSDABI,
|
|
1532
|
+
functionName: "hasStabilityConversion"
|
|
1533
|
+
})
|
|
1534
|
+
]);
|
|
1535
|
+
return {
|
|
1536
|
+
totalSupply,
|
|
1537
|
+
totalAssets,
|
|
1538
|
+
exchangeRate,
|
|
1539
|
+
hasXBNB: conversion[0],
|
|
1540
|
+
xBNBAmount: conversion[1]
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Get full protocol dashboard data in one call (for frontend overview page)
|
|
1545
|
+
* Batches all key metrics into a single multicall
|
|
1546
|
+
*/
|
|
1547
|
+
async getProtocolOverview() {
|
|
1548
|
+
const [cr, tvlBNB, tvlUSD, apUSD, xBNB, xPriceUSD, xPriceBNB, bnbPrice, fees, sm, staked] = await Promise.all([
|
|
1549
|
+
this.getCollateralRatio(),
|
|
1550
|
+
this.getTVLInBNB(),
|
|
1551
|
+
this.getTVLInUSD(),
|
|
1552
|
+
this.getApUSDSupply(),
|
|
1553
|
+
this.getXBNBSupply(),
|
|
1554
|
+
this.getXBNBPriceUSD(),
|
|
1555
|
+
this.getXBNBPriceBNB(),
|
|
1556
|
+
this.getBNBPriceUSD(),
|
|
1557
|
+
this.getCurrentFeeTier(),
|
|
1558
|
+
this.getStabilityMode(),
|
|
1559
|
+
this.getTotalStaked()
|
|
1560
|
+
]);
|
|
1561
|
+
return {
|
|
1562
|
+
collateralRatio: cr,
|
|
1563
|
+
tvlBNB,
|
|
1564
|
+
tvlUSD,
|
|
1565
|
+
apUSDSupply: apUSD,
|
|
1566
|
+
xBNBSupply: xBNB,
|
|
1567
|
+
xBNBPriceUSD: xPriceUSD,
|
|
1568
|
+
xBNBPriceBNB: xPriceBNB,
|
|
1569
|
+
bnbPriceUSD: bnbPrice,
|
|
1570
|
+
currentFees: fees,
|
|
1571
|
+
stabilityMode: sm,
|
|
1572
|
+
totalStaked: staked
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1275
1575
|
async getCurrentFeeTier() {
|
|
1276
1576
|
try {
|
|
1277
1577
|
const result = await this.publicClient.readContract({
|
|
@@ -1569,18 +1869,31 @@ var AspanClient = class extends AspanReadClient {
|
|
|
1569
1869
|
});
|
|
1570
1870
|
}
|
|
1571
1871
|
/**
|
|
1572
|
-
* Clean
|
|
1573
|
-
* @
|
|
1574
|
-
* @param
|
|
1872
|
+
* Clean xBNB from sApUSD vault by converting back to apUSD
|
|
1873
|
+
* @param xBNBAmount Amount of xBNB to clean
|
|
1874
|
+
* @param minApUSDOut Minimum apUSD to receive (slippage protection)
|
|
1575
1875
|
* @returns Transaction hash
|
|
1576
1876
|
*/
|
|
1577
|
-
async
|
|
1877
|
+
async cleanVaultXBNB(xBNBAmount, minApUSDOut = 0n) {
|
|
1578
1878
|
return this.walletClient.writeContract({
|
|
1579
1879
|
chain: this.chain,
|
|
1580
1880
|
account: this.walletClient.account,
|
|
1581
1881
|
address: this.diamondAddress,
|
|
1582
1882
|
abi: DiamondABI,
|
|
1583
|
-
functionName: "
|
|
1883
|
+
functionName: "cleanVaultXBNB",
|
|
1884
|
+
args: [xBNBAmount, minApUSDOut]
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Preview how much apUSD would be minted from cleaning xBNB
|
|
1889
|
+
* @param xBNBAmount Amount of xBNB to preview
|
|
1890
|
+
* @returns apUSD amount that would be minted
|
|
1891
|
+
*/
|
|
1892
|
+
async previewCleanVaultXBNB(xBNBAmount) {
|
|
1893
|
+
return this.publicClient.readContract({
|
|
1894
|
+
address: this.diamondAddress,
|
|
1895
|
+
abi: DiamondABI,
|
|
1896
|
+
functionName: "previewCleanVaultXBNB",
|
|
1584
1897
|
args: [xBNBAmount]
|
|
1585
1898
|
});
|
|
1586
1899
|
}
|
|
@@ -2494,7 +2807,7 @@ var BSC_ADDRESSES = {
|
|
|
2494
2807
|
router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6",
|
|
2495
2808
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
|
|
2496
2809
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
|
|
2497
|
-
sApUSD: "
|
|
2810
|
+
sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB",
|
|
2498
2811
|
// LSTs
|
|
2499
2812
|
slisBNB: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
|
|
2500
2813
|
asBNB: "0x77734e70b6E88b4d82fE632a168EDf6e700912b6",
|