@aspan/sdk 0.4.1 → 0.4.3
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 +80 -3
- package/dist/index.d.ts +80 -3
- package/dist/index.js +108 -3
- package/dist/index.mjs +95 -2
- package/package.json +1 -1
- package/src/bot/services/risk-keeper.ts +29 -31
- package/src/client.ts +106 -1
- package/src/index.ts +25 -1
- package/src/router.ts +69 -0
package/dist/index.d.mts
CHANGED
|
@@ -385,6 +385,20 @@ interface UnstakeClaimedEvent {
|
|
|
385
385
|
bnbAmount: bigint;
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
+
/** Pharos Atlantic Testnet chain definition */
|
|
389
|
+
declare const pharosTestnet: Chain;
|
|
390
|
+
/** Supported chain IDs */
|
|
391
|
+
declare const CHAIN_IDS: {
|
|
392
|
+
readonly BSC: 56;
|
|
393
|
+
readonly BSC_TESTNET: 97;
|
|
394
|
+
readonly PHAROS: 688689;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Get the viem Chain object for a given chainId.
|
|
398
|
+
* @throws if the chainId is not supported
|
|
399
|
+
*/
|
|
400
|
+
declare function getChainById(chainId: number): Chain;
|
|
401
|
+
|
|
388
402
|
interface AspanClientConfig {
|
|
389
403
|
/** Diamond contract address */
|
|
390
404
|
diamondAddress: Address;
|
|
@@ -404,7 +418,7 @@ interface AspanWriteClientConfig extends AspanClientConfig {
|
|
|
404
418
|
*/
|
|
405
419
|
declare class AspanReadClient {
|
|
406
420
|
protected readonly publicClient: PublicClient;
|
|
407
|
-
|
|
421
|
+
readonly diamondAddress: Address;
|
|
408
422
|
protected readonly chain: Chain;
|
|
409
423
|
private static readonly ZERO_SUPPLY_ERROR_SIGNATURES;
|
|
410
424
|
constructor(config: AspanClientConfig);
|
|
@@ -591,6 +605,33 @@ declare function createAspanTestnetReadClient(diamondAddress: Address, rpcUrl?:
|
|
|
591
605
|
* Create a full client for BSC testnet
|
|
592
606
|
*/
|
|
593
607
|
declare function createAspanTestnetClient(diamondAddress: Address, account: Account, rpcUrl?: string): AspanClient;
|
|
608
|
+
/**
|
|
609
|
+
* Create a read-only client for Pharos Atlantic Testnet
|
|
610
|
+
*/
|
|
611
|
+
declare function createAspanPharosReadClient(diamondAddress: Address, rpcUrl?: string): AspanReadClient;
|
|
612
|
+
/**
|
|
613
|
+
* Create a full client for Pharos Atlantic Testnet
|
|
614
|
+
*/
|
|
615
|
+
declare function createAspanPharosClient(diamondAddress: Address, account: Account, rpcUrl?: string): AspanClient;
|
|
616
|
+
/**
|
|
617
|
+
* Create a read-only Aspan client by chainId.
|
|
618
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
619
|
+
*
|
|
620
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
621
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
622
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
623
|
+
*/
|
|
624
|
+
declare function createAspanReadClientForChain(diamondAddress: Address, chainId?: number, rpcUrl?: string): AspanReadClient;
|
|
625
|
+
/**
|
|
626
|
+
* Create a write Aspan client by chainId using an external wagmi WalletClient.
|
|
627
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
628
|
+
*
|
|
629
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
630
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
631
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
632
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
633
|
+
*/
|
|
634
|
+
declare function createAspanWriteClientForChain(diamondAddress: Address, chainId: number | undefined, walletClient: WalletClient<Transport, Chain, Account>, rpcUrl?: string): AspanClient;
|
|
594
635
|
|
|
595
636
|
interface AspanRouterClientConfig {
|
|
596
637
|
/** Router contract address */
|
|
@@ -730,6 +771,33 @@ declare function createRouterTestnetReadClient(routerAddress: Address, rpcUrl?:
|
|
|
730
771
|
* Create a full router client for BSC testnet
|
|
731
772
|
*/
|
|
732
773
|
declare function createRouterTestnetClient(routerAddress: Address, account: Account, rpcUrl?: string): AspanRouterClient;
|
|
774
|
+
/**
|
|
775
|
+
* Create a read-only router client for Pharos Atlantic Testnet
|
|
776
|
+
*/
|
|
777
|
+
declare function createRouterPharosReadClient(routerAddress: Address, rpcUrl?: string): AspanRouterReadClient;
|
|
778
|
+
/**
|
|
779
|
+
* Create a full router client for Pharos Atlantic Testnet
|
|
780
|
+
*/
|
|
781
|
+
declare function createRouterPharosClient(routerAddress: Address, account: Account, rpcUrl?: string): AspanRouterClient;
|
|
782
|
+
/**
|
|
783
|
+
* Create a read-only AspanRouter client by chainId.
|
|
784
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
785
|
+
*
|
|
786
|
+
* @param routerAddress Router contract address for the target chain.
|
|
787
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
788
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
789
|
+
*/
|
|
790
|
+
declare function createRouterReadClientForChain(routerAddress: Address, chainId?: number, rpcUrl?: string): AspanRouterReadClient;
|
|
791
|
+
/**
|
|
792
|
+
* Create a write AspanRouter client by chainId using an external wagmi WalletClient.
|
|
793
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
794
|
+
*
|
|
795
|
+
* @param routerAddress Router contract address for the target chain.
|
|
796
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
797
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
798
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
799
|
+
*/
|
|
800
|
+
declare function createRouterWriteClientForChain(routerAddress: Address, chainId: number | undefined, walletClient: WalletClient<Transport, Chain, Account>, rpcUrl?: string): AspanRouterClient;
|
|
733
801
|
|
|
734
802
|
/**
|
|
735
803
|
* Combined Diamond ABI - includes all facet functions
|
|
@@ -2574,7 +2642,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2574
2642
|
declare const PRICE_PRECISION: bigint;
|
|
2575
2643
|
declare const BSC_ADDRESSES: {
|
|
2576
2644
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2577
|
-
readonly router: "
|
|
2645
|
+
readonly router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6";
|
|
2578
2646
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2579
2647
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2580
2648
|
readonly sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF";
|
|
@@ -2585,6 +2653,15 @@ declare const BSC_ADDRESSES: {
|
|
|
2585
2653
|
readonly USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
|
|
2586
2654
|
readonly WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
|
2587
2655
|
};
|
|
2656
|
+
declare const PHAROS_ADDRESSES: {
|
|
2657
|
+
readonly diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8";
|
|
2658
|
+
readonly apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4";
|
|
2659
|
+
readonly xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576";
|
|
2660
|
+
readonly sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8";
|
|
2661
|
+
readonly mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18";
|
|
2662
|
+
readonly mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682";
|
|
2663
|
+
readonly mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9";
|
|
2664
|
+
};
|
|
2588
2665
|
/**
|
|
2589
2666
|
* Format a bigint amount to human-readable string with decimals
|
|
2590
2667
|
* @param amount Amount in wei (18 decimals)
|
|
@@ -2625,4 +2702,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2625
2702
|
*/
|
|
2626
2703
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2627
2704
|
|
|
2628
|
-
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, 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 WithdrawAssetsParams, type WithdrawParams, type WithdrawalRequestInfo, type WithdrawnEvent, type XBNBMintedEvent, type XBNBRedeemedEvent, type YieldHarvestedEvent, type YieldStats, calculateAPY, createAspanClient, createAspanReadClient, createAspanTestnetClient, createAspanTestnetReadClient, createRouterClient, createRouterReadClient, createRouterTestnetClient, createRouterTestnetReadClient, encodeV3Path, formatAmount, formatCR, formatFeeBPS, formatPriceUSD, parseAmount };
|
|
2705
|
+
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 WithdrawAssetsParams, 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
|
@@ -385,6 +385,20 @@ interface UnstakeClaimedEvent {
|
|
|
385
385
|
bnbAmount: bigint;
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
+
/** Pharos Atlantic Testnet chain definition */
|
|
389
|
+
declare const pharosTestnet: Chain;
|
|
390
|
+
/** Supported chain IDs */
|
|
391
|
+
declare const CHAIN_IDS: {
|
|
392
|
+
readonly BSC: 56;
|
|
393
|
+
readonly BSC_TESTNET: 97;
|
|
394
|
+
readonly PHAROS: 688689;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Get the viem Chain object for a given chainId.
|
|
398
|
+
* @throws if the chainId is not supported
|
|
399
|
+
*/
|
|
400
|
+
declare function getChainById(chainId: number): Chain;
|
|
401
|
+
|
|
388
402
|
interface AspanClientConfig {
|
|
389
403
|
/** Diamond contract address */
|
|
390
404
|
diamondAddress: Address;
|
|
@@ -404,7 +418,7 @@ interface AspanWriteClientConfig extends AspanClientConfig {
|
|
|
404
418
|
*/
|
|
405
419
|
declare class AspanReadClient {
|
|
406
420
|
protected readonly publicClient: PublicClient;
|
|
407
|
-
|
|
421
|
+
readonly diamondAddress: Address;
|
|
408
422
|
protected readonly chain: Chain;
|
|
409
423
|
private static readonly ZERO_SUPPLY_ERROR_SIGNATURES;
|
|
410
424
|
constructor(config: AspanClientConfig);
|
|
@@ -591,6 +605,33 @@ declare function createAspanTestnetReadClient(diamondAddress: Address, rpcUrl?:
|
|
|
591
605
|
* Create a full client for BSC testnet
|
|
592
606
|
*/
|
|
593
607
|
declare function createAspanTestnetClient(diamondAddress: Address, account: Account, rpcUrl?: string): AspanClient;
|
|
608
|
+
/**
|
|
609
|
+
* Create a read-only client for Pharos Atlantic Testnet
|
|
610
|
+
*/
|
|
611
|
+
declare function createAspanPharosReadClient(diamondAddress: Address, rpcUrl?: string): AspanReadClient;
|
|
612
|
+
/**
|
|
613
|
+
* Create a full client for Pharos Atlantic Testnet
|
|
614
|
+
*/
|
|
615
|
+
declare function createAspanPharosClient(diamondAddress: Address, account: Account, rpcUrl?: string): AspanClient;
|
|
616
|
+
/**
|
|
617
|
+
* Create a read-only Aspan client by chainId.
|
|
618
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
619
|
+
*
|
|
620
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
621
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
622
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
623
|
+
*/
|
|
624
|
+
declare function createAspanReadClientForChain(diamondAddress: Address, chainId?: number, rpcUrl?: string): AspanReadClient;
|
|
625
|
+
/**
|
|
626
|
+
* Create a write Aspan client by chainId using an external wagmi WalletClient.
|
|
627
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
628
|
+
*
|
|
629
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
630
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
631
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
632
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
633
|
+
*/
|
|
634
|
+
declare function createAspanWriteClientForChain(diamondAddress: Address, chainId: number | undefined, walletClient: WalletClient<Transport, Chain, Account>, rpcUrl?: string): AspanClient;
|
|
594
635
|
|
|
595
636
|
interface AspanRouterClientConfig {
|
|
596
637
|
/** Router contract address */
|
|
@@ -730,6 +771,33 @@ declare function createRouterTestnetReadClient(routerAddress: Address, rpcUrl?:
|
|
|
730
771
|
* Create a full router client for BSC testnet
|
|
731
772
|
*/
|
|
732
773
|
declare function createRouterTestnetClient(routerAddress: Address, account: Account, rpcUrl?: string): AspanRouterClient;
|
|
774
|
+
/**
|
|
775
|
+
* Create a read-only router client for Pharos Atlantic Testnet
|
|
776
|
+
*/
|
|
777
|
+
declare function createRouterPharosReadClient(routerAddress: Address, rpcUrl?: string): AspanRouterReadClient;
|
|
778
|
+
/**
|
|
779
|
+
* Create a full router client for Pharos Atlantic Testnet
|
|
780
|
+
*/
|
|
781
|
+
declare function createRouterPharosClient(routerAddress: Address, account: Account, rpcUrl?: string): AspanRouterClient;
|
|
782
|
+
/**
|
|
783
|
+
* Create a read-only AspanRouter client by chainId.
|
|
784
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
785
|
+
*
|
|
786
|
+
* @param routerAddress Router contract address for the target chain.
|
|
787
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
788
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
789
|
+
*/
|
|
790
|
+
declare function createRouterReadClientForChain(routerAddress: Address, chainId?: number, rpcUrl?: string): AspanRouterReadClient;
|
|
791
|
+
/**
|
|
792
|
+
* Create a write AspanRouter client by chainId using an external wagmi WalletClient.
|
|
793
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
794
|
+
*
|
|
795
|
+
* @param routerAddress Router contract address for the target chain.
|
|
796
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
797
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
798
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
799
|
+
*/
|
|
800
|
+
declare function createRouterWriteClientForChain(routerAddress: Address, chainId: number | undefined, walletClient: WalletClient<Transport, Chain, Account>, rpcUrl?: string): AspanRouterClient;
|
|
733
801
|
|
|
734
802
|
/**
|
|
735
803
|
* Combined Diamond ABI - includes all facet functions
|
|
@@ -2574,7 +2642,7 @@ declare const BPS_PRECISION = 10000n;
|
|
|
2574
2642
|
declare const PRICE_PRECISION: bigint;
|
|
2575
2643
|
declare const BSC_ADDRESSES: {
|
|
2576
2644
|
readonly diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78";
|
|
2577
|
-
readonly router: "
|
|
2645
|
+
readonly router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6";
|
|
2578
2646
|
readonly apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287";
|
|
2579
2647
|
readonly xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43";
|
|
2580
2648
|
readonly sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF";
|
|
@@ -2585,6 +2653,15 @@ declare const BSC_ADDRESSES: {
|
|
|
2585
2653
|
readonly USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
|
|
2586
2654
|
readonly WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
|
2587
2655
|
};
|
|
2656
|
+
declare const PHAROS_ADDRESSES: {
|
|
2657
|
+
readonly diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8";
|
|
2658
|
+
readonly apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4";
|
|
2659
|
+
readonly xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576";
|
|
2660
|
+
readonly sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8";
|
|
2661
|
+
readonly mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18";
|
|
2662
|
+
readonly mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682";
|
|
2663
|
+
readonly mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9";
|
|
2664
|
+
};
|
|
2588
2665
|
/**
|
|
2589
2666
|
* Format a bigint amount to human-readable string with decimals
|
|
2590
2667
|
* @param amount Amount in wei (18 decimals)
|
|
@@ -2625,4 +2702,4 @@ declare function formatPriceUSD(price: bigint): string;
|
|
|
2625
2702
|
*/
|
|
2626
2703
|
declare function calculateAPY(previousRate: bigint, currentRate: bigint, periodDays: number): number;
|
|
2627
2704
|
|
|
2628
|
-
export { type ApUSDMintedEvent, type ApUSDRedeemedEvent, AspanClient, type AspanClientConfig, AspanReadClient, AspanRouterClient, type AspanRouterClientConfig, AspanRouterReadClient, type AspanRouterWriteClientConfig, type AspanWriteClientConfig, BPS_PRECISION, BSC_ADDRESSES, type BigIntString, type CurrentFeeTier, type CurrentFees, type DepositParams, type DepositedEvent, DiamondABI, type ExpectedOutput, type FeeTier, type LSTInfo, type LSTYieldInfo, type MintApUSDParams, type MintXBNBParams, type OracleBounds, 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 WithdrawAssetsParams, type WithdrawParams, type WithdrawalRequestInfo, type WithdrawnEvent, type XBNBMintedEvent, type XBNBRedeemedEvent, type YieldHarvestedEvent, type YieldStats, calculateAPY, createAspanClient, createAspanReadClient, createAspanTestnetClient, createAspanTestnetReadClient, createRouterClient, createRouterReadClient, createRouterTestnetClient, createRouterTestnetReadClient, encodeV3Path, formatAmount, formatCR, formatFeeBPS, formatPriceUSD, parseAmount };
|
|
2705
|
+
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 WithdrawAssetsParams, 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
|
@@ -26,25 +26,37 @@ __export(index_exports, {
|
|
|
26
26
|
AspanRouterReadClient: () => AspanRouterReadClient,
|
|
27
27
|
BPS_PRECISION: () => BPS_PRECISION,
|
|
28
28
|
BSC_ADDRESSES: () => BSC_ADDRESSES,
|
|
29
|
+
CHAIN_IDS: () => CHAIN_IDS,
|
|
29
30
|
DiamondABI: () => DiamondABI,
|
|
31
|
+
PHAROS_ADDRESSES: () => PHAROS_ADDRESSES,
|
|
30
32
|
PRECISION: () => PRECISION,
|
|
31
33
|
PRICE_PRECISION: () => PRICE_PRECISION,
|
|
32
34
|
RouterABI: () => RouterABI,
|
|
33
35
|
calculateAPY: () => calculateAPY,
|
|
34
36
|
createAspanClient: () => createAspanClient,
|
|
37
|
+
createAspanPharosClient: () => createAspanPharosClient,
|
|
38
|
+
createAspanPharosReadClient: () => createAspanPharosReadClient,
|
|
35
39
|
createAspanReadClient: () => createAspanReadClient,
|
|
40
|
+
createAspanReadClientForChain: () => createAspanReadClientForChain,
|
|
36
41
|
createAspanTestnetClient: () => createAspanTestnetClient,
|
|
37
42
|
createAspanTestnetReadClient: () => createAspanTestnetReadClient,
|
|
43
|
+
createAspanWriteClientForChain: () => createAspanWriteClientForChain,
|
|
38
44
|
createRouterClient: () => createRouterClient,
|
|
45
|
+
createRouterPharosClient: () => createRouterPharosClient,
|
|
46
|
+
createRouterPharosReadClient: () => createRouterPharosReadClient,
|
|
39
47
|
createRouterReadClient: () => createRouterReadClient,
|
|
48
|
+
createRouterReadClientForChain: () => createRouterReadClientForChain,
|
|
40
49
|
createRouterTestnetClient: () => createRouterTestnetClient,
|
|
41
50
|
createRouterTestnetReadClient: () => createRouterTestnetReadClient,
|
|
51
|
+
createRouterWriteClientForChain: () => createRouterWriteClientForChain,
|
|
42
52
|
encodeV3Path: () => encodeV3Path,
|
|
43
53
|
formatAmount: () => formatAmount,
|
|
44
54
|
formatCR: () => formatCR,
|
|
45
55
|
formatFeeBPS: () => formatFeeBPS,
|
|
46
56
|
formatPriceUSD: () => formatPriceUSD,
|
|
47
|
-
|
|
57
|
+
getChainById: () => getChainById,
|
|
58
|
+
parseAmount: () => parseAmount,
|
|
59
|
+
pharosTestnet: () => pharosTestnet
|
|
48
60
|
});
|
|
49
61
|
module.exports = __toCommonJS(index_exports);
|
|
50
62
|
|
|
@@ -650,6 +662,32 @@ var DiamondABI = [
|
|
|
650
662
|
];
|
|
651
663
|
|
|
652
664
|
// src/client.ts
|
|
665
|
+
var pharosTestnet = {
|
|
666
|
+
id: 688689,
|
|
667
|
+
name: "Pharos Atlantic Testnet",
|
|
668
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
669
|
+
rpcUrls: {
|
|
670
|
+
default: { http: ["https://atlantic.dplabs-internal.com"] }
|
|
671
|
+
},
|
|
672
|
+
blockExplorers: {
|
|
673
|
+
default: { name: "Pharos Explorer", url: "https://atlantic.pharosscan.xyz" }
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
var CHAIN_IDS = {
|
|
677
|
+
BSC: 56,
|
|
678
|
+
BSC_TESTNET: 97,
|
|
679
|
+
PHAROS: 688689
|
|
680
|
+
};
|
|
681
|
+
var CHAIN_MAP = {
|
|
682
|
+
[CHAIN_IDS.BSC]: import_chains.bsc,
|
|
683
|
+
[CHAIN_IDS.BSC_TESTNET]: import_chains.bscTestnet,
|
|
684
|
+
[CHAIN_IDS.PHAROS]: pharosTestnet
|
|
685
|
+
};
|
|
686
|
+
function getChainById(chainId) {
|
|
687
|
+
const chain = CHAIN_MAP[chainId];
|
|
688
|
+
if (!chain) throw new Error(`[Aspan SDK] Unsupported chainId: ${chainId}`);
|
|
689
|
+
return chain;
|
|
690
|
+
}
|
|
653
691
|
var AspanReadClient = class _AspanReadClient {
|
|
654
692
|
publicClient;
|
|
655
693
|
diamondAddress;
|
|
@@ -1621,6 +1659,29 @@ function createAspanTestnetClient(diamondAddress, account, rpcUrl) {
|
|
|
1621
1659
|
rpcUrl
|
|
1622
1660
|
});
|
|
1623
1661
|
}
|
|
1662
|
+
function createAspanPharosReadClient(diamondAddress, rpcUrl) {
|
|
1663
|
+
return new AspanReadClient({
|
|
1664
|
+
diamondAddress,
|
|
1665
|
+
chain: pharosTestnet,
|
|
1666
|
+
rpcUrl
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
function createAspanPharosClient(diamondAddress, account, rpcUrl) {
|
|
1670
|
+
return new AspanClient({
|
|
1671
|
+
diamondAddress,
|
|
1672
|
+
account,
|
|
1673
|
+
chain: pharosTestnet,
|
|
1674
|
+
rpcUrl
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
function createAspanReadClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
|
|
1678
|
+
const chain = getChainById(chainId);
|
|
1679
|
+
return new AspanReadClient({ diamondAddress, chain, rpcUrl });
|
|
1680
|
+
}
|
|
1681
|
+
function createAspanWriteClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
|
|
1682
|
+
const chain = getChainById(chainId);
|
|
1683
|
+
return new AspanClient({ diamondAddress, chain, walletClient, rpcUrl });
|
|
1684
|
+
}
|
|
1624
1685
|
|
|
1625
1686
|
// src/router.ts
|
|
1626
1687
|
var import_viem2 = require("viem");
|
|
@@ -2387,6 +2448,29 @@ function createRouterTestnetClient(routerAddress, account, rpcUrl) {
|
|
|
2387
2448
|
rpcUrl
|
|
2388
2449
|
});
|
|
2389
2450
|
}
|
|
2451
|
+
function createRouterPharosReadClient(routerAddress, rpcUrl) {
|
|
2452
|
+
return new AspanRouterReadClient({
|
|
2453
|
+
routerAddress,
|
|
2454
|
+
chain: pharosTestnet,
|
|
2455
|
+
rpcUrl
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
function createRouterPharosClient(routerAddress, account, rpcUrl) {
|
|
2459
|
+
return new AspanRouterClient({
|
|
2460
|
+
routerAddress,
|
|
2461
|
+
account,
|
|
2462
|
+
chain: pharosTestnet,
|
|
2463
|
+
rpcUrl
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
function createRouterReadClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
|
|
2467
|
+
const chain = getChainById(chainId);
|
|
2468
|
+
return new AspanRouterReadClient({ routerAddress, chain, rpcUrl });
|
|
2469
|
+
}
|
|
2470
|
+
function createRouterWriteClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
|
|
2471
|
+
const chain = getChainById(chainId);
|
|
2472
|
+
return new AspanRouterClient({ routerAddress, chain, walletClient, rpcUrl });
|
|
2473
|
+
}
|
|
2390
2474
|
|
|
2391
2475
|
// src/types.ts
|
|
2392
2476
|
function encodeV3Path(tokens, fees) {
|
|
@@ -2407,7 +2491,7 @@ var BPS_PRECISION = 10000n;
|
|
|
2407
2491
|
var PRICE_PRECISION = 10n ** 8n;
|
|
2408
2492
|
var BSC_ADDRESSES = {
|
|
2409
2493
|
diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
|
|
2410
|
-
router: "
|
|
2494
|
+
router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6",
|
|
2411
2495
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
|
|
2412
2496
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
|
|
2413
2497
|
sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF",
|
|
@@ -2420,6 +2504,15 @@ var BSC_ADDRESSES = {
|
|
|
2420
2504
|
USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
2421
2505
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
|
|
2422
2506
|
};
|
|
2507
|
+
var PHAROS_ADDRESSES = {
|
|
2508
|
+
diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8",
|
|
2509
|
+
apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4",
|
|
2510
|
+
xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576",
|
|
2511
|
+
sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8",
|
|
2512
|
+
mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18",
|
|
2513
|
+
mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682",
|
|
2514
|
+
mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9"
|
|
2515
|
+
};
|
|
2423
2516
|
function formatAmount(amount, decimals = 4) {
|
|
2424
2517
|
const divisor = 10n ** BigInt(18 - decimals);
|
|
2425
2518
|
const scaled = amount / divisor;
|
|
@@ -2459,23 +2552,35 @@ function calculateAPY(previousRate, currentRate, periodDays) {
|
|
|
2459
2552
|
AspanRouterReadClient,
|
|
2460
2553
|
BPS_PRECISION,
|
|
2461
2554
|
BSC_ADDRESSES,
|
|
2555
|
+
CHAIN_IDS,
|
|
2462
2556
|
DiamondABI,
|
|
2557
|
+
PHAROS_ADDRESSES,
|
|
2463
2558
|
PRECISION,
|
|
2464
2559
|
PRICE_PRECISION,
|
|
2465
2560
|
RouterABI,
|
|
2466
2561
|
calculateAPY,
|
|
2467
2562
|
createAspanClient,
|
|
2563
|
+
createAspanPharosClient,
|
|
2564
|
+
createAspanPharosReadClient,
|
|
2468
2565
|
createAspanReadClient,
|
|
2566
|
+
createAspanReadClientForChain,
|
|
2469
2567
|
createAspanTestnetClient,
|
|
2470
2568
|
createAspanTestnetReadClient,
|
|
2569
|
+
createAspanWriteClientForChain,
|
|
2471
2570
|
createRouterClient,
|
|
2571
|
+
createRouterPharosClient,
|
|
2572
|
+
createRouterPharosReadClient,
|
|
2472
2573
|
createRouterReadClient,
|
|
2574
|
+
createRouterReadClientForChain,
|
|
2473
2575
|
createRouterTestnetClient,
|
|
2474
2576
|
createRouterTestnetReadClient,
|
|
2577
|
+
createRouterWriteClientForChain,
|
|
2475
2578
|
encodeV3Path,
|
|
2476
2579
|
formatAmount,
|
|
2477
2580
|
formatCR,
|
|
2478
2581
|
formatFeeBPS,
|
|
2479
2582
|
formatPriceUSD,
|
|
2480
|
-
|
|
2583
|
+
getChainById,
|
|
2584
|
+
parseAmount,
|
|
2585
|
+
pharosTestnet
|
|
2481
2586
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -604,6 +604,32 @@ var DiamondABI = [
|
|
|
604
604
|
];
|
|
605
605
|
|
|
606
606
|
// src/client.ts
|
|
607
|
+
var pharosTestnet = {
|
|
608
|
+
id: 688689,
|
|
609
|
+
name: "Pharos Atlantic Testnet",
|
|
610
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
611
|
+
rpcUrls: {
|
|
612
|
+
default: { http: ["https://atlantic.dplabs-internal.com"] }
|
|
613
|
+
},
|
|
614
|
+
blockExplorers: {
|
|
615
|
+
default: { name: "Pharos Explorer", url: "https://atlantic.pharosscan.xyz" }
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var CHAIN_IDS = {
|
|
619
|
+
BSC: 56,
|
|
620
|
+
BSC_TESTNET: 97,
|
|
621
|
+
PHAROS: 688689
|
|
622
|
+
};
|
|
623
|
+
var CHAIN_MAP = {
|
|
624
|
+
[CHAIN_IDS.BSC]: bsc,
|
|
625
|
+
[CHAIN_IDS.BSC_TESTNET]: bscTestnet,
|
|
626
|
+
[CHAIN_IDS.PHAROS]: pharosTestnet
|
|
627
|
+
};
|
|
628
|
+
function getChainById(chainId) {
|
|
629
|
+
const chain = CHAIN_MAP[chainId];
|
|
630
|
+
if (!chain) throw new Error(`[Aspan SDK] Unsupported chainId: ${chainId}`);
|
|
631
|
+
return chain;
|
|
632
|
+
}
|
|
607
633
|
var AspanReadClient = class _AspanReadClient {
|
|
608
634
|
publicClient;
|
|
609
635
|
diamondAddress;
|
|
@@ -1575,6 +1601,29 @@ function createAspanTestnetClient(diamondAddress, account, rpcUrl) {
|
|
|
1575
1601
|
rpcUrl
|
|
1576
1602
|
});
|
|
1577
1603
|
}
|
|
1604
|
+
function createAspanPharosReadClient(diamondAddress, rpcUrl) {
|
|
1605
|
+
return new AspanReadClient({
|
|
1606
|
+
diamondAddress,
|
|
1607
|
+
chain: pharosTestnet,
|
|
1608
|
+
rpcUrl
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
function createAspanPharosClient(diamondAddress, account, rpcUrl) {
|
|
1612
|
+
return new AspanClient({
|
|
1613
|
+
diamondAddress,
|
|
1614
|
+
account,
|
|
1615
|
+
chain: pharosTestnet,
|
|
1616
|
+
rpcUrl
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
function createAspanReadClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
|
|
1620
|
+
const chain = getChainById(chainId);
|
|
1621
|
+
return new AspanReadClient({ diamondAddress, chain, rpcUrl });
|
|
1622
|
+
}
|
|
1623
|
+
function createAspanWriteClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
|
|
1624
|
+
const chain = getChainById(chainId);
|
|
1625
|
+
return new AspanClient({ diamondAddress, chain, walletClient, rpcUrl });
|
|
1626
|
+
}
|
|
1578
1627
|
|
|
1579
1628
|
// src/router.ts
|
|
1580
1629
|
import {
|
|
@@ -2346,6 +2395,29 @@ function createRouterTestnetClient(routerAddress, account, rpcUrl) {
|
|
|
2346
2395
|
rpcUrl
|
|
2347
2396
|
});
|
|
2348
2397
|
}
|
|
2398
|
+
function createRouterPharosReadClient(routerAddress, rpcUrl) {
|
|
2399
|
+
return new AspanRouterReadClient({
|
|
2400
|
+
routerAddress,
|
|
2401
|
+
chain: pharosTestnet,
|
|
2402
|
+
rpcUrl
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
function createRouterPharosClient(routerAddress, account, rpcUrl) {
|
|
2406
|
+
return new AspanRouterClient({
|
|
2407
|
+
routerAddress,
|
|
2408
|
+
account,
|
|
2409
|
+
chain: pharosTestnet,
|
|
2410
|
+
rpcUrl
|
|
2411
|
+
});
|
|
2412
|
+
}
|
|
2413
|
+
function createRouterReadClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
|
|
2414
|
+
const chain = getChainById(chainId);
|
|
2415
|
+
return new AspanRouterReadClient({ routerAddress, chain, rpcUrl });
|
|
2416
|
+
}
|
|
2417
|
+
function createRouterWriteClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
|
|
2418
|
+
const chain = getChainById(chainId);
|
|
2419
|
+
return new AspanRouterClient({ routerAddress, chain, walletClient, rpcUrl });
|
|
2420
|
+
}
|
|
2349
2421
|
|
|
2350
2422
|
// src/types.ts
|
|
2351
2423
|
function encodeV3Path(tokens, fees) {
|
|
@@ -2366,7 +2438,7 @@ var BPS_PRECISION = 10000n;
|
|
|
2366
2438
|
var PRICE_PRECISION = 10n ** 8n;
|
|
2367
2439
|
var BSC_ADDRESSES = {
|
|
2368
2440
|
diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
|
|
2369
|
-
router: "
|
|
2441
|
+
router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6",
|
|
2370
2442
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
|
|
2371
2443
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
|
|
2372
2444
|
sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF",
|
|
@@ -2379,6 +2451,15 @@ var BSC_ADDRESSES = {
|
|
|
2379
2451
|
USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
|
|
2380
2452
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
|
|
2381
2453
|
};
|
|
2454
|
+
var PHAROS_ADDRESSES = {
|
|
2455
|
+
diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8",
|
|
2456
|
+
apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4",
|
|
2457
|
+
xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576",
|
|
2458
|
+
sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8",
|
|
2459
|
+
mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18",
|
|
2460
|
+
mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682",
|
|
2461
|
+
mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9"
|
|
2462
|
+
};
|
|
2382
2463
|
function formatAmount(amount, decimals = 4) {
|
|
2383
2464
|
const divisor = 10n ** BigInt(18 - decimals);
|
|
2384
2465
|
const scaled = amount / divisor;
|
|
@@ -2417,23 +2498,35 @@ export {
|
|
|
2417
2498
|
AspanRouterReadClient,
|
|
2418
2499
|
BPS_PRECISION,
|
|
2419
2500
|
BSC_ADDRESSES,
|
|
2501
|
+
CHAIN_IDS,
|
|
2420
2502
|
DiamondABI,
|
|
2503
|
+
PHAROS_ADDRESSES,
|
|
2421
2504
|
PRECISION,
|
|
2422
2505
|
PRICE_PRECISION,
|
|
2423
2506
|
RouterABI,
|
|
2424
2507
|
calculateAPY,
|
|
2425
2508
|
createAspanClient,
|
|
2509
|
+
createAspanPharosClient,
|
|
2510
|
+
createAspanPharosReadClient,
|
|
2426
2511
|
createAspanReadClient,
|
|
2512
|
+
createAspanReadClientForChain,
|
|
2427
2513
|
createAspanTestnetClient,
|
|
2428
2514
|
createAspanTestnetReadClient,
|
|
2515
|
+
createAspanWriteClientForChain,
|
|
2429
2516
|
createRouterClient,
|
|
2517
|
+
createRouterPharosClient,
|
|
2518
|
+
createRouterPharosReadClient,
|
|
2430
2519
|
createRouterReadClient,
|
|
2520
|
+
createRouterReadClientForChain,
|
|
2431
2521
|
createRouterTestnetClient,
|
|
2432
2522
|
createRouterTestnetReadClient,
|
|
2523
|
+
createRouterWriteClientForChain,
|
|
2433
2524
|
encodeV3Path,
|
|
2434
2525
|
formatAmount,
|
|
2435
2526
|
formatCR,
|
|
2436
2527
|
formatFeeBPS,
|
|
2437
2528
|
formatPriceUSD,
|
|
2438
|
-
|
|
2529
|
+
getChainById,
|
|
2530
|
+
parseAmount,
|
|
2531
|
+
pharosTestnet
|
|
2439
2532
|
};
|
package/package.json
CHANGED
|
@@ -405,53 +405,51 @@ export class RiskKeeperService {
|
|
|
405
405
|
}
|
|
406
406
|
|
|
407
407
|
private async executeVaultClean(xBNBAmount: bigint): Promise<Hash> {
|
|
408
|
-
console.log(`[RiskKeeper] Cleaning ${xBNBAmount} xBNB from vault`);
|
|
409
|
-
|
|
410
|
-
// Build swap path: xBNB -> WBNB -> apUSD
|
|
411
|
-
// Note: In production, might need xBNB -> WBNB -> USDT -> apUSD
|
|
412
|
-
const path = [
|
|
413
|
-
await this.getXBNBAddress(),
|
|
414
|
-
this.keeperConfig.wbnbAddress,
|
|
415
|
-
await this.getApUSDAddress(),
|
|
416
|
-
];
|
|
408
|
+
console.log(`[RiskKeeper] Cleaning ${xBNBAmount} xBNB from vault via Diamond internal conversion`);
|
|
417
409
|
|
|
418
410
|
// Preview output
|
|
419
|
-
const expectedOut = await this.previewClean(xBNBAmount
|
|
411
|
+
const expectedOut = await this.previewClean(xBNBAmount);
|
|
420
412
|
|
|
421
413
|
// Calculate min out with slippage
|
|
422
414
|
const minOut = (expectedOut * BigInt(10000 - this.MAX_SLIPPAGE_BPS)) / 10000n;
|
|
423
415
|
|
|
424
|
-
|
|
425
|
-
const deadline = BigInt(Math.floor(Date.now() / 1000) + 300);
|
|
416
|
+
console.log(`[RiskKeeper] Expected apUSD out: ${Number(expectedOut) / 1e18}, min: ${Number(minOut) / 1e18}`);
|
|
426
417
|
|
|
418
|
+
// Call Diamond's cleanVaultXBNB (internal burn xBNB + mint apUSD)
|
|
427
419
|
return this.walletClient.writeContract({
|
|
428
420
|
chain: bsc,
|
|
429
|
-
account: this.account,
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
421
|
+
account: this.account,
|
|
422
|
+
address: this.client.diamondAddress,
|
|
423
|
+
abi: [{
|
|
424
|
+
type: "function",
|
|
425
|
+
name: "cleanVaultXBNB",
|
|
426
|
+
inputs: [
|
|
427
|
+
{ name: "_xBNBAmount", type: "uint256" },
|
|
428
|
+
{ name: "_minApUSDOut", type: "uint256" },
|
|
429
|
+
],
|
|
430
|
+
outputs: [{ name: "apUSDMinted", type: "uint256" }],
|
|
431
|
+
stateMutability: "nonpayable",
|
|
432
|
+
}],
|
|
433
|
+
functionName: "cleanVaultXBNB",
|
|
434
|
+
args: [xBNBAmount, minOut],
|
|
433
435
|
});
|
|
434
436
|
}
|
|
435
437
|
|
|
436
|
-
private async previewClean(xBNBAmount: bigint
|
|
438
|
+
private async previewClean(xBNBAmount: bigint): Promise<bigint> {
|
|
437
439
|
return this.publicClient.readContract({
|
|
438
|
-
address: this.
|
|
439
|
-
abi:
|
|
440
|
-
|
|
441
|
-
|
|
440
|
+
address: this.client.diamondAddress,
|
|
441
|
+
abi: [{
|
|
442
|
+
type: "function",
|
|
443
|
+
name: "previewCleanVaultXBNB",
|
|
444
|
+
inputs: [{ name: "_xBNBAmount", type: "uint256" }],
|
|
445
|
+
outputs: [{ name: "apUSDOut", type: "uint256" }],
|
|
446
|
+
stateMutability: "view",
|
|
447
|
+
}],
|
|
448
|
+
functionName: "previewCleanVaultXBNB",
|
|
449
|
+
args: [xBNBAmount],
|
|
442
450
|
});
|
|
443
451
|
}
|
|
444
452
|
|
|
445
|
-
private async getXBNBAddress(): Promise<Address> {
|
|
446
|
-
const tokens = await this.client.getTokens();
|
|
447
|
-
return tokens.xBNB;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
private async getApUSDAddress(): Promise<Address> {
|
|
451
|
-
const tokens = await this.client.getTokens();
|
|
452
|
-
return tokens.apUSD;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
453
|
// ============ Notifications ============
|
|
456
454
|
|
|
457
455
|
private async notifySM2Success(cr: bigint, amount: bigint, txHash: Hash): Promise<void> {
|
package/src/client.ts
CHANGED
|
@@ -16,6 +16,43 @@ import {
|
|
|
16
16
|
type Hash,
|
|
17
17
|
} from "viem";
|
|
18
18
|
import { bsc, bscTestnet } from "viem/chains";
|
|
19
|
+
|
|
20
|
+
/** Pharos Atlantic Testnet chain definition */
|
|
21
|
+
export const pharosTestnet: Chain = {
|
|
22
|
+
id: 688689,
|
|
23
|
+
name: "Pharos Atlantic Testnet",
|
|
24
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
25
|
+
rpcUrls: {
|
|
26
|
+
default: { http: ["https://atlantic.dplabs-internal.com"] },
|
|
27
|
+
},
|
|
28
|
+
blockExplorers: {
|
|
29
|
+
default: { name: "Pharos Explorer", url: "https://atlantic.pharosscan.xyz" },
|
|
30
|
+
},
|
|
31
|
+
} as const satisfies Chain;
|
|
32
|
+
|
|
33
|
+
/** Supported chain IDs */
|
|
34
|
+
export const CHAIN_IDS = {
|
|
35
|
+
BSC: 56,
|
|
36
|
+
BSC_TESTNET: 97,
|
|
37
|
+
PHAROS: 688689,
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
/** Internal: map chainId to viem Chain object */
|
|
41
|
+
const CHAIN_MAP: Record<number, Chain> = {
|
|
42
|
+
[CHAIN_IDS.BSC]: bsc,
|
|
43
|
+
[CHAIN_IDS.BSC_TESTNET]: bscTestnet,
|
|
44
|
+
[CHAIN_IDS.PHAROS]: pharosTestnet,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the viem Chain object for a given chainId.
|
|
49
|
+
* @throws if the chainId is not supported
|
|
50
|
+
*/
|
|
51
|
+
export function getChainById(chainId: number): Chain {
|
|
52
|
+
const chain = CHAIN_MAP[chainId];
|
|
53
|
+
if (!chain) throw new Error(`[Aspan SDK] Unsupported chainId: ${chainId}`);
|
|
54
|
+
return chain;
|
|
55
|
+
}
|
|
19
56
|
import { DiamondABI } from "./abi/diamond";
|
|
20
57
|
import type {
|
|
21
58
|
LSTInfo,
|
|
@@ -65,7 +102,7 @@ export interface AspanWriteClientConfig extends AspanClientConfig {
|
|
|
65
102
|
*/
|
|
66
103
|
export class AspanReadClient {
|
|
67
104
|
protected readonly publicClient: PublicClient;
|
|
68
|
-
|
|
105
|
+
public readonly diamondAddress: Address;
|
|
69
106
|
protected readonly chain: Chain;
|
|
70
107
|
|
|
71
108
|
// Known error signatures for zero supply states
|
|
@@ -1213,3 +1250,71 @@ export function createAspanTestnetClient(
|
|
|
1213
1250
|
rpcUrl,
|
|
1214
1251
|
});
|
|
1215
1252
|
}
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Create a read-only client for Pharos Atlantic Testnet
|
|
1256
|
+
*/
|
|
1257
|
+
export function createAspanPharosReadClient(
|
|
1258
|
+
diamondAddress: Address,
|
|
1259
|
+
rpcUrl?: string
|
|
1260
|
+
): AspanReadClient {
|
|
1261
|
+
return new AspanReadClient({
|
|
1262
|
+
diamondAddress,
|
|
1263
|
+
chain: pharosTestnet,
|
|
1264
|
+
rpcUrl,
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Create a full client for Pharos Atlantic Testnet
|
|
1270
|
+
*/
|
|
1271
|
+
export function createAspanPharosClient(
|
|
1272
|
+
diamondAddress: Address,
|
|
1273
|
+
account: Account,
|
|
1274
|
+
rpcUrl?: string
|
|
1275
|
+
): AspanClient {
|
|
1276
|
+
return new AspanClient({
|
|
1277
|
+
diamondAddress,
|
|
1278
|
+
account,
|
|
1279
|
+
chain: pharosTestnet,
|
|
1280
|
+
rpcUrl,
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// ============ Chain-ID-based Factory Functions ============
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* Create a read-only Aspan client by chainId.
|
|
1288
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
1289
|
+
*
|
|
1290
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
1291
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
1292
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
1293
|
+
*/
|
|
1294
|
+
export function createAspanReadClientForChain(
|
|
1295
|
+
diamondAddress: Address,
|
|
1296
|
+
chainId: number = CHAIN_IDS.BSC,
|
|
1297
|
+
rpcUrl?: string
|
|
1298
|
+
): AspanReadClient {
|
|
1299
|
+
const chain = getChainById(chainId);
|
|
1300
|
+
return new AspanReadClient({ diamondAddress, chain, rpcUrl });
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Create a write Aspan client by chainId using an external wagmi WalletClient.
|
|
1305
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
1306
|
+
*
|
|
1307
|
+
* @param diamondAddress Diamond contract address for the target chain.
|
|
1308
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
1309
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
1310
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
1311
|
+
*/
|
|
1312
|
+
export function createAspanWriteClientForChain(
|
|
1313
|
+
diamondAddress: Address,
|
|
1314
|
+
chainId: number = CHAIN_IDS.BSC,
|
|
1315
|
+
walletClient: WalletClient<Transport, Chain, Account>,
|
|
1316
|
+
rpcUrl?: string
|
|
1317
|
+
): AspanClient {
|
|
1318
|
+
const chain = getChainById(chainId);
|
|
1319
|
+
return new AspanClient({ diamondAddress, chain, walletClient, rpcUrl });
|
|
1320
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,15 @@ export {
|
|
|
13
13
|
createAspanClient,
|
|
14
14
|
createAspanTestnetReadClient,
|
|
15
15
|
createAspanTestnetClient,
|
|
16
|
+
createAspanPharosReadClient,
|
|
17
|
+
createAspanPharosClient,
|
|
18
|
+
// Chain-ID-based factory functions
|
|
19
|
+
createAspanReadClientForChain,
|
|
20
|
+
createAspanWriteClientForChain,
|
|
21
|
+
// Chain helpers
|
|
22
|
+
pharosTestnet,
|
|
23
|
+
CHAIN_IDS,
|
|
24
|
+
getChainById,
|
|
16
25
|
type AspanClientConfig,
|
|
17
26
|
type AspanWriteClientConfig,
|
|
18
27
|
} from "./client";
|
|
@@ -25,6 +34,11 @@ export {
|
|
|
25
34
|
createRouterClient,
|
|
26
35
|
createRouterTestnetReadClient,
|
|
27
36
|
createRouterTestnetClient,
|
|
37
|
+
createRouterPharosReadClient,
|
|
38
|
+
createRouterPharosClient,
|
|
39
|
+
// Chain-ID-based factory functions
|
|
40
|
+
createRouterReadClientForChain,
|
|
41
|
+
createRouterWriteClientForChain,
|
|
28
42
|
type AspanRouterClientConfig,
|
|
29
43
|
type AspanRouterWriteClientConfig,
|
|
30
44
|
} from "./router";
|
|
@@ -103,7 +117,7 @@ export const PRICE_PRECISION = 10n ** 8n; // Chainlink price precision
|
|
|
103
117
|
// ============ Contract Addresses (BSC Mainnet) ============
|
|
104
118
|
export const BSC_ADDRESSES = {
|
|
105
119
|
diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78" as const,
|
|
106
|
-
router: "
|
|
120
|
+
router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6" as const,
|
|
107
121
|
apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287" as const,
|
|
108
122
|
xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43" as const,
|
|
109
123
|
sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF" as const,
|
|
@@ -117,6 +131,16 @@ export const BSC_ADDRESSES = {
|
|
|
117
131
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" as const,
|
|
118
132
|
} as const;
|
|
119
133
|
|
|
134
|
+
export const PHAROS_ADDRESSES = {
|
|
135
|
+
diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8" as const,
|
|
136
|
+
apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4" as const,
|
|
137
|
+
xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576" as const,
|
|
138
|
+
sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8" as const,
|
|
139
|
+
mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18" as const,
|
|
140
|
+
mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682" as const,
|
|
141
|
+
mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9" as const,
|
|
142
|
+
} as const;
|
|
143
|
+
|
|
120
144
|
// ============ Utility Functions ============
|
|
121
145
|
|
|
122
146
|
/**
|
package/src/router.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type Hash,
|
|
19
19
|
} from "viem";
|
|
20
20
|
import { bsc, bscTestnet } from "viem/chains";
|
|
21
|
+
import { pharosTestnet, CHAIN_IDS, getChainById } from "./client";
|
|
21
22
|
import { RouterABI } from "./abi/router";
|
|
22
23
|
import type {
|
|
23
24
|
SwapAndMintParams,
|
|
@@ -514,3 +515,71 @@ export function createRouterTestnetClient(
|
|
|
514
515
|
rpcUrl,
|
|
515
516
|
});
|
|
516
517
|
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Create a read-only router client for Pharos Atlantic Testnet
|
|
521
|
+
*/
|
|
522
|
+
export function createRouterPharosReadClient(
|
|
523
|
+
routerAddress: Address,
|
|
524
|
+
rpcUrl?: string
|
|
525
|
+
): AspanRouterReadClient {
|
|
526
|
+
return new AspanRouterReadClient({
|
|
527
|
+
routerAddress,
|
|
528
|
+
chain: pharosTestnet,
|
|
529
|
+
rpcUrl,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Create a full router client for Pharos Atlantic Testnet
|
|
535
|
+
*/
|
|
536
|
+
export function createRouterPharosClient(
|
|
537
|
+
routerAddress: Address,
|
|
538
|
+
account: Account,
|
|
539
|
+
rpcUrl?: string
|
|
540
|
+
): AspanRouterClient {
|
|
541
|
+
return new AspanRouterClient({
|
|
542
|
+
routerAddress,
|
|
543
|
+
account,
|
|
544
|
+
chain: pharosTestnet,
|
|
545
|
+
rpcUrl,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// ============ Chain-ID-based Factory Functions ============
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Create a read-only AspanRouter client by chainId.
|
|
553
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
554
|
+
*
|
|
555
|
+
* @param routerAddress Router contract address for the target chain.
|
|
556
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
557
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
558
|
+
*/
|
|
559
|
+
export function createRouterReadClientForChain(
|
|
560
|
+
routerAddress: Address,
|
|
561
|
+
chainId: number = CHAIN_IDS.BSC,
|
|
562
|
+
rpcUrl?: string
|
|
563
|
+
): AspanRouterReadClient {
|
|
564
|
+
const chain = getChainById(chainId);
|
|
565
|
+
return new AspanRouterReadClient({ routerAddress, chain, rpcUrl });
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Create a write AspanRouter client by chainId using an external wagmi WalletClient.
|
|
570
|
+
* Defaults to BSC mainnet (chainId = 56) if chainId is not provided.
|
|
571
|
+
*
|
|
572
|
+
* @param routerAddress Router contract address for the target chain.
|
|
573
|
+
* @param chainId Target chain ID (56 = BSC, 688689 = Pharos). Defaults to 56.
|
|
574
|
+
* @param walletClient External WalletClient from wagmi / viem.
|
|
575
|
+
* @param rpcUrl Optional custom RPC endpoint.
|
|
576
|
+
*/
|
|
577
|
+
export function createRouterWriteClientForChain(
|
|
578
|
+
routerAddress: Address,
|
|
579
|
+
chainId: number = CHAIN_IDS.BSC,
|
|
580
|
+
walletClient: WalletClient<Transport, Chain, Account>,
|
|
581
|
+
rpcUrl?: string
|
|
582
|
+
): AspanRouterClient {
|
|
583
|
+
const chain = getChainById(chainId);
|
|
584
|
+
return new AspanRouterClient({ routerAddress, chain, walletClient, rpcUrl });
|
|
585
|
+
}
|