@aspan/sdk 0.4.7 → 0.4.9
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 +33 -12
- package/dist/index.d.ts +33 -12
- package/dist/index.js +165 -114
- package/dist/index.mjs +165 -114
- package/package.json +1 -1
- package/src/__tests__/risk.test.ts +3 -3
- package/src/abi/diamond.ts +14 -4
- package/src/client.ts +8 -7
- package/src/index.ts +2 -2
- package/src/router.ts +143 -109
- package/src/types.ts +6 -3
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** | `0x1Ca976d2043dfb785c7F3A17535B3A38c50113f3` |
|
|
26
26
|
| **ApUSD** | `0x4570047eeB5aDb4081c5d470494EB5134e34A287` |
|
|
27
27
|
| **XBNB** | `0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43` |
|
|
28
28
|
| **SApUSD** | `0xE2BE739C4aA4126ee72D612d9548C38B1B0e5A1b` |
|
package/dist/index.d.mts
CHANGED
|
@@ -97,11 +97,14 @@ interface RedeemXBNBParams {
|
|
|
97
97
|
}
|
|
98
98
|
/** Parameters for depositing to stability pool */
|
|
99
99
|
interface DepositParams {
|
|
100
|
-
|
|
100
|
+
assets: bigint;
|
|
101
|
+
receiver: Address;
|
|
101
102
|
}
|
|
102
|
-
/** Parameters for
|
|
103
|
-
interface
|
|
103
|
+
/** Parameters for redeeming from stability pool */
|
|
104
|
+
interface RedeemParams {
|
|
104
105
|
shares: bigint;
|
|
106
|
+
receiver: Address;
|
|
107
|
+
owner: Address;
|
|
105
108
|
}
|
|
106
109
|
/** Overall protocol statistics */
|
|
107
110
|
interface ProtocolStats {
|
|
@@ -577,11 +580,11 @@ declare class AspanClient extends AspanReadClient {
|
|
|
577
580
|
*/
|
|
578
581
|
deposit(params: DepositParams): Promise<Hash>;
|
|
579
582
|
/**
|
|
580
|
-
*
|
|
581
|
-
* @param params
|
|
583
|
+
* Redeem from stability pool by shares
|
|
584
|
+
* @param params Redeem parameters
|
|
582
585
|
* @returns Transaction hash
|
|
583
586
|
*/
|
|
584
|
-
|
|
587
|
+
redeem(params: RedeemParams): Promise<Hash>;
|
|
585
588
|
/**
|
|
586
589
|
* Harvest yield from LSTs
|
|
587
590
|
* @returns Transaction hash
|
|
@@ -702,7 +705,9 @@ declare class AspanRouterReadClient {
|
|
|
702
705
|
protected readonly publicClient: PublicClient;
|
|
703
706
|
protected readonly routerAddress: Address;
|
|
704
707
|
protected readonly chain: Chain;
|
|
708
|
+
private readonly _addressCache;
|
|
705
709
|
constructor(config: AspanRouterClientConfig);
|
|
710
|
+
protected _getCachedAddress(key: string, fetcher: () => Promise<Address>): Promise<Address>;
|
|
706
711
|
/**
|
|
707
712
|
* Get the default LST address
|
|
708
713
|
*/
|
|
@@ -1329,9 +1334,13 @@ declare const DiamondABI: readonly [{
|
|
|
1329
1334
|
readonly type: "function";
|
|
1330
1335
|
readonly name: "deposit";
|
|
1331
1336
|
readonly inputs: readonly [{
|
|
1332
|
-
readonly name: "
|
|
1337
|
+
readonly name: "assets";
|
|
1333
1338
|
readonly type: "uint256";
|
|
1334
1339
|
readonly internalType: "uint256";
|
|
1340
|
+
}, {
|
|
1341
|
+
readonly name: "receiver";
|
|
1342
|
+
readonly type: "address";
|
|
1343
|
+
readonly internalType: "address";
|
|
1335
1344
|
}];
|
|
1336
1345
|
readonly outputs: readonly [{
|
|
1337
1346
|
readonly name: "shares";
|
|
@@ -1341,14 +1350,26 @@ declare const DiamondABI: readonly [{
|
|
|
1341
1350
|
readonly stateMutability: "nonpayable";
|
|
1342
1351
|
}, {
|
|
1343
1352
|
readonly type: "function";
|
|
1344
|
-
readonly name: "
|
|
1353
|
+
readonly name: "redeem";
|
|
1345
1354
|
readonly inputs: readonly [{
|
|
1346
|
-
readonly name: "
|
|
1355
|
+
readonly name: "shares";
|
|
1347
1356
|
readonly type: "uint256";
|
|
1348
1357
|
readonly internalType: "uint256";
|
|
1358
|
+
}, {
|
|
1359
|
+
readonly name: "receiver";
|
|
1360
|
+
readonly type: "address";
|
|
1361
|
+
readonly internalType: "address";
|
|
1362
|
+
}, {
|
|
1363
|
+
readonly name: "owner";
|
|
1364
|
+
readonly type: "address";
|
|
1365
|
+
readonly internalType: "address";
|
|
1349
1366
|
}];
|
|
1350
1367
|
readonly outputs: readonly [{
|
|
1351
|
-
readonly name: "
|
|
1368
|
+
readonly name: "apUSDOut";
|
|
1369
|
+
readonly type: "uint256";
|
|
1370
|
+
readonly internalType: "uint256";
|
|
1371
|
+
}, {
|
|
1372
|
+
readonly name: "xBNBOut";
|
|
1352
1373
|
readonly type: "uint256";
|
|
1353
1374
|
readonly internalType: "uint256";
|
|
1354
1375
|
}];
|
|
@@ -2807,7 +2828,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2807
2828
|
declare const PRICE_PRECISION: bigint;
|
|
2808
2829
|
declare const BSC_ADDRESSES: {
|
|
2809
2830
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2810
|
-
readonly router: "
|
|
2831
|
+
readonly router: "0x1Ca976d2043dfb785c7F3A17535B3A38c50113f3";
|
|
2811
2832
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2812
2833
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2813
2834
|
readonly sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB";
|
|
@@ -2867,4 +2888,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2867
2888
|
*/
|
|
2868
2889
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2869
2890
|
|
|
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
|
|
2891
|
+
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 RedeemParams, 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 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
|
@@ -97,11 +97,14 @@ interface RedeemXBNBParams {
|
|
|
97
97
|
}
|
|
98
98
|
/** Parameters for depositing to stability pool */
|
|
99
99
|
interface DepositParams {
|
|
100
|
-
|
|
100
|
+
assets: bigint;
|
|
101
|
+
receiver: Address;
|
|
101
102
|
}
|
|
102
|
-
/** Parameters for
|
|
103
|
-
interface
|
|
103
|
+
/** Parameters for redeeming from stability pool */
|
|
104
|
+
interface RedeemParams {
|
|
104
105
|
shares: bigint;
|
|
106
|
+
receiver: Address;
|
|
107
|
+
owner: Address;
|
|
105
108
|
}
|
|
106
109
|
/** Overall protocol statistics */
|
|
107
110
|
interface ProtocolStats {
|
|
@@ -577,11 +580,11 @@ declare class AspanClient extends AspanReadClient {
|
|
|
577
580
|
*/
|
|
578
581
|
deposit(params: DepositParams): Promise<Hash>;
|
|
579
582
|
/**
|
|
580
|
-
*
|
|
581
|
-
* @param params
|
|
583
|
+
* Redeem from stability pool by shares
|
|
584
|
+
* @param params Redeem parameters
|
|
582
585
|
* @returns Transaction hash
|
|
583
586
|
*/
|
|
584
|
-
|
|
587
|
+
redeem(params: RedeemParams): Promise<Hash>;
|
|
585
588
|
/**
|
|
586
589
|
* Harvest yield from LSTs
|
|
587
590
|
* @returns Transaction hash
|
|
@@ -702,7 +705,9 @@ declare class AspanRouterReadClient {
|
|
|
702
705
|
protected readonly publicClient: PublicClient;
|
|
703
706
|
protected readonly routerAddress: Address;
|
|
704
707
|
protected readonly chain: Chain;
|
|
708
|
+
private readonly _addressCache;
|
|
705
709
|
constructor(config: AspanRouterClientConfig);
|
|
710
|
+
protected _getCachedAddress(key: string, fetcher: () => Promise<Address>): Promise<Address>;
|
|
706
711
|
/**
|
|
707
712
|
* Get the default LST address
|
|
708
713
|
*/
|
|
@@ -1329,9 +1334,13 @@ declare const DiamondABI: readonly [{
|
|
|
1329
1334
|
readonly type: "function";
|
|
1330
1335
|
readonly name: "deposit";
|
|
1331
1336
|
readonly inputs: readonly [{
|
|
1332
|
-
readonly name: "
|
|
1337
|
+
readonly name: "assets";
|
|
1333
1338
|
readonly type: "uint256";
|
|
1334
1339
|
readonly internalType: "uint256";
|
|
1340
|
+
}, {
|
|
1341
|
+
readonly name: "receiver";
|
|
1342
|
+
readonly type: "address";
|
|
1343
|
+
readonly internalType: "address";
|
|
1335
1344
|
}];
|
|
1336
1345
|
readonly outputs: readonly [{
|
|
1337
1346
|
readonly name: "shares";
|
|
@@ -1341,14 +1350,26 @@ declare const DiamondABI: readonly [{
|
|
|
1341
1350
|
readonly stateMutability: "nonpayable";
|
|
1342
1351
|
}, {
|
|
1343
1352
|
readonly type: "function";
|
|
1344
|
-
readonly name: "
|
|
1353
|
+
readonly name: "redeem";
|
|
1345
1354
|
readonly inputs: readonly [{
|
|
1346
|
-
readonly name: "
|
|
1355
|
+
readonly name: "shares";
|
|
1347
1356
|
readonly type: "uint256";
|
|
1348
1357
|
readonly internalType: "uint256";
|
|
1358
|
+
}, {
|
|
1359
|
+
readonly name: "receiver";
|
|
1360
|
+
readonly type: "address";
|
|
1361
|
+
readonly internalType: "address";
|
|
1362
|
+
}, {
|
|
1363
|
+
readonly name: "owner";
|
|
1364
|
+
readonly type: "address";
|
|
1365
|
+
readonly internalType: "address";
|
|
1349
1366
|
}];
|
|
1350
1367
|
readonly outputs: readonly [{
|
|
1351
|
-
readonly name: "
|
|
1368
|
+
readonly name: "apUSDOut";
|
|
1369
|
+
readonly type: "uint256";
|
|
1370
|
+
readonly internalType: "uint256";
|
|
1371
|
+
}, {
|
|
1372
|
+
readonly name: "xBNBOut";
|
|
1352
1373
|
readonly type: "uint256";
|
|
1353
1374
|
readonly internalType: "uint256";
|
|
1354
1375
|
}];
|
|
@@ -2807,7 +2828,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2807
2828
|
declare const PRICE_PRECISION: bigint;
|
|
2808
2829
|
declare const BSC_ADDRESSES: {
|
|
2809
2830
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2810
|
-
readonly router: "
|
|
2831
|
+
readonly router: "0x1Ca976d2043dfb785c7F3A17535B3A38c50113f3";
|
|
2811
2832
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2812
2833
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2813
2834
|
readonly sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB";
|
|
@@ -2867,4 +2888,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2867
2888
|
*/
|
|
2868
2889
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2869
2890
|
|
|
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
|
|
2891
|
+
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 RedeemParams, 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 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
|
@@ -303,15 +303,25 @@ var DiamondABI = [
|
|
|
303
303
|
{
|
|
304
304
|
type: "function",
|
|
305
305
|
name: "deposit",
|
|
306
|
-
inputs: [
|
|
306
|
+
inputs: [
|
|
307
|
+
{ name: "assets", type: "uint256", internalType: "uint256" },
|
|
308
|
+
{ name: "receiver", type: "address", internalType: "address" }
|
|
309
|
+
],
|
|
307
310
|
outputs: [{ name: "shares", type: "uint256", internalType: "uint256" }],
|
|
308
311
|
stateMutability: "nonpayable"
|
|
309
312
|
},
|
|
310
313
|
{
|
|
311
314
|
type: "function",
|
|
312
|
-
name: "
|
|
313
|
-
inputs: [
|
|
314
|
-
|
|
315
|
+
name: "redeem",
|
|
316
|
+
inputs: [
|
|
317
|
+
{ name: "shares", type: "uint256", internalType: "uint256" },
|
|
318
|
+
{ name: "receiver", type: "address", internalType: "address" },
|
|
319
|
+
{ name: "owner", type: "address", internalType: "address" }
|
|
320
|
+
],
|
|
321
|
+
outputs: [
|
|
322
|
+
{ name: "apUSDOut", type: "uint256", internalType: "uint256" },
|
|
323
|
+
{ name: "xBNBOut", type: "uint256", internalType: "uint256" }
|
|
324
|
+
],
|
|
315
325
|
stateMutability: "nonpayable"
|
|
316
326
|
},
|
|
317
327
|
{
|
|
@@ -892,7 +902,8 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
892
902
|
this.chain = config.chain ?? import_chains.bsc;
|
|
893
903
|
this.publicClient = (0, import_viem.createPublicClient)({
|
|
894
904
|
chain: this.chain,
|
|
895
|
-
transport: (0, import_viem.http)(config.rpcUrl)
|
|
905
|
+
transport: (0, import_viem.http)(config.rpcUrl),
|
|
906
|
+
batch: { multicall: true }
|
|
896
907
|
});
|
|
897
908
|
}
|
|
898
909
|
/**
|
|
@@ -1801,22 +1812,22 @@ var AspanClient = class extends AspanReadClient {
|
|
|
1801
1812
|
address: this.diamondAddress,
|
|
1802
1813
|
abi: DiamondABI,
|
|
1803
1814
|
functionName: "deposit",
|
|
1804
|
-
args: [params.
|
|
1815
|
+
args: [params.assets, params.receiver]
|
|
1805
1816
|
});
|
|
1806
1817
|
}
|
|
1807
1818
|
/**
|
|
1808
|
-
*
|
|
1809
|
-
* @param params
|
|
1819
|
+
* Redeem from stability pool by shares
|
|
1820
|
+
* @param params Redeem parameters
|
|
1810
1821
|
* @returns Transaction hash
|
|
1811
1822
|
*/
|
|
1812
|
-
async
|
|
1823
|
+
async redeem(params) {
|
|
1813
1824
|
return this.walletClient.writeContract({
|
|
1814
1825
|
chain: this.chain,
|
|
1815
1826
|
account: this.walletClient.account,
|
|
1816
1827
|
address: this.diamondAddress,
|
|
1817
1828
|
abi: DiamondABI,
|
|
1818
|
-
functionName: "
|
|
1819
|
-
args: [params.shares]
|
|
1829
|
+
functionName: "redeem",
|
|
1830
|
+
args: [params.shares, params.receiver, params.owner]
|
|
1820
1831
|
});
|
|
1821
1832
|
}
|
|
1822
1833
|
/**
|
|
@@ -2383,14 +2394,23 @@ var AspanRouterReadClient = class {
|
|
|
2383
2394
|
publicClient;
|
|
2384
2395
|
routerAddress;
|
|
2385
2396
|
chain;
|
|
2397
|
+
_addressCache = /* @__PURE__ */ new Map();
|
|
2386
2398
|
constructor(config) {
|
|
2387
2399
|
this.routerAddress = config.routerAddress;
|
|
2388
2400
|
this.chain = config.chain ?? import_chains2.bsc;
|
|
2389
2401
|
this.publicClient = (0, import_viem2.createPublicClient)({
|
|
2390
2402
|
chain: this.chain,
|
|
2391
|
-
transport: (0, import_viem2.http)(config.rpcUrl)
|
|
2403
|
+
transport: (0, import_viem2.http)(config.rpcUrl),
|
|
2404
|
+
batch: { multicall: true }
|
|
2392
2405
|
});
|
|
2393
2406
|
}
|
|
2407
|
+
async _getCachedAddress(key, fetcher) {
|
|
2408
|
+
const cached = this._addressCache.get(key);
|
|
2409
|
+
if (cached) return cached;
|
|
2410
|
+
const addr = await fetcher();
|
|
2411
|
+
this._addressCache.set(key, addr);
|
|
2412
|
+
return addr;
|
|
2413
|
+
}
|
|
2394
2414
|
// ============ View Functions ============
|
|
2395
2415
|
/**
|
|
2396
2416
|
* Get the default LST address
|
|
@@ -2451,11 +2471,14 @@ var AspanRouterReadClient = class {
|
|
|
2451
2471
|
* Get the Diamond contract address
|
|
2452
2472
|
*/
|
|
2453
2473
|
async getDiamond() {
|
|
2454
|
-
return this.
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2474
|
+
return this._getCachedAddress(
|
|
2475
|
+
"diamond",
|
|
2476
|
+
async () => this.publicClient.readContract({
|
|
2477
|
+
address: this.routerAddress,
|
|
2478
|
+
abi: RouterABI,
|
|
2479
|
+
functionName: "diamond"
|
|
2480
|
+
})
|
|
2481
|
+
);
|
|
2459
2482
|
}
|
|
2460
2483
|
/**
|
|
2461
2484
|
* Preview mint output for a given LST amount
|
|
@@ -2491,39 +2514,41 @@ var AspanRouterReadClient = class {
|
|
|
2491
2514
|
*/
|
|
2492
2515
|
async previewMintByInput(inputToken, inputAmount, targetLST, mintXBNB) {
|
|
2493
2516
|
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
2517
|
let lstAmount = 0n;
|
|
2517
2518
|
const inNorm = inputToken.toLowerCase();
|
|
2518
2519
|
if (inNorm === targetLST.toLowerCase()) {
|
|
2519
2520
|
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
2521
|
} else {
|
|
2526
|
-
|
|
2522
|
+
const [diamond, wbnb, usdt, usdc] = await Promise.all([
|
|
2523
|
+
this.getDiamond(),
|
|
2524
|
+
this.getWBNB(),
|
|
2525
|
+
this.getUSDT(),
|
|
2526
|
+
this.getUSDC()
|
|
2527
|
+
]);
|
|
2528
|
+
const [bnbPrice8, lstPrice] = await Promise.all([
|
|
2529
|
+
this.publicClient.readContract({
|
|
2530
|
+
address: diamond,
|
|
2531
|
+
abi: DiamondABI,
|
|
2532
|
+
functionName: "getBNBPriceUSD"
|
|
2533
|
+
}),
|
|
2534
|
+
this.publicClient.readContract({
|
|
2535
|
+
address: diamond,
|
|
2536
|
+
abi: DiamondABI,
|
|
2537
|
+
functionName: "getLSTPriceUSD",
|
|
2538
|
+
args: [targetLST]
|
|
2539
|
+
})
|
|
2540
|
+
]);
|
|
2541
|
+
const bnbPrice18 = BigInt(bnbPrice8) * 10n ** 10n;
|
|
2542
|
+
const lstPrice18 = BigInt(lstPrice);
|
|
2543
|
+
const one = 10n ** 18n;
|
|
2544
|
+
if (inNorm === import_viem2.zeroAddress.toLowerCase() || inNorm === wbnb.toLowerCase()) {
|
|
2545
|
+
const usdValue = inputAmount * bnbPrice18 / one;
|
|
2546
|
+
lstAmount = lstPrice18 === 0n ? 0n : usdValue * one / lstPrice18;
|
|
2547
|
+
} else if (inNorm === usdt.toLowerCase() || inNorm === usdc.toLowerCase()) {
|
|
2548
|
+
lstAmount = lstPrice18 === 0n ? 0n : inputAmount * one / lstPrice18;
|
|
2549
|
+
} else {
|
|
2550
|
+
throw new Error("Unsupported input token for SDK preview");
|
|
2551
|
+
}
|
|
2527
2552
|
}
|
|
2528
2553
|
const mintedAmount = await this.previewMint(targetLST, lstAmount, mintXBNB);
|
|
2529
2554
|
return { lstAmount, mintedAmount };
|
|
@@ -2535,39 +2560,41 @@ var AspanRouterReadClient = class {
|
|
|
2535
2560
|
async previewRedeemToOutput(lst, redeemXBNB, amount, outputToken) {
|
|
2536
2561
|
const lstAmount = await this.previewRedeem(lst, redeemXBNB, amount);
|
|
2537
2562
|
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
2563
|
let outputAmount = 0n;
|
|
2562
2564
|
const outNorm = outputToken.toLowerCase();
|
|
2563
2565
|
if (outNorm === lst.toLowerCase()) {
|
|
2564
2566
|
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
2567
|
} else {
|
|
2570
|
-
|
|
2568
|
+
const [diamond, wbnb, usdt, usdc] = await Promise.all([
|
|
2569
|
+
this.getDiamond(),
|
|
2570
|
+
this.getWBNB(),
|
|
2571
|
+
this.getUSDT(),
|
|
2572
|
+
this.getUSDC()
|
|
2573
|
+
]);
|
|
2574
|
+
const [bnbPrice8, lstPrice] = await Promise.all([
|
|
2575
|
+
this.publicClient.readContract({
|
|
2576
|
+
address: diamond,
|
|
2577
|
+
abi: DiamondABI,
|
|
2578
|
+
functionName: "getBNBPriceUSD"
|
|
2579
|
+
}),
|
|
2580
|
+
this.publicClient.readContract({
|
|
2581
|
+
address: diamond,
|
|
2582
|
+
abi: DiamondABI,
|
|
2583
|
+
functionName: "getLSTPriceUSD",
|
|
2584
|
+
args: [lst]
|
|
2585
|
+
})
|
|
2586
|
+
]);
|
|
2587
|
+
const bnbPrice18 = BigInt(bnbPrice8) * 10n ** 10n;
|
|
2588
|
+
const lstPrice18 = BigInt(lstPrice);
|
|
2589
|
+
const one = 10n ** 18n;
|
|
2590
|
+
const usdValue = lstAmount * lstPrice18 / one;
|
|
2591
|
+
if (outNorm === import_viem2.zeroAddress.toLowerCase() || outNorm === wbnb.toLowerCase()) {
|
|
2592
|
+
outputAmount = bnbPrice18 === 0n ? 0n : usdValue * one / bnbPrice18;
|
|
2593
|
+
} else if (outNorm === usdt.toLowerCase() || outNorm === usdc.toLowerCase()) {
|
|
2594
|
+
outputAmount = usdValue;
|
|
2595
|
+
} else {
|
|
2596
|
+
throw new Error("Unsupported output token for SDK preview");
|
|
2597
|
+
}
|
|
2571
2598
|
}
|
|
2572
2599
|
return { lstAmount, outputAmount };
|
|
2573
2600
|
}
|
|
@@ -2600,60 +2627,84 @@ var AspanRouterReadClient = class {
|
|
|
2600
2627
|
}
|
|
2601
2628
|
// ============ Token Address Getters ============
|
|
2602
2629
|
async getWBNB() {
|
|
2603
|
-
return this.
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2630
|
+
return this._getCachedAddress(
|
|
2631
|
+
"wbnb",
|
|
2632
|
+
async () => this.publicClient.readContract({
|
|
2633
|
+
address: this.routerAddress,
|
|
2634
|
+
abi: RouterABI,
|
|
2635
|
+
functionName: "wbnb"
|
|
2636
|
+
})
|
|
2637
|
+
);
|
|
2608
2638
|
}
|
|
2609
2639
|
async getUSDT() {
|
|
2610
|
-
return this.
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2640
|
+
return this._getCachedAddress(
|
|
2641
|
+
"usdt",
|
|
2642
|
+
async () => this.publicClient.readContract({
|
|
2643
|
+
address: this.routerAddress,
|
|
2644
|
+
abi: RouterABI,
|
|
2645
|
+
functionName: "usdt"
|
|
2646
|
+
})
|
|
2647
|
+
);
|
|
2615
2648
|
}
|
|
2616
2649
|
async getUSDC() {
|
|
2617
|
-
return this.
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2650
|
+
return this._getCachedAddress(
|
|
2651
|
+
"usdc",
|
|
2652
|
+
async () => this.publicClient.readContract({
|
|
2653
|
+
address: this.routerAddress,
|
|
2654
|
+
abi: RouterABI,
|
|
2655
|
+
functionName: "usdc"
|
|
2656
|
+
})
|
|
2657
|
+
);
|
|
2622
2658
|
}
|
|
2623
2659
|
async getSlisBNB() {
|
|
2624
|
-
return this.
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2660
|
+
return this._getCachedAddress(
|
|
2661
|
+
"slisBNB",
|
|
2662
|
+
async () => this.publicClient.readContract({
|
|
2663
|
+
address: this.routerAddress,
|
|
2664
|
+
abi: RouterABI,
|
|
2665
|
+
functionName: "slisBNB"
|
|
2666
|
+
})
|
|
2667
|
+
);
|
|
2629
2668
|
}
|
|
2630
2669
|
async getAsBNB() {
|
|
2631
|
-
return this.
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2670
|
+
return this._getCachedAddress(
|
|
2671
|
+
"asBNB",
|
|
2672
|
+
async () => this.publicClient.readContract({
|
|
2673
|
+
address: this.routerAddress,
|
|
2674
|
+
abi: RouterABI,
|
|
2675
|
+
functionName: "asBNB"
|
|
2676
|
+
})
|
|
2677
|
+
);
|
|
2636
2678
|
}
|
|
2637
2679
|
async getWclisBNB() {
|
|
2638
|
-
return this.
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2680
|
+
return this._getCachedAddress(
|
|
2681
|
+
"wclisBNB",
|
|
2682
|
+
async () => this.publicClient.readContract({
|
|
2683
|
+
address: this.routerAddress,
|
|
2684
|
+
abi: RouterABI,
|
|
2685
|
+
functionName: "wclisBNB"
|
|
2686
|
+
})
|
|
2687
|
+
);
|
|
2643
2688
|
}
|
|
2644
2689
|
async getApUSD() {
|
|
2645
|
-
return this.
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2690
|
+
return this._getCachedAddress(
|
|
2691
|
+
"apUSD",
|
|
2692
|
+
async () => this.publicClient.readContract({
|
|
2693
|
+
address: this.routerAddress,
|
|
2694
|
+
abi: RouterABI,
|
|
2695
|
+
functionName: "apUSD"
|
|
2696
|
+
})
|
|
2697
|
+
);
|
|
2650
2698
|
}
|
|
2651
2699
|
async getXBNB() {
|
|
2652
|
-
return this.
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2700
|
+
return this._getCachedAddress(
|
|
2701
|
+
"xBNB",
|
|
2702
|
+
async () => this.publicClient.readContract({
|
|
2703
|
+
address: this.routerAddress,
|
|
2704
|
+
abi: RouterABI,
|
|
2705
|
+
functionName: "xBNB"
|
|
2706
|
+
})
|
|
2707
|
+
);
|
|
2657
2708
|
}
|
|
2658
2709
|
};
|
|
2659
2710
|
var AspanRouterClient = class extends AspanRouterReadClient {
|
|
@@ -2909,7 +2960,7 @@ var BPS_PRECISION = 10000n;
|
|
|
2909
2960
|
var PRICE_PRECISION = 10n ** 8n;
|
|
2910
2961
|
var BSC_ADDRESSES = {
|
|
2911
2962
|
diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
|
|
2912
|
-
router: "
|
|
2963
|
+
router: "0x1Ca976d2043dfb785c7F3A17535B3A38c50113f3",
|
|
2913
2964
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
|
|
2914
2965
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
|
|
2915
2966
|
sApUSD: "0x896770Dba7c0481539E25aaB56bE285ECF6D65eB",
|