@aspan/sdk 0.4.6 → 0.4.7
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 +1 -1
- package/dist/index.d.mts +48 -26
- package/dist/index.d.ts +48 -26
- package/dist/index.js +169 -55
- package/dist/index.mjs +169 -55
- package/package.json +3 -1
- package/src/__tests__/fork.test.ts +1 -0
- package/src/__tests__/risk.test.ts +2084 -0
- package/src/__tests__/router.test.ts +676 -62
- package/src/abi/diamond.ts +0 -7
- package/src/abi/router.ts +14 -0
- package/src/abi/sApUSD.ts +47 -33
- package/src/client.ts +0 -17
- package/src/index.ts +1 -2
- package/src/router.ts +136 -0
- package/src/types.ts +0 -5
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ import { BSC_ADDRESSES } from "@aspan/sdk";
|
|
|
22
22
|
| Contract | Address |
|
|
23
23
|
|----------|---------|
|
|
24
24
|
| **Diamond (Main Entry)** | `0x6a11B30d3a70727d5477D6d8090e144443fA1c78` |
|
|
25
|
-
| **Router** | `
|
|
25
|
+
| **Router** | `0x34a64c4EbDe830773083BA8c9469456616F6723b` |
|
|
26
26
|
| **ApUSD** | `0x4570047eeB5aDb4081c5d470494EB5134e34A287` |
|
|
27
27
|
| **XBNB** | `0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43` |
|
|
28
28
|
| **SApUSD** | `0xE2BE739C4aA4126ee72D612d9548C38B1B0e5A1b` |
|
package/dist/index.d.mts
CHANGED
|
@@ -103,10 +103,6 @@ interface DepositParams {
|
|
|
103
103
|
interface WithdrawParams {
|
|
104
104
|
shares: bigint;
|
|
105
105
|
}
|
|
106
|
-
/** Parameters for withdrawing assets from stability pool */
|
|
107
|
-
interface WithdrawAssetsParams {
|
|
108
|
-
assets: bigint;
|
|
109
|
-
}
|
|
110
106
|
/** Overall protocol statistics */
|
|
111
107
|
interface ProtocolStats {
|
|
112
108
|
tvlInBNB: bigint;
|
|
@@ -586,12 +582,6 @@ declare class AspanClient extends AspanReadClient {
|
|
|
586
582
|
* @returns Transaction hash
|
|
587
583
|
*/
|
|
588
584
|
withdraw(params: WithdrawParams): Promise<Hash>;
|
|
589
|
-
/**
|
|
590
|
-
* Withdraw from stability pool by asset amount
|
|
591
|
-
* @param params Withdraw parameters
|
|
592
|
-
* @returns Transaction hash
|
|
593
|
-
*/
|
|
594
|
-
withdrawAssets(params: WithdrawAssetsParams): Promise<Hash>;
|
|
595
585
|
/**
|
|
596
586
|
* Harvest yield from LSTs
|
|
597
587
|
* @returns Transaction hash
|
|
@@ -725,6 +715,14 @@ declare class AspanRouterReadClient {
|
|
|
725
715
|
* Check if an LST is supported
|
|
726
716
|
*/
|
|
727
717
|
isSupportedLST(lst: Address): Promise<boolean>;
|
|
718
|
+
/**
|
|
719
|
+
* Get LST mode (0 = SYNC, 1 = ASYNC_DIRECT_ONLY)
|
|
720
|
+
*/
|
|
721
|
+
getLSTMode(lst: Address): Promise<number>;
|
|
722
|
+
/**
|
|
723
|
+
* Check whether an LST supports routed flows (swap/stake/redeemAndSwap)
|
|
724
|
+
*/
|
|
725
|
+
isLSTRoutable(lst: Address): Promise<boolean>;
|
|
728
726
|
/**
|
|
729
727
|
* Get the Diamond contract address
|
|
730
728
|
*/
|
|
@@ -743,6 +741,22 @@ declare class AspanRouterReadClient {
|
|
|
743
741
|
* @param amount Amount of apUSD/xBNB to redeem
|
|
744
742
|
*/
|
|
745
743
|
previewRedeem(lst: Address, redeemXBNB: boolean, amount: bigint): Promise<bigint>;
|
|
744
|
+
/**
|
|
745
|
+
* SDK-only preview: input token -> estimated LST -> previewMint
|
|
746
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
747
|
+
*/
|
|
748
|
+
previewMintByInput(inputToken: Address, inputAmount: bigint, targetLST: Address, mintXBNB: boolean): Promise<{
|
|
749
|
+
lstAmount: bigint;
|
|
750
|
+
mintedAmount: bigint;
|
|
751
|
+
}>;
|
|
752
|
+
/**
|
|
753
|
+
* SDK-only preview: previewRedeem -> estimated output token
|
|
754
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
755
|
+
*/
|
|
756
|
+
previewRedeemToOutput(lst: Address, redeemXBNB: boolean, amount: bigint, outputToken: Address): Promise<{
|
|
757
|
+
lstAmount: bigint;
|
|
758
|
+
outputAmount: bigint;
|
|
759
|
+
}>;
|
|
746
760
|
/**
|
|
747
761
|
* Get user's withdrawal request indices
|
|
748
762
|
*/
|
|
@@ -1339,20 +1353,6 @@ declare const DiamondABI: readonly [{
|
|
|
1339
1353
|
readonly internalType: "uint256";
|
|
1340
1354
|
}];
|
|
1341
1355
|
readonly stateMutability: "nonpayable";
|
|
1342
|
-
}, {
|
|
1343
|
-
readonly type: "function";
|
|
1344
|
-
readonly name: "withdrawAssets";
|
|
1345
|
-
readonly inputs: readonly [{
|
|
1346
|
-
readonly name: "_assets";
|
|
1347
|
-
readonly type: "uint256";
|
|
1348
|
-
readonly internalType: "uint256";
|
|
1349
|
-
}];
|
|
1350
|
-
readonly outputs: readonly [{
|
|
1351
|
-
readonly name: "shares";
|
|
1352
|
-
readonly type: "uint256";
|
|
1353
|
-
readonly internalType: "uint256";
|
|
1354
|
-
}];
|
|
1355
|
-
readonly stateMutability: "nonpayable";
|
|
1356
1356
|
}, {
|
|
1357
1357
|
readonly type: "function";
|
|
1358
1358
|
readonly name: "getShares";
|
|
@@ -2330,6 +2330,28 @@ declare const RouterABI: readonly [{
|
|
|
2330
2330
|
readonly type: "bool";
|
|
2331
2331
|
}];
|
|
2332
2332
|
readonly stateMutability: "view";
|
|
2333
|
+
}, {
|
|
2334
|
+
readonly type: "function";
|
|
2335
|
+
readonly name: "lstModes";
|
|
2336
|
+
readonly inputs: readonly [{
|
|
2337
|
+
readonly name: "lst";
|
|
2338
|
+
readonly type: "address";
|
|
2339
|
+
}];
|
|
2340
|
+
readonly outputs: readonly [{
|
|
2341
|
+
readonly type: "uint8";
|
|
2342
|
+
}];
|
|
2343
|
+
readonly stateMutability: "view";
|
|
2344
|
+
}, {
|
|
2345
|
+
readonly type: "function";
|
|
2346
|
+
readonly name: "isLSTRoutable";
|
|
2347
|
+
readonly inputs: readonly [{
|
|
2348
|
+
readonly name: "lst";
|
|
2349
|
+
readonly type: "address";
|
|
2350
|
+
}];
|
|
2351
|
+
readonly outputs: readonly [{
|
|
2352
|
+
readonly type: "bool";
|
|
2353
|
+
}];
|
|
2354
|
+
readonly stateMutability: "view";
|
|
2333
2355
|
}, {
|
|
2334
2356
|
readonly type: "function";
|
|
2335
2357
|
readonly name: "previewMint";
|
|
@@ -2785,7 +2807,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2785
2807
|
declare const PRICE_PRECISION: bigint;
|
|
2786
2808
|
declare const BSC_ADDRESSES: {
|
|
2787
2809
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2788
|
-
readonly router: "
|
|
2810
|
+
readonly router: "0x34a64c4EbDe830773083BA8c9469456616F6723b";
|
|
2789
2811
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2790
2812
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2791
2813
|
readonly sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB";
|
|
@@ -2845,4 +2867,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2845
2867
|
*/
|
|
2846
2868
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2847
2869
|
|
|
2848
|
-
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, CHAIN_IDS, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, PHAROS_ADDRESSES, PRECISION, PRICE_PRECISION, type ProtocolStats, type RedeemAndSwapEvent, type RedeemApUSDParams, type RedeemXBNBParams, RouterABI, type RouterMintEvent, type RouterMintParams, type RouterMintParams2, type RouterRedeemAndSwapParams, type RouterRedeemAndUnstakeParams, type RouterRedeemEvent, type RouterRedeemParams, type RouterSwapParams, type StabilityMode2Info, type StabilityModeInfo, type StabilityPoolStats, type StakeAndMintEvent, type StakeAndMintParams, type SwapAndMintDefaultParams, type SwapAndMintEvent, type SwapAndMintParams, type TokenAddresses, type TransactionReceipt, type TransactionResult, type UnstakeClaimedEvent, type UnstakeRequestedEvent, type UserStabilityPoolPosition, type
|
|
2870
|
+
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, CHAIN_IDS, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, PHAROS_ADDRESSES, PRECISION, PRICE_PRECISION, type ProtocolStats, type RedeemAndSwapEvent, type RedeemApUSDParams, type RedeemXBNBParams, RouterABI, type RouterMintEvent, type RouterMintParams, type RouterMintParams2, type RouterRedeemAndSwapParams, type RouterRedeemAndUnstakeParams, type RouterRedeemEvent, type RouterRedeemParams, type RouterSwapParams, type StabilityMode2Info, type StabilityModeInfo, type StabilityPoolStats, type StakeAndMintEvent, type StakeAndMintParams, type SwapAndMintDefaultParams, type SwapAndMintEvent, type SwapAndMintParams, type TokenAddresses, type TransactionReceipt, type TransactionResult, type UnstakeClaimedEvent, type UnstakeRequestedEvent, type UserStabilityPoolPosition, type WithdrawParams, type WithdrawalRequestInfo, type WithdrawnEvent, type XBNBMintedEvent, type XBNBRedeemedEvent, type YieldHarvestedEvent, type YieldStats, calculateAPY, createAspanClient, createAspanPharosClient, createAspanPharosReadClient, createAspanReadClient, createAspanReadClientForChain, createAspanTestnetClient, createAspanTestnetReadClient, createAspanWriteClientForChain, createRouterClient, createRouterPharosClient, createRouterPharosReadClient, createRouterReadClient, createRouterReadClientForChain, createRouterTestnetClient, createRouterTestnetReadClient, createRouterWriteClientForChain, encodeV3Path, formatAmount, formatCR, formatFeeBPS, formatPriceUSD, getChainById, parseAmount, pharosTestnet };
|
package/dist/index.d.ts
CHANGED
|
@@ -103,10 +103,6 @@ interface DepositParams {
|
|
|
103
103
|
interface WithdrawParams {
|
|
104
104
|
shares: bigint;
|
|
105
105
|
}
|
|
106
|
-
/** Parameters for withdrawing assets from stability pool */
|
|
107
|
-
interface WithdrawAssetsParams {
|
|
108
|
-
assets: bigint;
|
|
109
|
-
}
|
|
110
106
|
/** Overall protocol statistics */
|
|
111
107
|
interface ProtocolStats {
|
|
112
108
|
tvlInBNB: bigint;
|
|
@@ -586,12 +582,6 @@ declare class AspanClient extends AspanReadClient {
|
|
|
586
582
|
* @returns Transaction hash
|
|
587
583
|
*/
|
|
588
584
|
withdraw(params: WithdrawParams): Promise<Hash>;
|
|
589
|
-
/**
|
|
590
|
-
* Withdraw from stability pool by asset amount
|
|
591
|
-
* @param params Withdraw parameters
|
|
592
|
-
* @returns Transaction hash
|
|
593
|
-
*/
|
|
594
|
-
withdrawAssets(params: WithdrawAssetsParams): Promise<Hash>;
|
|
595
585
|
/**
|
|
596
586
|
* Harvest yield from LSTs
|
|
597
587
|
* @returns Transaction hash
|
|
@@ -725,6 +715,14 @@ declare class AspanRouterReadClient {
|
|
|
725
715
|
* Check if an LST is supported
|
|
726
716
|
*/
|
|
727
717
|
isSupportedLST(lst: Address): Promise<boolean>;
|
|
718
|
+
/**
|
|
719
|
+
* Get LST mode (0 = SYNC, 1 = ASYNC_DIRECT_ONLY)
|
|
720
|
+
*/
|
|
721
|
+
getLSTMode(lst: Address): Promise<number>;
|
|
722
|
+
/**
|
|
723
|
+
* Check whether an LST supports routed flows (swap/stake/redeemAndSwap)
|
|
724
|
+
*/
|
|
725
|
+
isLSTRoutable(lst: Address): Promise<boolean>;
|
|
728
726
|
/**
|
|
729
727
|
* Get the Diamond contract address
|
|
730
728
|
*/
|
|
@@ -743,6 +741,22 @@ declare class AspanRouterReadClient {
|
|
|
743
741
|
* @param amount Amount of apUSD/xBNB to redeem
|
|
744
742
|
*/
|
|
745
743
|
previewRedeem(lst: Address, redeemXBNB: boolean, amount: bigint): Promise<bigint>;
|
|
744
|
+
/**
|
|
745
|
+
* SDK-only preview: input token -> estimated LST -> previewMint
|
|
746
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
747
|
+
*/
|
|
748
|
+
previewMintByInput(inputToken: Address, inputAmount: bigint, targetLST: Address, mintXBNB: boolean): Promise<{
|
|
749
|
+
lstAmount: bigint;
|
|
750
|
+
mintedAmount: bigint;
|
|
751
|
+
}>;
|
|
752
|
+
/**
|
|
753
|
+
* SDK-only preview: previewRedeem -> estimated output token
|
|
754
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
755
|
+
*/
|
|
756
|
+
previewRedeemToOutput(lst: Address, redeemXBNB: boolean, amount: bigint, outputToken: Address): Promise<{
|
|
757
|
+
lstAmount: bigint;
|
|
758
|
+
outputAmount: bigint;
|
|
759
|
+
}>;
|
|
746
760
|
/**
|
|
747
761
|
* Get user's withdrawal request indices
|
|
748
762
|
*/
|
|
@@ -1339,20 +1353,6 @@ declare const DiamondABI: readonly [{
|
|
|
1339
1353
|
readonly internalType: "uint256";
|
|
1340
1354
|
}];
|
|
1341
1355
|
readonly stateMutability: "nonpayable";
|
|
1342
|
-
}, {
|
|
1343
|
-
readonly type: "function";
|
|
1344
|
-
readonly name: "withdrawAssets";
|
|
1345
|
-
readonly inputs: readonly [{
|
|
1346
|
-
readonly name: "_assets";
|
|
1347
|
-
readonly type: "uint256";
|
|
1348
|
-
readonly internalType: "uint256";
|
|
1349
|
-
}];
|
|
1350
|
-
readonly outputs: readonly [{
|
|
1351
|
-
readonly name: "shares";
|
|
1352
|
-
readonly type: "uint256";
|
|
1353
|
-
readonly internalType: "uint256";
|
|
1354
|
-
}];
|
|
1355
|
-
readonly stateMutability: "nonpayable";
|
|
1356
1356
|
}, {
|
|
1357
1357
|
readonly type: "function";
|
|
1358
1358
|
readonly name: "getShares";
|
|
@@ -2330,6 +2330,28 @@ declare const RouterABI: readonly [{
|
|
|
2330
2330
|
readonly type: "bool";
|
|
2331
2331
|
}];
|
|
2332
2332
|
readonly stateMutability: "view";
|
|
2333
|
+
}, {
|
|
2334
|
+
readonly type: "function";
|
|
2335
|
+
readonly name: "lstModes";
|
|
2336
|
+
readonly inputs: readonly [{
|
|
2337
|
+
readonly name: "lst";
|
|
2338
|
+
readonly type: "address";
|
|
2339
|
+
}];
|
|
2340
|
+
readonly outputs: readonly [{
|
|
2341
|
+
readonly type: "uint8";
|
|
2342
|
+
}];
|
|
2343
|
+
readonly stateMutability: "view";
|
|
2344
|
+
}, {
|
|
2345
|
+
readonly type: "function";
|
|
2346
|
+
readonly name: "isLSTRoutable";
|
|
2347
|
+
readonly inputs: readonly [{
|
|
2348
|
+
readonly name: "lst";
|
|
2349
|
+
readonly type: "address";
|
|
2350
|
+
}];
|
|
2351
|
+
readonly outputs: readonly [{
|
|
2352
|
+
readonly type: "bool";
|
|
2353
|
+
}];
|
|
2354
|
+
readonly stateMutability: "view";
|
|
2333
2355
|
}, {
|
|
2334
2356
|
readonly type: "function";
|
|
2335
2357
|
readonly name: "previewMint";
|
|
@@ -2785,7 +2807,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2785
2807
|
declare const PRICE_PRECISION: bigint;
|
|
2786
2808
|
declare const BSC_ADDRESSES: {
|
|
2787
2809
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2788
|
-
readonly router: "
|
|
2810
|
+
readonly router: "0x34a64c4EbDe830773083BA8c9469456616F6723b";
|
|
2789
2811
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2790
2812
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2791
2813
|
readonly sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB";
|
|
@@ -2845,4 +2867,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2845
2867
|
*/
|
|
2846
2868
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2847
2869
|
|
|
2848
|
-
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, CHAIN_IDS, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, PHAROS_ADDRESSES, PRECISION, PRICE_PRECISION, type ProtocolStats, type RedeemAndSwapEvent, type RedeemApUSDParams, type RedeemXBNBParams, RouterABI, type RouterMintEvent, type RouterMintParams, type RouterMintParams2, type RouterRedeemAndSwapParams, type RouterRedeemAndUnstakeParams, type RouterRedeemEvent, type RouterRedeemParams, type RouterSwapParams, type StabilityMode2Info, type StabilityModeInfo, type StabilityPoolStats, type StakeAndMintEvent, type StakeAndMintParams, type SwapAndMintDefaultParams, type SwapAndMintEvent, type SwapAndMintParams, type TokenAddresses, type TransactionReceipt, type TransactionResult, type UnstakeClaimedEvent, type UnstakeRequestedEvent, type UserStabilityPoolPosition, type
|
|
2870
|
+
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, CHAIN_IDS, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, PHAROS_ADDRESSES, PRECISION, PRICE_PRECISION, type ProtocolStats, type RedeemAndSwapEvent, type RedeemApUSDParams, type RedeemXBNBParams, RouterABI, type RouterMintEvent, type RouterMintParams, type RouterMintParams2, type RouterRedeemAndSwapParams, type RouterRedeemAndUnstakeParams, type RouterRedeemEvent, type RouterRedeemParams, type RouterSwapParams, type StabilityMode2Info, type StabilityModeInfo, type StabilityPoolStats, type StakeAndMintEvent, type StakeAndMintParams, type SwapAndMintDefaultParams, type SwapAndMintEvent, type SwapAndMintParams, type TokenAddresses, type TransactionReceipt, type TransactionResult, type UnstakeClaimedEvent, type UnstakeRequestedEvent, type UserStabilityPoolPosition, type WithdrawParams, type WithdrawalRequestInfo, type WithdrawnEvent, type XBNBMintedEvent, type XBNBRedeemedEvent, type YieldHarvestedEvent, type YieldStats, calculateAPY, createAspanClient, createAspanPharosClient, createAspanPharosReadClient, createAspanReadClient, createAspanReadClientForChain, createAspanTestnetClient, createAspanTestnetReadClient, createAspanWriteClientForChain, createRouterClient, createRouterPharosClient, createRouterPharosReadClient, createRouterReadClient, createRouterReadClientForChain, createRouterTestnetClient, createRouterTestnetReadClient, createRouterWriteClientForChain, encodeV3Path, formatAmount, formatCR, formatFeeBPS, formatPriceUSD, getChainById, parseAmount, pharosTestnet };
|
package/dist/index.js
CHANGED
|
@@ -314,13 +314,6 @@ var DiamondABI = [
|
|
|
314
314
|
outputs: [{ name: "assets", type: "uint256", internalType: "uint256" }],
|
|
315
315
|
stateMutability: "nonpayable"
|
|
316
316
|
},
|
|
317
|
-
{
|
|
318
|
-
type: "function",
|
|
319
|
-
name: "withdrawAssets",
|
|
320
|
-
inputs: [{ name: "_assets", type: "uint256", internalType: "uint256" }],
|
|
321
|
-
outputs: [{ name: "shares", type: "uint256", internalType: "uint256" }],
|
|
322
|
-
stateMutability: "nonpayable"
|
|
323
|
-
},
|
|
324
317
|
{
|
|
325
318
|
type: "function",
|
|
326
319
|
name: "getShares",
|
|
@@ -739,13 +732,13 @@ var SApUSDABI = [
|
|
|
739
732
|
},
|
|
740
733
|
{
|
|
741
734
|
type: "function",
|
|
742
|
-
name: "
|
|
735
|
+
name: "previewRedeem",
|
|
743
736
|
inputs: [
|
|
744
737
|
{ name: "shares", type: "uint256", internalType: "uint256" }
|
|
745
738
|
],
|
|
746
739
|
outputs: [
|
|
747
|
-
{ name: "
|
|
748
|
-
{ name: "
|
|
740
|
+
{ name: "apUSDOut", type: "uint256", internalType: "uint256" },
|
|
741
|
+
{ name: "xBNBOut", type: "uint256", internalType: "uint256" }
|
|
749
742
|
],
|
|
750
743
|
stateMutability: "view"
|
|
751
744
|
},
|
|
@@ -792,56 +785,69 @@ var SApUSDABI = [
|
|
|
792
785
|
},
|
|
793
786
|
{
|
|
794
787
|
type: "function",
|
|
795
|
-
name: "
|
|
788
|
+
name: "hasRole",
|
|
796
789
|
inputs: [
|
|
797
|
-
{ name: "
|
|
798
|
-
{ name: "
|
|
799
|
-
{ name: "_path", type: "address[]", internalType: "address[]" }
|
|
790
|
+
{ name: "role", type: "bytes32", internalType: "bytes32" },
|
|
791
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
800
792
|
],
|
|
801
|
-
outputs: [{ name: "
|
|
793
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
802
794
|
stateMutability: "view"
|
|
803
795
|
},
|
|
796
|
+
// ============ Write Functions ============
|
|
804
797
|
{
|
|
805
798
|
type: "function",
|
|
806
|
-
name: "
|
|
807
|
-
inputs: [
|
|
808
|
-
|
|
809
|
-
|
|
799
|
+
name: "redeem",
|
|
800
|
+
inputs: [
|
|
801
|
+
{ name: "shares", type: "uint256", internalType: "uint256" },
|
|
802
|
+
{ name: "receiver", type: "address", internalType: "address" },
|
|
803
|
+
{ name: "owner", type: "address", internalType: "address" }
|
|
804
|
+
],
|
|
805
|
+
outputs: [
|
|
806
|
+
{ name: "apUSDOut", type: "uint256", internalType: "uint256" },
|
|
807
|
+
{ name: "xBNBOut", type: "uint256", internalType: "uint256" }
|
|
808
|
+
],
|
|
809
|
+
stateMutability: "nonpayable"
|
|
810
810
|
},
|
|
811
811
|
{
|
|
812
812
|
type: "function",
|
|
813
|
-
name: "
|
|
813
|
+
name: "deposit",
|
|
814
814
|
inputs: [
|
|
815
|
-
{ name: "
|
|
816
|
-
{ name: "
|
|
815
|
+
{ name: "assets", type: "uint256", internalType: "uint256" },
|
|
816
|
+
{ name: "receiver", type: "address", internalType: "address" }
|
|
817
817
|
],
|
|
818
|
-
outputs: [{ name: "", type: "
|
|
819
|
-
stateMutability: "
|
|
818
|
+
outputs: [{ name: "shares", type: "uint256", internalType: "uint256" }],
|
|
819
|
+
stateMutability: "nonpayable"
|
|
820
820
|
},
|
|
821
|
-
// ============
|
|
821
|
+
// ============ Accounting Functions ============
|
|
822
822
|
{
|
|
823
823
|
type: "function",
|
|
824
|
-
name: "
|
|
824
|
+
name: "addAccounting",
|
|
825
825
|
inputs: [
|
|
826
|
-
{ name: "
|
|
827
|
-
{ name: "
|
|
828
|
-
{ name: "_router", type: "address", internalType: "address" },
|
|
829
|
-
{ name: "_path", type: "address[]", internalType: "address[]" },
|
|
830
|
-
{ name: "_deadline", type: "uint256", internalType: "uint256" }
|
|
826
|
+
{ name: "apUSD", type: "uint256", internalType: "uint256" },
|
|
827
|
+
{ name: "xBNB", type: "uint256", internalType: "uint256" }
|
|
831
828
|
],
|
|
832
|
-
outputs: [
|
|
829
|
+
outputs: [],
|
|
833
830
|
stateMutability: "nonpayable"
|
|
834
831
|
},
|
|
835
|
-
// ============ Events ============
|
|
836
832
|
{
|
|
837
|
-
type: "
|
|
838
|
-
name: "
|
|
833
|
+
type: "function",
|
|
834
|
+
name: "subAccounting",
|
|
839
835
|
inputs: [
|
|
840
|
-
{ name: "
|
|
841
|
-
{ name: "
|
|
842
|
-
{ name: "keeper", type: "address", indexed: true, internalType: "address" }
|
|
836
|
+
{ name: "apUSD", type: "uint256", internalType: "uint256" },
|
|
837
|
+
{ name: "xBNB", type: "uint256", internalType: "uint256" }
|
|
843
838
|
],
|
|
844
|
-
|
|
839
|
+
outputs: [],
|
|
840
|
+
stateMutability: "nonpayable"
|
|
841
|
+
},
|
|
842
|
+
// ============ Admin Functions ============
|
|
843
|
+
{
|
|
844
|
+
type: "function",
|
|
845
|
+
name: "sweepExcess",
|
|
846
|
+
inputs: [
|
|
847
|
+
{ name: "recipient", type: "address", internalType: "address" }
|
|
848
|
+
],
|
|
849
|
+
outputs: [],
|
|
850
|
+
stateMutability: "nonpayable"
|
|
845
851
|
}
|
|
846
852
|
];
|
|
847
853
|
|
|
@@ -1813,21 +1819,6 @@ var AspanClient = class extends AspanReadClient {
|
|
|
1813
1819
|
args: [params.shares]
|
|
1814
1820
|
});
|
|
1815
1821
|
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Withdraw from stability pool by asset amount
|
|
1818
|
-
* @param params Withdraw parameters
|
|
1819
|
-
* @returns Transaction hash
|
|
1820
|
-
*/
|
|
1821
|
-
async withdrawAssets(params) {
|
|
1822
|
-
return this.walletClient.writeContract({
|
|
1823
|
-
chain: this.chain,
|
|
1824
|
-
account: this.walletClient.account,
|
|
1825
|
-
address: this.diamondAddress,
|
|
1826
|
-
abi: DiamondABI,
|
|
1827
|
-
functionName: "withdrawAssets",
|
|
1828
|
-
args: [params.assets]
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
1822
|
/**
|
|
1832
1823
|
* Harvest yield from LSTs
|
|
1833
1824
|
* @returns Transaction hash
|
|
@@ -2157,6 +2148,20 @@ var RouterABI = [
|
|
|
2157
2148
|
outputs: [{ type: "bool" }],
|
|
2158
2149
|
stateMutability: "view"
|
|
2159
2150
|
},
|
|
2151
|
+
{
|
|
2152
|
+
type: "function",
|
|
2153
|
+
name: "lstModes",
|
|
2154
|
+
inputs: [{ name: "lst", type: "address" }],
|
|
2155
|
+
outputs: [{ type: "uint8" }],
|
|
2156
|
+
stateMutability: "view"
|
|
2157
|
+
},
|
|
2158
|
+
{
|
|
2159
|
+
type: "function",
|
|
2160
|
+
name: "isLSTRoutable",
|
|
2161
|
+
inputs: [{ name: "lst", type: "address" }],
|
|
2162
|
+
outputs: [{ type: "bool" }],
|
|
2163
|
+
stateMutability: "view"
|
|
2164
|
+
},
|
|
2160
2165
|
// Preview functions - unified
|
|
2161
2166
|
{
|
|
2162
2167
|
type: "function",
|
|
@@ -2419,6 +2424,29 @@ var AspanRouterReadClient = class {
|
|
|
2419
2424
|
args: [lst]
|
|
2420
2425
|
});
|
|
2421
2426
|
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Get LST mode (0 = SYNC, 1 = ASYNC_DIRECT_ONLY)
|
|
2429
|
+
*/
|
|
2430
|
+
async getLSTMode(lst) {
|
|
2431
|
+
const mode = await this.publicClient.readContract({
|
|
2432
|
+
address: this.routerAddress,
|
|
2433
|
+
abi: RouterABI,
|
|
2434
|
+
functionName: "lstModes",
|
|
2435
|
+
args: [lst]
|
|
2436
|
+
});
|
|
2437
|
+
return Number(mode);
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Check whether an LST supports routed flows (swap/stake/redeemAndSwap)
|
|
2441
|
+
*/
|
|
2442
|
+
async isLSTRoutable(lst) {
|
|
2443
|
+
return this.publicClient.readContract({
|
|
2444
|
+
address: this.routerAddress,
|
|
2445
|
+
abi: RouterABI,
|
|
2446
|
+
functionName: "isLSTRoutable",
|
|
2447
|
+
args: [lst]
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2422
2450
|
/**
|
|
2423
2451
|
* Get the Diamond contract address
|
|
2424
2452
|
*/
|
|
@@ -2457,6 +2485,92 @@ var AspanRouterReadClient = class {
|
|
|
2457
2485
|
args: [lst, redeemXBNB, amount]
|
|
2458
2486
|
});
|
|
2459
2487
|
}
|
|
2488
|
+
/**
|
|
2489
|
+
* SDK-only preview: input token -> estimated LST -> previewMint
|
|
2490
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
2491
|
+
*/
|
|
2492
|
+
async previewMintByInput(inputToken, inputAmount, targetLST, mintXBNB) {
|
|
2493
|
+
if (inputAmount === 0n) return { lstAmount: 0n, mintedAmount: 0n };
|
|
2494
|
+
const [diamond, wbnb, usdt, usdc] = await Promise.all([
|
|
2495
|
+
this.getDiamond(),
|
|
2496
|
+
this.getWBNB(),
|
|
2497
|
+
this.getUSDT(),
|
|
2498
|
+
this.getUSDC()
|
|
2499
|
+
]);
|
|
2500
|
+
const [bnbPrice8, lstPrice] = await Promise.all([
|
|
2501
|
+
this.publicClient.readContract({
|
|
2502
|
+
address: diamond,
|
|
2503
|
+
abi: DiamondABI,
|
|
2504
|
+
functionName: "getBNBPriceUSD"
|
|
2505
|
+
}),
|
|
2506
|
+
this.publicClient.readContract({
|
|
2507
|
+
address: diamond,
|
|
2508
|
+
abi: DiamondABI,
|
|
2509
|
+
functionName: "getLSTPriceUSD",
|
|
2510
|
+
args: [targetLST]
|
|
2511
|
+
})
|
|
2512
|
+
]);
|
|
2513
|
+
const bnbPrice18 = BigInt(bnbPrice8) * 10n ** 10n;
|
|
2514
|
+
const lstPrice18 = BigInt(lstPrice);
|
|
2515
|
+
const one = 10n ** 18n;
|
|
2516
|
+
let lstAmount = 0n;
|
|
2517
|
+
const inNorm = inputToken.toLowerCase();
|
|
2518
|
+
if (inNorm === targetLST.toLowerCase()) {
|
|
2519
|
+
lstAmount = inputAmount;
|
|
2520
|
+
} else if (inNorm === import_viem2.zeroAddress.toLowerCase() || inNorm === wbnb.toLowerCase()) {
|
|
2521
|
+
const usdValue = inputAmount * bnbPrice18 / one;
|
|
2522
|
+
lstAmount = lstPrice18 === 0n ? 0n : usdValue * one / lstPrice18;
|
|
2523
|
+
} else if (inNorm === usdt.toLowerCase() || inNorm === usdc.toLowerCase()) {
|
|
2524
|
+
lstAmount = lstPrice18 === 0n ? 0n : inputAmount * one / lstPrice18;
|
|
2525
|
+
} else {
|
|
2526
|
+
throw new Error("Unsupported input token for SDK preview");
|
|
2527
|
+
}
|
|
2528
|
+
const mintedAmount = await this.previewMint(targetLST, lstAmount, mintXBNB);
|
|
2529
|
+
return { lstAmount, mintedAmount };
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* SDK-only preview: previewRedeem -> estimated output token
|
|
2533
|
+
* Note: oracle-based estimation (does not include live DEX slippage/price impact)
|
|
2534
|
+
*/
|
|
2535
|
+
async previewRedeemToOutput(lst, redeemXBNB, amount, outputToken) {
|
|
2536
|
+
const lstAmount = await this.previewRedeem(lst, redeemXBNB, amount);
|
|
2537
|
+
if (lstAmount === 0n) return { lstAmount: 0n, outputAmount: 0n };
|
|
2538
|
+
const [diamond, wbnb, usdt, usdc] = await Promise.all([
|
|
2539
|
+
this.getDiamond(),
|
|
2540
|
+
this.getWBNB(),
|
|
2541
|
+
this.getUSDT(),
|
|
2542
|
+
this.getUSDC()
|
|
2543
|
+
]);
|
|
2544
|
+
const [bnbPrice8, lstPrice] = await Promise.all([
|
|
2545
|
+
this.publicClient.readContract({
|
|
2546
|
+
address: diamond,
|
|
2547
|
+
abi: DiamondABI,
|
|
2548
|
+
functionName: "getBNBPriceUSD"
|
|
2549
|
+
}),
|
|
2550
|
+
this.publicClient.readContract({
|
|
2551
|
+
address: diamond,
|
|
2552
|
+
abi: DiamondABI,
|
|
2553
|
+
functionName: "getLSTPriceUSD",
|
|
2554
|
+
args: [lst]
|
|
2555
|
+
})
|
|
2556
|
+
]);
|
|
2557
|
+
const bnbPrice18 = BigInt(bnbPrice8) * 10n ** 10n;
|
|
2558
|
+
const lstPrice18 = BigInt(lstPrice);
|
|
2559
|
+
const one = 10n ** 18n;
|
|
2560
|
+
const usdValue = lstAmount * lstPrice18 / one;
|
|
2561
|
+
let outputAmount = 0n;
|
|
2562
|
+
const outNorm = outputToken.toLowerCase();
|
|
2563
|
+
if (outNorm === lst.toLowerCase()) {
|
|
2564
|
+
outputAmount = lstAmount;
|
|
2565
|
+
} else if (outNorm === import_viem2.zeroAddress.toLowerCase() || outNorm === wbnb.toLowerCase()) {
|
|
2566
|
+
outputAmount = bnbPrice18 === 0n ? 0n : usdValue * one / bnbPrice18;
|
|
2567
|
+
} else if (outNorm === usdt.toLowerCase() || outNorm === usdc.toLowerCase()) {
|
|
2568
|
+
outputAmount = usdValue;
|
|
2569
|
+
} else {
|
|
2570
|
+
throw new Error("Unsupported output token for SDK preview");
|
|
2571
|
+
}
|
|
2572
|
+
return { lstAmount, outputAmount };
|
|
2573
|
+
}
|
|
2460
2574
|
/**
|
|
2461
2575
|
* Get user's withdrawal request indices
|
|
2462
2576
|
*/
|
|
@@ -2795,7 +2909,7 @@ var BPS_PRECISION = 10000n;
|
|
|
2795
2909
|
var PRICE_PRECISION = 10n ** 8n;
|
|
2796
2910
|
var BSC_ADDRESSES = {
|
|
2797
2911
|
diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
|
|
2798
|
-
router: "
|
|
2912
|
+
router: "0x34a64c4EbDe830773083BA8c9469456616F6723b",
|
|
2799
2913
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
|
|
2800
2914
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
|
|
2801
2915
|
sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB",
|