@aspan/sdk 0.4.5 → 0.4.6
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/README.md +8 -0
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +23 -32
- package/dist/index.mjs +23 -32
- package/package.json +1 -1
- package/src/abi/diamond.ts +10 -0
- package/src/client.ts +17 -33
package/README.md
CHANGED
|
@@ -347,6 +347,13 @@ const hash = await client.deposit({ apUSDAmount: parseAmount("1000") });
|
|
|
347
347
|
const position = await client.getUserStabilityPoolPosition(account.address);
|
|
348
348
|
console.log("sApUSD Balance:", formatAmount(position.balance));
|
|
349
349
|
console.log("Earned:", formatAmount(position.balance - position.deposited));
|
|
350
|
+
|
|
351
|
+
// Preview withdrawal (supports dirty pools with apUSD + xBNB)
|
|
352
|
+
const preview = await client.previewRedeemMulti(position.shares);
|
|
353
|
+
console.log("Will receive apUSD:", formatAmount(preview.apUSD));
|
|
354
|
+
if (preview.hasXBNB) {
|
|
355
|
+
console.log("Will also receive xBNB:", formatAmount(preview.xBNB));
|
|
356
|
+
}
|
|
350
357
|
```
|
|
351
358
|
|
|
352
359
|
### 5. Quick Exit: apUSD/xBNB → USDT
|
|
@@ -539,6 +546,7 @@ console.log("Leverage:", formatAmount(stats.effectiveLeverage), "x");
|
|
|
539
546
|
| `redeemXBNB(params)` | Redeem xBNB for LST |
|
|
540
547
|
| `deposit(params)` | Deposit apUSD to stability pool |
|
|
541
548
|
| `withdraw(params)` | Withdraw from stability pool |
|
|
549
|
+
| `previewRedeemMulti(shares)` | Preview multi-asset withdrawal (apUSD + xBNB) |
|
|
542
550
|
| `harvestYield()` | Trigger yield distribution |
|
|
543
551
|
|
|
544
552
|
---
|
package/dist/index.d.mts
CHANGED
|
@@ -468,9 +468,9 @@ declare class AspanReadClient {
|
|
|
468
468
|
getExchangeRate(): Promise<bigint>;
|
|
469
469
|
getTotalStaked(): Promise<bigint>;
|
|
470
470
|
previewDeposit(assets: bigint): Promise<bigint>;
|
|
471
|
-
previewRedeem(shares: bigint): Promise<bigint>;
|
|
472
471
|
/**
|
|
473
472
|
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
473
|
+
* Replaces previewRedeem — works for both clean and dirty pools.
|
|
474
474
|
* @param shares Amount of sApUSD shares to redeem
|
|
475
475
|
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
476
476
|
*/
|
|
@@ -478,6 +478,8 @@ declare class AspanReadClient {
|
|
|
478
478
|
apUSD: bigint;
|
|
479
479
|
xBNB: bigint;
|
|
480
480
|
hasXBNB: boolean;
|
|
481
|
+
assets: Address[];
|
|
482
|
+
amounts: bigint[];
|
|
481
483
|
}>;
|
|
482
484
|
getPendingYield(): Promise<bigint>;
|
|
483
485
|
getTotalYieldGenerated(): Promise<bigint>;
|
|
@@ -1427,6 +1429,24 @@ declare const DiamondABI: readonly [{
|
|
|
1427
1429
|
readonly internalType: "uint256";
|
|
1428
1430
|
}];
|
|
1429
1431
|
readonly stateMutability: "view";
|
|
1432
|
+
}, {
|
|
1433
|
+
readonly type: "function";
|
|
1434
|
+
readonly name: "previewRedeemMulti";
|
|
1435
|
+
readonly inputs: readonly [{
|
|
1436
|
+
readonly name: "_shares";
|
|
1437
|
+
readonly type: "uint256";
|
|
1438
|
+
readonly internalType: "uint256";
|
|
1439
|
+
}];
|
|
1440
|
+
readonly outputs: readonly [{
|
|
1441
|
+
readonly name: "assets";
|
|
1442
|
+
readonly type: "address[]";
|
|
1443
|
+
readonly internalType: "address[]";
|
|
1444
|
+
}, {
|
|
1445
|
+
readonly name: "amounts";
|
|
1446
|
+
readonly type: "uint256[]";
|
|
1447
|
+
readonly internalType: "uint256[]";
|
|
1448
|
+
}];
|
|
1449
|
+
readonly stateMutability: "view";
|
|
1430
1450
|
}, {
|
|
1431
1451
|
readonly type: "function";
|
|
1432
1452
|
readonly name: "getPendingYield";
|
package/dist/index.d.ts
CHANGED
|
@@ -468,9 +468,9 @@ declare class AspanReadClient {
|
|
|
468
468
|
getExchangeRate(): Promise<bigint>;
|
|
469
469
|
getTotalStaked(): Promise<bigint>;
|
|
470
470
|
previewDeposit(assets: bigint): Promise<bigint>;
|
|
471
|
-
previewRedeem(shares: bigint): Promise<bigint>;
|
|
472
471
|
/**
|
|
473
472
|
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
473
|
+
* Replaces previewRedeem — works for both clean and dirty pools.
|
|
474
474
|
* @param shares Amount of sApUSD shares to redeem
|
|
475
475
|
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
476
476
|
*/
|
|
@@ -478,6 +478,8 @@ declare class AspanReadClient {
|
|
|
478
478
|
apUSD: bigint;
|
|
479
479
|
xBNB: bigint;
|
|
480
480
|
hasXBNB: boolean;
|
|
481
|
+
assets: Address[];
|
|
482
|
+
amounts: bigint[];
|
|
481
483
|
}>;
|
|
482
484
|
getPendingYield(): Promise<bigint>;
|
|
483
485
|
getTotalYieldGenerated(): Promise<bigint>;
|
|
@@ -1427,6 +1429,24 @@ declare const DiamondABI: readonly [{
|
|
|
1427
1429
|
readonly internalType: "uint256";
|
|
1428
1430
|
}];
|
|
1429
1431
|
readonly stateMutability: "view";
|
|
1432
|
+
}, {
|
|
1433
|
+
readonly type: "function";
|
|
1434
|
+
readonly name: "previewRedeemMulti";
|
|
1435
|
+
readonly inputs: readonly [{
|
|
1436
|
+
readonly name: "_shares";
|
|
1437
|
+
readonly type: "uint256";
|
|
1438
|
+
readonly internalType: "uint256";
|
|
1439
|
+
}];
|
|
1440
|
+
readonly outputs: readonly [{
|
|
1441
|
+
readonly name: "assets";
|
|
1442
|
+
readonly type: "address[]";
|
|
1443
|
+
readonly internalType: "address[]";
|
|
1444
|
+
}, {
|
|
1445
|
+
readonly name: "amounts";
|
|
1446
|
+
readonly type: "uint256[]";
|
|
1447
|
+
readonly internalType: "uint256[]";
|
|
1448
|
+
}];
|
|
1449
|
+
readonly stateMutability: "view";
|
|
1430
1450
|
}, {
|
|
1431
1451
|
readonly type: "function";
|
|
1432
1452
|
readonly name: "getPendingYield";
|
package/dist/index.js
CHANGED
|
@@ -363,6 +363,16 @@ var DiamondABI = [
|
|
|
363
363
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
364
364
|
stateMutability: "view"
|
|
365
365
|
},
|
|
366
|
+
{
|
|
367
|
+
type: "function",
|
|
368
|
+
name: "previewRedeemMulti",
|
|
369
|
+
inputs: [{ name: "_shares", type: "uint256", internalType: "uint256" }],
|
|
370
|
+
outputs: [
|
|
371
|
+
{ name: "assets", type: "address[]", internalType: "address[]" },
|
|
372
|
+
{ name: "amounts", type: "uint256[]", internalType: "uint256[]" }
|
|
373
|
+
],
|
|
374
|
+
stateMutability: "view"
|
|
375
|
+
},
|
|
366
376
|
{
|
|
367
377
|
type: "function",
|
|
368
378
|
name: "getPendingYield",
|
|
@@ -1291,45 +1301,26 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1291
1301
|
throw error;
|
|
1292
1302
|
}
|
|
1293
1303
|
}
|
|
1294
|
-
async previewRedeem(shares) {
|
|
1295
|
-
try {
|
|
1296
|
-
return await this.publicClient.readContract({
|
|
1297
|
-
address: this.diamondAddress,
|
|
1298
|
-
abi: DiamondABI,
|
|
1299
|
-
functionName: "previewRedeem",
|
|
1300
|
-
args: [shares]
|
|
1301
|
-
});
|
|
1302
|
-
} catch (error) {
|
|
1303
|
-
if (this.isZeroSupplyError(error)) {
|
|
1304
|
-
return shares;
|
|
1305
|
-
}
|
|
1306
|
-
throw error;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
1304
|
/**
|
|
1310
1305
|
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
1306
|
+
* Replaces previewRedeem — works for both clean and dirty pools.
|
|
1311
1307
|
* @param shares Amount of sApUSD shares to redeem
|
|
1312
1308
|
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
1313
1309
|
*/
|
|
1314
1310
|
async previewRedeemMulti(shares) {
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
}),
|
|
1323
|
-
this.publicClient.readContract({
|
|
1324
|
-
address: sApUSDAddress,
|
|
1325
|
-
abi: SApUSDABI,
|
|
1326
|
-
functionName: "hasStabilityConversion"
|
|
1327
|
-
})
|
|
1328
|
-
]);
|
|
1311
|
+
const [assets, amounts] = await this.publicClient.readContract({
|
|
1312
|
+
address: this.diamondAddress,
|
|
1313
|
+
abi: DiamondABI,
|
|
1314
|
+
functionName: "previewRedeemMulti",
|
|
1315
|
+
args: [shares]
|
|
1316
|
+
});
|
|
1317
|
+
const hasXBNB = amounts.length > 1 && amounts[1] > 0n;
|
|
1329
1318
|
return {
|
|
1330
|
-
apUSD:
|
|
1331
|
-
xBNB:
|
|
1332
|
-
hasXBNB
|
|
1319
|
+
apUSD: amounts[0] ?? 0n,
|
|
1320
|
+
xBNB: amounts[1] ?? 0n,
|
|
1321
|
+
hasXBNB,
|
|
1322
|
+
assets,
|
|
1323
|
+
amounts
|
|
1333
1324
|
};
|
|
1334
1325
|
}
|
|
1335
1326
|
async getPendingYield() {
|
package/dist/index.mjs
CHANGED
|
@@ -305,6 +305,16 @@ var DiamondABI = [
|
|
|
305
305
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
306
306
|
stateMutability: "view"
|
|
307
307
|
},
|
|
308
|
+
{
|
|
309
|
+
type: "function",
|
|
310
|
+
name: "previewRedeemMulti",
|
|
311
|
+
inputs: [{ name: "_shares", type: "uint256", internalType: "uint256" }],
|
|
312
|
+
outputs: [
|
|
313
|
+
{ name: "assets", type: "address[]", internalType: "address[]" },
|
|
314
|
+
{ name: "amounts", type: "uint256[]", internalType: "uint256[]" }
|
|
315
|
+
],
|
|
316
|
+
stateMutability: "view"
|
|
317
|
+
},
|
|
308
318
|
{
|
|
309
319
|
type: "function",
|
|
310
320
|
name: "getPendingYield",
|
|
@@ -1233,45 +1243,26 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1233
1243
|
throw error;
|
|
1234
1244
|
}
|
|
1235
1245
|
}
|
|
1236
|
-
async previewRedeem(shares) {
|
|
1237
|
-
try {
|
|
1238
|
-
return await this.publicClient.readContract({
|
|
1239
|
-
address: this.diamondAddress,
|
|
1240
|
-
abi: DiamondABI,
|
|
1241
|
-
functionName: "previewRedeem",
|
|
1242
|
-
args: [shares]
|
|
1243
|
-
});
|
|
1244
|
-
} catch (error) {
|
|
1245
|
-
if (this.isZeroSupplyError(error)) {
|
|
1246
|
-
return shares;
|
|
1247
|
-
}
|
|
1248
|
-
throw error;
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
1246
|
/**
|
|
1252
1247
|
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
1248
|
+
* Replaces previewRedeem — works for both clean and dirty pools.
|
|
1253
1249
|
* @param shares Amount of sApUSD shares to redeem
|
|
1254
1250
|
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
1255
1251
|
*/
|
|
1256
1252
|
async previewRedeemMulti(shares) {
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
}),
|
|
1265
|
-
this.publicClient.readContract({
|
|
1266
|
-
address: sApUSDAddress,
|
|
1267
|
-
abi: SApUSDABI,
|
|
1268
|
-
functionName: "hasStabilityConversion"
|
|
1269
|
-
})
|
|
1270
|
-
]);
|
|
1253
|
+
const [assets, amounts] = await this.publicClient.readContract({
|
|
1254
|
+
address: this.diamondAddress,
|
|
1255
|
+
abi: DiamondABI,
|
|
1256
|
+
functionName: "previewRedeemMulti",
|
|
1257
|
+
args: [shares]
|
|
1258
|
+
});
|
|
1259
|
+
const hasXBNB = amounts.length > 1 && amounts[1] > 0n;
|
|
1271
1260
|
return {
|
|
1272
|
-
apUSD:
|
|
1273
|
-
xBNB:
|
|
1274
|
-
hasXBNB
|
|
1261
|
+
apUSD: amounts[0] ?? 0n,
|
|
1262
|
+
xBNB: amounts[1] ?? 0n,
|
|
1263
|
+
hasXBNB,
|
|
1264
|
+
assets,
|
|
1265
|
+
amounts
|
|
1275
1266
|
};
|
|
1276
1267
|
}
|
|
1277
1268
|
async getPendingYield() {
|
package/package.json
CHANGED
package/src/abi/diamond.ts
CHANGED
|
@@ -303,6 +303,16 @@ export const DiamondABI = [
|
|
|
303
303
|
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
304
304
|
stateMutability: "view"
|
|
305
305
|
},
|
|
306
|
+
{
|
|
307
|
+
type: "function",
|
|
308
|
+
name: "previewRedeemMulti",
|
|
309
|
+
inputs: [{ name: "_shares", type: "uint256", internalType: "uint256" }],
|
|
310
|
+
outputs: [
|
|
311
|
+
{ name: "assets", type: "address[]", internalType: "address[]" },
|
|
312
|
+
{ name: "amounts", type: "uint256[]", internalType: "uint256[]" }
|
|
313
|
+
],
|
|
314
|
+
stateMutability: "view"
|
|
315
|
+
},
|
|
306
316
|
{
|
|
307
317
|
type: "function",
|
|
308
318
|
name: "getPendingYield",
|
package/src/client.ts
CHANGED
|
@@ -598,24 +598,9 @@ export class AspanReadClient {
|
|
|
598
598
|
}
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
-
async previewRedeem(shares: bigint): Promise<bigint> {
|
|
602
|
-
try {
|
|
603
|
-
return await this.publicClient.readContract({
|
|
604
|
-
address: this.diamondAddress,
|
|
605
|
-
abi: DiamondABI,
|
|
606
|
-
functionName: "previewRedeem",
|
|
607
|
-
args: [shares],
|
|
608
|
-
});
|
|
609
|
-
} catch (error) {
|
|
610
|
-
if (this.isZeroSupplyError(error)) {
|
|
611
|
-
return shares; // 1:1 when pool is empty
|
|
612
|
-
}
|
|
613
|
-
throw error;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
601
|
/**
|
|
618
602
|
* Preview withdraw with multi-asset support (apUSD + xBNB)
|
|
603
|
+
* Replaces previewRedeem — works for both clean and dirty pools.
|
|
619
604
|
* @param shares Amount of sApUSD shares to redeem
|
|
620
605
|
* @returns Object with apUSD and xBNB amounts, plus whether vault has xBNB
|
|
621
606
|
*/
|
|
@@ -623,25 +608,24 @@ export class AspanReadClient {
|
|
|
623
608
|
apUSD: bigint;
|
|
624
609
|
xBNB: bigint;
|
|
625
610
|
hasXBNB: boolean;
|
|
611
|
+
assets: Address[];
|
|
612
|
+
amounts: bigint[];
|
|
626
613
|
}> {
|
|
627
|
-
|
|
628
|
-
const [
|
|
629
|
-
this.
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
address: sApUSDAddress,
|
|
637
|
-
abi: SApUSDABI,
|
|
638
|
-
functionName: "hasStabilityConversion",
|
|
639
|
-
}) as Promise<[boolean, bigint]>,
|
|
640
|
-
]);
|
|
614
|
+
// Use Diamond's previewRedeemMulti (forwards to SApUSD)
|
|
615
|
+
const [assets, amounts] = await this.publicClient.readContract({
|
|
616
|
+
address: this.diamondAddress,
|
|
617
|
+
abi: DiamondABI,
|
|
618
|
+
functionName: "previewRedeemMulti",
|
|
619
|
+
args: [shares],
|
|
620
|
+
}) as [Address[], bigint[]];
|
|
621
|
+
|
|
622
|
+
const hasXBNB = amounts.length > 1 && amounts[1] > 0n;
|
|
641
623
|
return {
|
|
642
|
-
apUSD:
|
|
643
|
-
xBNB:
|
|
644
|
-
hasXBNB
|
|
624
|
+
apUSD: amounts[0] ?? 0n,
|
|
625
|
+
xBNB: amounts[1] ?? 0n,
|
|
626
|
+
hasXBNB,
|
|
627
|
+
assets,
|
|
628
|
+
amounts,
|
|
645
629
|
};
|
|
646
630
|
}
|
|
647
631
|
|