@lifi/sdk-provider-sui 4.0.1-alpha.0 → 4.0.1
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/CHANGELOG.md +25 -0
- package/README.md +88 -5
- package/dist/esm/SuiProvider.d.ts +7 -2
- package/dist/esm/SuiProvider.d.ts.map +1 -0
- package/dist/esm/SuiProvider.js +32 -32
- package/dist/esm/SuiProvider.js.map +1 -1
- package/dist/esm/actions/getSuiBalance.d.ts +7 -2
- package/dist/esm/actions/getSuiBalance.d.ts.map +1 -0
- package/dist/esm/actions/getSuiBalance.js +40 -47
- package/dist/esm/actions/getSuiBalance.js.map +1 -1
- package/dist/esm/actions/getSuiNSAddress.d.ts +7 -1
- package/dist/esm/actions/getSuiNSAddress.d.ts.map +1 -0
- package/dist/esm/actions/getSuiNSAddress.js +24 -27
- package/dist/esm/actions/getSuiNSAddress.js.map +1 -1
- package/dist/esm/actions/resolveSuiAddress.d.ts +5 -1
- package/dist/esm/actions/resolveSuiAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveSuiAddress.js +7 -3
- package/dist/esm/actions/resolveSuiAddress.js.map +1 -1
- package/dist/esm/client/suiClient.d.ts +13 -8
- package/dist/esm/client/suiClient.d.ts.map +1 -0
- package/dist/esm/client/suiClient.js +32 -33
- package/dist/esm/client/suiClient.js.map +1 -1
- package/dist/esm/core/SuiStepExecutor.d.ts +16 -0
- package/dist/esm/core/SuiStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/SuiStepExecutor.js +44 -0
- package/dist/esm/core/SuiStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js +26 -0
- package/dist/esm/core/tasks/SuiSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js +26 -0
- package/dist/esm/core/tasks/SuiWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseSuiErrors.d.ts +7 -2
- package/dist/esm/errors/parseSuiErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseSuiErrors.js +17 -27
- package/dist/esm/errors/parseSuiErrors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/package.json +1 -1
- package/dist/esm/types.d.ts +27 -11
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +9 -5
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +9 -9
- package/src/SuiProvider.ts +22 -6
- package/src/actions/getSuiBalance.ts +10 -10
- package/src/actions/getSuiNSAddress.ts +6 -3
- package/src/client/suiClient.ts +6 -6
- package/src/core/SuiStepExecutor.ts +93 -0
- package/src/core/tasks/SuiSignAndExecuteTask.ts +68 -0
- package/src/core/tasks/SuiWaitForTransactionTask.ts +67 -0
- package/src/types.ts +20 -3
- package/src/version.ts +1 -1
- package/dist/cjs/SuiProvider.d.ts +0 -2
- package/dist/cjs/SuiProvider.js +0 -37
- package/dist/cjs/SuiProvider.js.map +0 -1
- package/dist/cjs/SuiStepExecutor.d.ts +0 -8
- package/dist/cjs/SuiStepExecutor.js +0 -109
- package/dist/cjs/SuiStepExecutor.js.map +0 -1
- package/dist/cjs/actions/getSuiBalance.d.ts +0 -2
- package/dist/cjs/actions/getSuiBalance.js +0 -54
- package/dist/cjs/actions/getSuiBalance.js.map +0 -1
- package/dist/cjs/actions/getSuiNSAddress.d.ts +0 -1
- package/dist/cjs/actions/getSuiNSAddress.js +0 -32
- package/dist/cjs/actions/getSuiNSAddress.js.map +0 -1
- package/dist/cjs/actions/resolveSuiAddress.d.ts +0 -1
- package/dist/cjs/actions/resolveSuiAddress.js +0 -8
- package/dist/cjs/actions/resolveSuiAddress.js.map +0 -1
- package/dist/cjs/client/suiClient.d.ts +0 -3
- package/dist/cjs/client/suiClient.js +0 -30
- package/dist/cjs/client/suiClient.js.map +0 -1
- package/dist/cjs/errors/parseSuiErrors.d.ts +0 -2
- package/dist/cjs/errors/parseSuiErrors.js +0 -35
- package/dist/cjs/errors/parseSuiErrors.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/types.d.ts +0 -14
- package/dist/cjs/types.js +0 -11
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/version.d.ts +0 -2
- package/dist/cjs/version.js +0 -6
- package/dist/cjs/version.js.map +0 -1
- package/dist/esm/SuiStepExecutor.d.ts +0 -8
- package/dist/esm/SuiStepExecutor.js +0 -110
- package/dist/esm/SuiStepExecutor.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/types/SuiProvider.d.ts +0 -3
- package/dist/types/SuiProvider.d.ts.map +0 -1
- package/dist/types/SuiStepExecutor.d.ts +0 -9
- package/dist/types/SuiStepExecutor.d.ts.map +0 -1
- package/dist/types/actions/getSuiBalance.d.ts +0 -3
- package/dist/types/actions/getSuiBalance.d.ts.map +0 -1
- package/dist/types/actions/getSuiNSAddress.d.ts +0 -2
- package/dist/types/actions/getSuiNSAddress.d.ts.map +0 -1
- package/dist/types/actions/resolveSuiAddress.d.ts +0 -2
- package/dist/types/actions/resolveSuiAddress.d.ts.map +0 -1
- package/dist/types/client/suiClient.d.ts +0 -10
- package/dist/types/client/suiClient.d.ts.map +0 -1
- package/dist/types/errors/parseSuiErrors.d.ts +0 -3
- package/dist/types/errors/parseSuiErrors.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -15
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -3
- package/dist/types/version.d.ts.map +0 -1
- package/src/SuiStepExecutor.ts +0 -191
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @lifi/sdk-provider-sui
|
|
2
|
+
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#402](https://github.com/lifinance/sdk/pull/402) [`bf3d047`](https://github.com/lifinance/sdk/commit/bf3d047ebdc9a8b3a5a6362f65d25aa1eb652ffa) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: @lifi/types to 17.85.0, viem to 2.52.2, @solana/kit to 6.10.0 (with @solana/wallet-standard-features and @wallet-standard/base), @mysten/sui to 2.19.0, and @tronweb3/tronwallet-abstract-adapter to 1.2.0.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`bf3d047`](https://github.com/lifinance/sdk/commit/bf3d047ebdc9a8b3a5a6362f65d25aa1eb652ffa)]:
|
|
10
|
+
- @lifi/sdk@4.0.1
|
|
11
|
+
|
|
12
|
+
## 4.0.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#396](https://github.com/lifinance/sdk/pull/396) [`8a8773f`](https://github.com/lifinance/sdk/commit/8a8773f4bbd6d5245fc933b140502b87e1c953c8) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: viem to 2.51.3, @mysten/sui to 2.17.0.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies []:
|
|
19
|
+
- @lifi/sdk@4.0.0
|
|
20
|
+
|
|
21
|
+
## 4.0.0-beta.12
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [#396](https://github.com/lifinance/sdk/pull/396) [`8a8773f`](https://github.com/lifinance/sdk/commit/8a8773f4bbd6d5245fc933b140502b87e1c953c8) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: viem to 2.51.3, @mysten/sui to 2.17.0.
|
package/README.md
CHANGED
|
@@ -13,18 +13,23 @@
|
|
|
13
13
|
|
|
14
14
|
[**LI.FI SDK**](https://docs.li.fi/sdk/overview) features include:
|
|
15
15
|
|
|
16
|
+
- **Modular architecture** - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron)
|
|
16
17
|
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
|
|
17
18
|
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
|
|
18
19
|
- Easy tracking of the route and quote execution through the robust event and hooks handling
|
|
19
20
|
- Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
|
|
20
21
|
- Supports widely adopted industry standards, including [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
|
|
21
|
-
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/), [
|
|
22
|
+
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/) for EVM, [Solana Kit](https://github.com/solana-labs/solana-web3.js) for Solana, [Bigmi](https://github.com/lifinance/bigmi) for Bitcoin, [Mysten Sui SDK](https://github.com/MystenLabs/sui/tree/main/sdk) for Sui, [TronWeb](https://tronweb.network/) for Tron)
|
|
22
23
|
- Support for arbitrary contract calls on the destination chain
|
|
23
24
|
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
|
|
24
25
|
- Compatibility tested with Node.js and popular front-end tools like Vite
|
|
25
26
|
|
|
26
27
|
## Installation
|
|
27
28
|
|
|
29
|
+
The LI.FI SDK follows a modular architecture. Install the core SDK package and the provider packages for the blockchain ecosystems you need:
|
|
30
|
+
|
|
31
|
+
### Core SDK
|
|
32
|
+
|
|
28
33
|
```bash
|
|
29
34
|
pnpm add @lifi/sdk
|
|
30
35
|
```
|
|
@@ -35,17 +40,95 @@ or
|
|
|
35
40
|
npm install --save @lifi/sdk
|
|
36
41
|
```
|
|
37
42
|
|
|
43
|
+
### Provider Packages
|
|
44
|
+
|
|
45
|
+
Install provider packages based on the blockchain ecosystems you want to support:
|
|
46
|
+
|
|
47
|
+
**EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)**
|
|
48
|
+
```bash
|
|
49
|
+
pnpm add @lifi/sdk-provider-ethereum
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Solana**
|
|
53
|
+
```bash
|
|
54
|
+
pnpm add @lifi/sdk-provider-solana
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Bitcoin**
|
|
58
|
+
```bash
|
|
59
|
+
pnpm add @lifi/sdk-provider-bitcoin
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Sui**
|
|
63
|
+
```bash
|
|
64
|
+
pnpm add @lifi/sdk-provider-sui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Tron**
|
|
68
|
+
```bash
|
|
69
|
+
pnpm add @lifi/sdk-provider-tron
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Architecture
|
|
73
|
+
|
|
74
|
+
The LI.FI SDK uses a modular provider architecture:
|
|
75
|
+
|
|
76
|
+
- **`@lifi/sdk`** - Core SDK package containing shared functionality, actions, and execution logic
|
|
77
|
+
- **Provider packages** - Ecosystem-specific packages that handle wallet interactions and transaction execution for different blockchain types
|
|
78
|
+
|
|
79
|
+
This architecture allows you to:
|
|
80
|
+
- Install only the providers you need, reducing bundle size
|
|
81
|
+
- Use ecosystem-specific libraries optimized for each blockchain
|
|
82
|
+
- Maintain clean separation between core SDK logic and blockchain-specific implementations
|
|
83
|
+
|
|
38
84
|
## Quick Start
|
|
39
85
|
|
|
40
86
|
### Set up the SDK
|
|
41
87
|
|
|
42
|
-
|
|
88
|
+
Create SDK config with your integrator string and configure the providers for the blockchain ecosystems you want to support.
|
|
43
89
|
|
|
90
|
+
**For EVM chains:**
|
|
44
91
|
```ts
|
|
45
|
-
import {
|
|
92
|
+
import { createClient } from '@lifi/sdk'
|
|
93
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
94
|
+
import { createWalletClient, http } from 'viem'
|
|
95
|
+
import { mainnet } from 'viem/chains'
|
|
96
|
+
|
|
97
|
+
// Add your account (e.g. privateKeyToAccount, mnemonicToAccount)
|
|
98
|
+
const walletClient = createWalletClient({
|
|
99
|
+
account,
|
|
100
|
+
chain: mainnet,
|
|
101
|
+
transport: http(),
|
|
102
|
+
})
|
|
46
103
|
|
|
47
|
-
|
|
104
|
+
const client = createClient({
|
|
105
|
+
integrator: 'Your dApp/company name',
|
|
106
|
+
providers: [
|
|
107
|
+
EthereumProvider({
|
|
108
|
+
getWalletClient: () => Promise.resolve(walletClient),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**For multiple ecosystems:**
|
|
115
|
+
```ts
|
|
116
|
+
import { createClient } from '@lifi/sdk'
|
|
117
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
118
|
+
import { SolanaProvider } from '@lifi/sdk-provider-solana'
|
|
119
|
+
import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
120
|
+
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
121
|
+
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
122
|
+
|
|
123
|
+
const client = createClient({
|
|
48
124
|
integrator: 'Your dApp/company name',
|
|
125
|
+
providers: [
|
|
126
|
+
EthereumProvider({ /* options */ }),
|
|
127
|
+
SolanaProvider({ /* options */ }),
|
|
128
|
+
BitcoinProvider({ /* options */ }),
|
|
129
|
+
SuiProvider({ /* options */ }),
|
|
130
|
+
TronProvider({ /* options */ }),
|
|
131
|
+
],
|
|
49
132
|
})
|
|
50
133
|
```
|
|
51
134
|
|
|
@@ -56,7 +139,7 @@ Now you can interact with the SDK and for example request a quote.
|
|
|
56
139
|
```ts
|
|
57
140
|
import { ChainId, getQuote } from '@lifi/sdk'
|
|
58
141
|
|
|
59
|
-
const quote = await getQuote({
|
|
142
|
+
const quote = await getQuote(client, {
|
|
60
143
|
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
61
144
|
fromChain: ChainId.ARB,
|
|
62
145
|
toChain: ChainId.OPT,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { SuiProviderOptions, SuiSDKProvider } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/SuiProvider.d.ts
|
|
4
|
+
declare function SuiProvider(options?: SuiProviderOptions): SuiSDKProvider;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { SuiProvider };
|
|
7
|
+
//# sourceMappingURL=SuiProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SuiProvider.d.ts","names":[],"sources":["../../src/SuiProvider.ts"],"mappings":";;;iBAYgB,WAAA,CAAY,OAAA,GAAU,kBAAA,GAAqB,cAAA"}
|
package/dist/esm/SuiProvider.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.assign(_options, options);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
1
|
+
import { getSuiBalance } from "./actions/getSuiBalance.js";
|
|
2
|
+
import { resolveSuiAddress } from "./actions/resolveSuiAddress.js";
|
|
3
|
+
import { SuiStepExecutor } from "./core/SuiStepExecutor.js";
|
|
4
|
+
import { ChainType, LiFiErrorCode, ProviderError } from "@lifi/sdk";
|
|
5
|
+
import { isValidSuiAddress } from "@mysten/sui/utils";
|
|
6
|
+
//#region src/SuiProvider.ts
|
|
7
|
+
function SuiProvider(options) {
|
|
8
|
+
const _options = options ?? {};
|
|
9
|
+
return {
|
|
10
|
+
get type() {
|
|
11
|
+
return ChainType.MVM;
|
|
12
|
+
},
|
|
13
|
+
isAddress: isValidSuiAddress,
|
|
14
|
+
resolveAddress: resolveSuiAddress,
|
|
15
|
+
getBalance: getSuiBalance,
|
|
16
|
+
async getStepExecutor(options) {
|
|
17
|
+
if (!_options.getClient) throw new ProviderError(LiFiErrorCode.ProviderUnavailable, "getClient is not provided.");
|
|
18
|
+
if (!_options.getSigner) throw new ProviderError(LiFiErrorCode.ProviderUnavailable, "getSigner is not provided.");
|
|
19
|
+
return new SuiStepExecutor({
|
|
20
|
+
client: await _options.getClient(),
|
|
21
|
+
signer: await _options.getSigner(),
|
|
22
|
+
routeId: options.routeId,
|
|
23
|
+
executionOptions: { ...options.executionOptions }
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
setOptions(options) {
|
|
27
|
+
Object.assign(_options, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
33
30
|
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { SuiProvider };
|
|
33
|
+
|
|
34
34
|
//# sourceMappingURL=SuiProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SuiProvider.js","
|
|
1
|
+
{"version":3,"file":"SuiProvider.js","names":[],"sources":["../../src/SuiProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport { isValidSuiAddress } from '@mysten/sui/utils'\nimport { getSuiBalance } from './actions/getSuiBalance.js'\nimport { resolveSuiAddress } from './actions/resolveSuiAddress.js'\nimport { SuiStepExecutor } from './core/SuiStepExecutor.js'\nimport type { SuiProviderOptions, SuiSDKProvider } from './types.js'\n\nexport function SuiProvider(options?: SuiProviderOptions): SuiSDKProvider {\n const _options: SuiProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.MVM\n },\n isAddress: isValidSuiAddress,\n resolveAddress: resolveSuiAddress,\n getBalance: getSuiBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<SuiStepExecutor> {\n if (!_options.getClient) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getClient is not provided.'\n )\n }\n if (!_options.getSigner) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getSigner is not provided.'\n )\n }\n\n const client = await _options.getClient()\n const signer = await _options.getSigner()\n\n const executor = new SuiStepExecutor({\n client,\n signer,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: SuiProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAYA,SAAgB,YAAY,SAA8C;CACxE,MAAM,WAA+B,WAAW,CAAC;CACjD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,YAAY;EACZ,MAAM,gBACJ,SAC0B;GAC1B,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAEF,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAeF,OAAO,IATc,gBAAgB;IACnC,QAAA,MAJmB,SAAS,UAAU;IAKtC,QAAA,MAJmB,SAAS,UAAU;IAKtC,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAA6B;GACtC,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { SDKClient, Token, TokenAmount } from "@lifi/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getSuiBalance.d.ts
|
|
4
|
+
declare function getSuiBalance(client: SDKClient, walletAddress: string, tokens: Token[]): Promise<TokenAmount[]>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getSuiBalance };
|
|
7
|
+
//# sourceMappingURL=getSuiBalance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiBalance.d.ts","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"mappings":";;;iBASsB,aAAA,CACpB,MAAA,EAAQ,SAAA,EACR,aAAA,UACA,MAAA,EAAQ,KAAA,KACP,OAAA,CAAQ,WAAA"}
|
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (token.chainId !== chainId) {
|
|
11
|
-
console.warn('Requested tokens have to be on the same chain.');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return getSuiBalanceDefault(client, chainId, tokens, walletAddress);
|
|
1
|
+
import { callSuiWithRetry } from "../client/suiClient.js";
|
|
2
|
+
import { SuiTokenLongAddress, SuiTokenShortAddress } from "../types.js";
|
|
3
|
+
import { withDedupe } from "@lifi/sdk";
|
|
4
|
+
//#region src/actions/getSuiBalance.ts
|
|
5
|
+
async function getSuiBalance(client, walletAddress, tokens) {
|
|
6
|
+
if (tokens.length === 0) return [];
|
|
7
|
+
const { chainId } = tokens[0];
|
|
8
|
+
for (const token of tokens) if (token.chainId !== chainId) console.warn("Requested tokens have to be on the same chain.");
|
|
9
|
+
return getSuiBalanceDefault(client, chainId, tokens, walletAddress);
|
|
15
10
|
}
|
|
16
11
|
const getSuiBalanceDefault = async (client, _chainId, tokens, walletAddress) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
...token,
|
|
46
|
-
blockNumber,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
return tokenAmounts;
|
|
12
|
+
const [coins, checkpoint] = await Promise.allSettled([withDedupe(() => callSuiWithRetry(client, (client) => client.getAllBalances({ owner: walletAddress })), { id: `${getSuiBalanceDefault.name}.getAllBalances` }), withDedupe(() => callSuiWithRetry(client, (client) => client.getLatestCheckpointSequenceNumber()), { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` })]);
|
|
13
|
+
const coinsOk = coins.status === "fulfilled";
|
|
14
|
+
const coinsResult = coinsOk ? coins.value : [];
|
|
15
|
+
const blockNumber = checkpoint.status === "fulfilled" ? BigInt(checkpoint.value) : 0n;
|
|
16
|
+
const walletTokenAmounts = coinsResult.reduce((tokenAmounts, coin) => {
|
|
17
|
+
const amount = BigInt(coin.totalBalance);
|
|
18
|
+
if (amount > 0n) tokenAmounts[coin.coinType] = amount;
|
|
19
|
+
return tokenAmounts;
|
|
20
|
+
}, {});
|
|
21
|
+
const suiTokenBalance = coinsResult.find((coin) => coin.coinType === SuiTokenShortAddress);
|
|
22
|
+
if (suiTokenBalance?.totalBalance) walletTokenAmounts[SuiTokenLongAddress] = BigInt(suiTokenBalance.totalBalance);
|
|
23
|
+
return tokens.map((token) => {
|
|
24
|
+
const found = walletTokenAmounts[token.address];
|
|
25
|
+
if (found !== void 0) return {
|
|
26
|
+
...token,
|
|
27
|
+
amount: found,
|
|
28
|
+
blockNumber
|
|
29
|
+
};
|
|
30
|
+
if (coinsOk) return {
|
|
31
|
+
...token,
|
|
32
|
+
amount: 0n,
|
|
33
|
+
blockNumber
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
...token,
|
|
37
|
+
blockNumber
|
|
38
|
+
};
|
|
39
|
+
});
|
|
50
40
|
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { getSuiBalance };
|
|
43
|
+
|
|
51
44
|
//# sourceMappingURL=getSuiBalance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSuiBalance.js","
|
|
1
|
+
{"version":3,"file":"getSuiBalance.js","names":[],"sources":["../../../src/actions/getSuiBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport { callSuiWithRetry } from '../client/suiClient.js'\nimport { SuiTokenLongAddress, SuiTokenShortAddress } from '../types.js'\n\nexport async function getSuiBalance(\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> {\n if (tokens.length === 0) {\n return []\n }\n\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n\n return getSuiBalanceDefault(client, chainId, tokens, walletAddress)\n}\n\nconst getSuiBalanceDefault = async (\n client: SDKClient,\n _chainId: number,\n tokens: Token[],\n walletAddress: string\n): Promise<TokenAmount[]> => {\n const [coins, checkpoint] = await Promise.allSettled([\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getAllBalances({\n owner: walletAddress,\n })\n ),\n { id: `${getSuiBalanceDefault.name}.getAllBalances` }\n ),\n withDedupe(\n () =>\n callSuiWithRetry(client, (client) =>\n client.getLatestCheckpointSequenceNumber()\n ),\n { id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }\n ),\n ])\n\n const coinsOk = coins.status === 'fulfilled'\n const coinsResult = coinsOk ? coins.value : []\n const blockNumber =\n checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n\n\n const walletTokenAmounts = coinsResult.reduce(\n (tokenAmounts, coin) => {\n const amount = BigInt(coin.totalBalance)\n if (amount > 0n) {\n tokenAmounts[coin.coinType] = amount\n }\n return tokenAmounts\n },\n {} as Record<string, bigint>\n )\n\n const suiTokenBalance = coinsResult.find(\n (coin) => coin.coinType === SuiTokenShortAddress\n )\n if (suiTokenBalance?.totalBalance) {\n walletTokenAmounts[SuiTokenLongAddress] = BigInt(\n suiTokenBalance.totalBalance\n )\n }\n\n const tokenAmounts: TokenAmount[] = tokens.map((token) => {\n const found = walletTokenAmounts[token.address]\n if (found !== undefined) {\n return { ...token, amount: found, blockNumber }\n }\n if (coinsOk) {\n // Wallet genuinely has no coins of this type.\n return { ...token, amount: 0n, blockNumber }\n }\n // RPC failed — leave amount undefined.\n return { ...token, blockNumber }\n })\n return tokenAmounts\n}\n"],"mappings":";;;;AASA,eAAsB,cACpB,QACA,eACA,QACwB;CACxB,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAIjE,OAAO,qBAAqB,QAAQ,SAAS,QAAQ,aAAa;AACpE;AAEA,MAAM,uBAAuB,OAC3B,QACA,UACA,QACA,kBAC2B;CAC3B,MAAM,CAAC,OAAO,cAAc,MAAM,QAAQ,WAAW,CACnD,iBAEI,iBAAiB,SAAS,WACxB,OAAO,eAAe,EACpB,OAAO,cACT,CAAC,CACH,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,iBAAiB,CACtD,GACA,iBAEI,iBAAiB,SAAS,WACxB,OAAO,kCAAkC,CAC3C,GACF,EAAE,IAAI,GAAG,qBAAqB,KAAK,oCAAoC,CACzE,CACF,CAAC;CAED,MAAM,UAAU,MAAM,WAAW;CACjC,MAAM,cAAc,UAAU,MAAM,QAAQ,CAAC;CAC7C,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,MAAM,qBAAqB,YAAY,QACpC,cAAc,SAAS;EACtB,MAAM,SAAS,OAAO,KAAK,YAAY;EACvC,IAAI,SAAS,IACX,aAAa,KAAK,YAAY;EAEhC,OAAO;CACT,GACA,CAAC,CACH;CAEA,MAAM,kBAAkB,YAAY,MACjC,SAAS,KAAK,aAAa,oBAC9B;CACA,IAAI,iBAAiB,cACnB,mBAAmB,uBAAuB,OACxC,gBAAgB,YAClB;CAeF,OAZoC,OAAO,KAAK,UAAU;EACxD,MAAM,QAAQ,mBAAmB,MAAM;EACvC,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAO;EAAY;EAEhD,IAAI,SAEF,OAAO;GAAE,GAAG;GAAO,QAAQ;GAAI;EAAY;EAG7C,OAAO;GAAE,GAAG;GAAO;EAAY;CACjC,CACkB;AACpB"}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getSuiNSAddress.d.ts
|
|
4
|
+
declare function getSuiNSAddress(name: string, rpcUrl?: string, network?: SuiClientTypes.Network): Promise<string | undefined>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getSuiNSAddress };
|
|
7
|
+
//# sourceMappingURL=getSuiNSAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSuiNSAddress.d.ts","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"mappings":";;;iBAMsB,eAAA,CACpB,IAAA,UACA,MAAA,WACA,OAAA,GAAU,cAAA,CAAe,OAAA,GACxB,OAAA"}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return nameRecord.fields.address;
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
console.error('Error resolving SuiNS address:', error);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
1
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
2
|
+
//#region src/actions/getSuiNSAddress.ts
|
|
3
|
+
const SNS_REGISTRY_ID = "0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4";
|
|
4
|
+
async function getSuiNSAddress(name, rpcUrl, network) {
|
|
5
|
+
const client = new SuiJsonRpcClient({
|
|
6
|
+
url: rpcUrl || "https://fullnode.mainnet.sui.io:443",
|
|
7
|
+
network: network || "mainnet"
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
const result = await client.getObject({
|
|
11
|
+
id: SNS_REGISTRY_ID,
|
|
12
|
+
options: { showContent: true }
|
|
13
|
+
});
|
|
14
|
+
if (!result.data?.content) return;
|
|
15
|
+
const nameRecord = result.data.content.fields.records.find((record) => record.fields.name === name);
|
|
16
|
+
if (!nameRecord) return;
|
|
17
|
+
return nameRecord.fields.address;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Error resolving SuiNS address:", error);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
28
22
|
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { getSuiNSAddress };
|
|
25
|
+
|
|
29
26
|
//# sourceMappingURL=getSuiNSAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSuiNSAddress.js","
|
|
1
|
+
{"version":3,"file":"getSuiNSAddress.js","names":[],"sources":["../../../src/actions/getSuiNSAddress.ts"],"sourcesContent":["import type { SuiClientTypes } from '@mysten/sui/client'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst SNS_REGISTRY_ID =\n '0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4'\n\nexport async function getSuiNSAddress(\n name: string,\n rpcUrl?: string,\n network?: SuiClientTypes.Network\n): Promise<string | undefined> {\n const client = new SuiJsonRpcClient({\n url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',\n network: network || 'mainnet',\n })\n\n try {\n const result = await client.getObject({\n id: SNS_REGISTRY_ID,\n options: {\n showContent: true,\n },\n })\n\n if (!result.data?.content) {\n return\n }\n\n const registry = result.data.content as any\n const nameRecord = registry.fields.records.find(\n (record: any) => record.fields.name === name\n )\n\n if (!nameRecord) {\n return\n }\n\n return nameRecord.fields.address\n } catch (error) {\n console.error('Error resolving SuiNS address:', error)\n return\n }\n}\n"],"mappings":";;AAGA,MAAM,kBACJ;AAEF,eAAsB,gBACpB,MACA,QACA,SAC6B;CAC7B,MAAM,SAAS,IAAI,iBAAiB;EAClC,KAAK,UAAU;EACf,SAAS,WAAW;CACtB,CAAC;CAED,IAAI;EACF,MAAM,SAAS,MAAM,OAAO,UAAU;GACpC,IAAI;GACJ,SAAS,EACP,aAAa,KACf;EACF,CAAC;EAED,IAAI,CAAC,OAAO,MAAM,SAChB;EAIF,MAAM,aADW,OAAO,KAAK,QACD,OAAO,QAAQ,MACxC,WAAgB,OAAO,OAAO,SAAS,IAC1C;EAEA,IAAI,CAAC,YACH;EAGF,OAAO,WAAW,OAAO;CAC3B,SAAS,OAAO;EACd,QAAQ,MAAM,kCAAkC,KAAK;EACrD;CACF;AACF"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/actions/resolveSuiAddress.d.ts
|
|
2
|
+
declare function resolveSuiAddress(name: string): Promise<string | undefined>;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { resolveSuiAddress };
|
|
5
|
+
//# sourceMappingURL=resolveSuiAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSuiAddress.d.ts","names":[],"sources":["../../../src/actions/resolveSuiAddress.ts"],"mappings":";iBAEsB,iBAAA,CACpB,IAAA,WACC,OAAA"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { getSuiNSAddress } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { getSuiNSAddress } from "./getSuiNSAddress.js";
|
|
2
|
+
//#region src/actions/resolveSuiAddress.ts
|
|
3
|
+
async function resolveSuiAddress(name) {
|
|
4
|
+
return await getSuiNSAddress(name);
|
|
4
5
|
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { resolveSuiAddress };
|
|
8
|
+
|
|
5
9
|
//# sourceMappingURL=resolveSuiAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveSuiAddress.js","
|
|
1
|
+
{"version":3,"file":"resolveSuiAddress.js","names":[],"sources":["../../../src/actions/resolveSuiAddress.ts"],"sourcesContent":["import { getSuiNSAddress } from './getSuiNSAddress.js'\n\nexport async function resolveSuiAddress(\n name: string\n): Promise<string | undefined> {\n return await getSuiNSAddress(name)\n}\n"],"mappings":";;AAEA,eAAsB,kBACpB,MAC6B;CAC7B,OAAO,MAAM,gBAAgB,IAAI;AACnC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SDKClient } from "@lifi/sdk";
|
|
2
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
3
|
+
|
|
4
|
+
//#region src/client/suiClient.d.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* Calls a function on the SuiJsonRpcClient instances with retry logic.
|
|
7
|
+
* @param client - The SDK client
|
|
8
|
+
* @param fn - The function to call, which receives a SuiJsonRpcClient instance.
|
|
9
|
+
* @returns - The result of the function call.
|
|
10
|
+
*/
|
|
11
|
+
declare function callSuiWithRetry<R>(client: SDKClient, fn: (client: SuiJsonRpcClient) => Promise<R>): Promise<R>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { callSuiWithRetry };
|
|
14
|
+
//# sourceMappingURL=suiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiClient.d.ts","names":[],"sources":["../../../src/client/suiClient.ts"],"mappings":";;;;;;AAyBA;;;;iBAAsB,gBAAA,IACpB,MAAA,EAAQ,SAAA,EACR,EAAA,GAAK,MAAA,EAAQ,gBAAA,KAAqB,OAAA,CAAQ,CAAA,IACzC,OAAA,CAAQ,CAAA"}
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import { ChainId } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ChainId } from "@lifi/sdk";
|
|
2
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
3
|
+
//#region src/client/suiClient.ts
|
|
4
|
+
const clients = /* @__PURE__ */ new Map();
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
* Initializes the Sui clients if they haven't been initialized yet.
|
|
7
|
+
* @returns - Promise that resolves when clients are initialized.
|
|
8
|
+
*/
|
|
8
9
|
const ensureClients = async (client) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI);
|
|
11
|
+
for (const rpcUrl of rpcUrls) if (!clients.get(rpcUrl)) {
|
|
12
|
+
const client = new SuiJsonRpcClient({
|
|
13
|
+
url: rpcUrl,
|
|
14
|
+
network: "mainnet"
|
|
15
|
+
});
|
|
16
|
+
clients.set(rpcUrl, client);
|
|
17
|
+
}
|
|
16
18
|
};
|
|
17
19
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
catch (error) {
|
|
33
|
-
lastError = error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// Throw the last encountered error
|
|
37
|
-
throw lastError;
|
|
20
|
+
* Calls a function on the SuiJsonRpcClient instances with retry logic.
|
|
21
|
+
* @param client - The SDK client
|
|
22
|
+
* @param fn - The function to call, which receives a SuiJsonRpcClient instance.
|
|
23
|
+
* @returns - The result of the function call.
|
|
24
|
+
*/
|
|
25
|
+
async function callSuiWithRetry(client, fn) {
|
|
26
|
+
await ensureClients(client);
|
|
27
|
+
let lastError = null;
|
|
28
|
+
for (const client of clients.values()) try {
|
|
29
|
+
return await fn(client);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
lastError = error;
|
|
32
|
+
}
|
|
33
|
+
throw lastError;
|
|
38
34
|
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { callSuiWithRetry };
|
|
37
|
+
|
|
39
38
|
//# sourceMappingURL=suiClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suiClient.js","
|
|
1
|
+
{"version":3,"file":"suiClient.js","names":[],"sources":["../../../src/client/suiClient.ts"],"sourcesContent":["import { ChainId, type SDKClient } from '@lifi/sdk'\nimport { SuiJsonRpcClient } from '@mysten/sui/jsonRpc'\n\nconst clients = new Map<string, SuiJsonRpcClient>()\n\n/**\n * Initializes the Sui clients if they haven't been initialized yet.\n * @returns - Promise that resolves when clients are initialized.\n */\nconst ensureClients = async (client: SDKClient): Promise<void> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SUI)\n for (const rpcUrl of rpcUrls) {\n if (!clients.get(rpcUrl)) {\n const client = new SuiJsonRpcClient({ url: rpcUrl, network: 'mainnet' })\n clients.set(rpcUrl, client)\n }\n }\n}\n\n/**\n * Calls a function on the SuiJsonRpcClient instances with retry logic.\n * @param client - The SDK client\n * @param fn - The function to call, which receives a SuiJsonRpcClient instance.\n * @returns - The result of the function call.\n */\nexport async function callSuiWithRetry<R>(\n client: SDKClient,\n fn: (client: SuiJsonRpcClient) => Promise<R>\n): Promise<R> {\n // Ensure clients are initialized\n await ensureClients(client)\n let lastError: any = null\n for (const client of clients.values()) {\n try {\n const result = await fn(client)\n return result\n } catch (error) {\n lastError = error\n }\n }\n // Throw the last encountered error\n throw lastError\n}\n"],"mappings":";;;AAGA,MAAM,0BAAU,IAAI,IAA8B;;;;;AAMlD,MAAM,gBAAgB,OAAO,WAAqC;CAChE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,QAAQ,IAAI,MAAM,GAAG;EACxB,MAAM,SAAS,IAAI,iBAAiB;GAAE,KAAK;GAAQ,SAAS;EAAU,CAAC;EACvE,QAAQ,IAAI,QAAQ,MAAM;CAC5B;AAEJ;;;;;;;AAQA,eAAsB,iBACpB,QACA,IACY;CAEZ,MAAM,cAAc,MAAM;CAC1B,IAAI,YAAiB;CACrB,KAAK,MAAM,UAAU,QAAQ,OAAO,GAClC,IAAI;EAEF,OAAO,MADc,GAAG,MAAM;CAEhC,SAAS,OAAO;EACd,YAAY;CACd;CAGF,MAAM;AACR"}
|