@lifi/sdk 3.6.14-beta.0 → 3.7.0-alpha.0
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/package.json +6 -4
- package/src/_cjs/core/EVM/isBatchingSupported.js +2 -19
- package/src/_cjs/core/EVM/isBatchingSupported.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/Solana/types.js.map +1 -1
- package/src/_cjs/core/Sui/Sui.js +37 -0
- package/src/_cjs/core/Sui/Sui.js.map +1 -0
- package/src/_cjs/core/Sui/SuiStepExecutor.js +117 -0
- package/src/_cjs/core/Sui/SuiStepExecutor.js.map +1 -0
- package/src/_cjs/core/Sui/getSuiBalance.js +54 -0
- package/src/_cjs/core/Sui/getSuiBalance.js.map +1 -0
- package/src/_cjs/core/Sui/getSuiNSAddress.js +32 -0
- package/src/_cjs/core/Sui/getSuiNSAddress.js.map +1 -0
- package/src/_cjs/core/Sui/parseSuiErrors.js +38 -0
- package/src/_cjs/core/Sui/parseSuiErrors.js.map +1 -0
- package/src/_cjs/core/Sui/suiClient.js +38 -0
- package/src/_cjs/core/Sui/suiClient.js.map +1 -0
- package/src/_cjs/core/Sui/types.js +11 -0
- package/src/_cjs/core/Sui/types.js.map +1 -0
- package/src/_cjs/core/checkBalance.js +2 -2
- package/src/_cjs/core/checkBalance.js.map +1 -1
- package/src/_cjs/core/rpc.js +1 -1
- package/src/_cjs/core/rpc.js.map +1 -1
- package/src/_cjs/createConfig.js +1 -1
- package/src/_cjs/createConfig.js.map +1 -1
- package/src/_cjs/index.js +5 -1
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/balance.js +1 -5
- package/src/_cjs/services/balance.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_esm/core/EVM/isBatchingSupported.js +1 -17
- package/src/_esm/core/EVM/isBatchingSupported.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/Solana/types.js.map +1 -1
- package/src/_esm/core/StatusManager.js +1 -1
- package/src/_esm/core/Sui/Sui.js +34 -0
- package/src/_esm/core/Sui/Sui.js.map +1 -0
- package/src/_esm/core/Sui/SuiStepExecutor.js +118 -0
- package/src/_esm/core/Sui/SuiStepExecutor.js.map +1 -0
- package/src/_esm/core/Sui/getSuiBalance.js +51 -0
- package/src/_esm/core/Sui/getSuiBalance.js.map +1 -0
- package/src/_esm/core/Sui/getSuiNSAddress.js +29 -0
- package/src/_esm/core/Sui/getSuiNSAddress.js.map +1 -0
- package/src/_esm/core/Sui/parseSuiErrors.js +34 -0
- package/src/_esm/core/Sui/parseSuiErrors.js.map +1 -0
- package/src/_esm/core/Sui/suiClient.js +47 -0
- package/src/_esm/core/Sui/suiClient.js.map +1 -0
- package/src/_esm/core/Sui/types.js +7 -0
- package/src/_esm/core/Sui/types.js.map +1 -0
- package/src/_esm/core/checkBalance.js +2 -2
- package/src/_esm/core/checkBalance.js.map +1 -1
- package/src/_esm/core/rpc.js +1 -1
- package/src/_esm/core/rpc.js.map +1 -1
- package/src/_esm/createConfig.js +1 -1
- package/src/_esm/createConfig.js.map +1 -1
- package/src/_esm/index.js +3 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/balance.js +1 -5
- package/src/_esm/services/balance.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_types/core/EVM/isBatchingSupported.d.ts +1 -3
- package/src/_types/core/EVM/isBatchingSupported.d.ts.map +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts +2 -5
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/Solana/types.d.ts +4 -1
- package/src/_types/core/Solana/types.d.ts.map +1 -1
- package/src/_types/core/StatusManager.d.ts +1 -1
- package/src/_types/core/Sui/Sui.d.ts +3 -0
- package/src/_types/core/Sui/Sui.d.ts.map +1 -0
- package/src/_types/core/Sui/SuiStepExecutor.d.ts +10 -0
- package/src/_types/core/Sui/SuiStepExecutor.d.ts.map +1 -0
- package/src/_types/core/Sui/getSuiBalance.d.ts +3 -0
- package/src/_types/core/Sui/getSuiBalance.d.ts.map +1 -0
- package/src/_types/core/Sui/getSuiNSAddress.d.ts +2 -0
- package/src/_types/core/Sui/getSuiNSAddress.d.ts.map +1 -0
- package/src/_types/core/Sui/parseSuiErrors.d.ts +5 -0
- package/src/_types/core/Sui/parseSuiErrors.d.ts.map +1 -0
- package/src/_types/core/Sui/suiClient.d.ts +18 -0
- package/src/_types/core/Sui/suiClient.d.ts.map +1 -0
- package/src/_types/core/Sui/types.d.ts +15 -0
- package/src/_types/core/Sui/types.d.ts.map +1 -0
- package/src/_types/index.d.ts +5 -2
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/balance.d.ts +1 -1
- package/src/_types/services/balance.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/core/EVM/isBatchingSupported.ts +2 -41
- package/src/core/Solana/SolanaStepExecutor.ts +2 -10
- package/src/core/Solana/types.ts +5 -1
- package/src/core/StatusManager.ts +1 -1
- package/src/core/Sui/Sui.ts +41 -0
- package/src/core/Sui/SuiStepExecutor.ts +203 -0
- package/src/core/Sui/getSuiBalance.ts +86 -0
- package/src/core/Sui/getSuiNSAddress.ts +40 -0
- package/src/core/Sui/parseSuiErrors.ts +55 -0
- package/src/core/Sui/suiClient.ts +51 -0
- package/src/core/Sui/types.ts +23 -0
- package/src/core/checkBalance.ts +2 -2
- package/src/core/rpc.ts +1 -1
- package/src/createConfig.ts +1 -1
- package/src/index.ts +5 -9
- package/src/services/balance.ts +2 -7
- package/src/version.ts +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
2
|
+
|
|
3
|
+
const SNS_REGISTRY_ID =
|
|
4
|
+
'0x6e0ddefc0ad3ed64f53f5f91b7023077b2f7c131d7e6d5e0d1a0e4e6f1a2c3b4'
|
|
5
|
+
|
|
6
|
+
export async function getSuiNSAddress(
|
|
7
|
+
name: string,
|
|
8
|
+
rpcUrl?: string
|
|
9
|
+
): Promise<string | undefined> {
|
|
10
|
+
const client = new SuiClient({
|
|
11
|
+
url: rpcUrl || 'https://fullnode.mainnet.sui.io:443',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const result = await client.getObject({
|
|
16
|
+
id: SNS_REGISTRY_ID,
|
|
17
|
+
options: {
|
|
18
|
+
showContent: true,
|
|
19
|
+
},
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
if (!result.data?.content) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const registry = result.data.content as any
|
|
27
|
+
const nameRecord = registry.fields.records.find(
|
|
28
|
+
(record: any) => record.fields.name === name
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if (!nameRecord) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return nameRecord.fields.address
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error('Error resolving SuiNS address:', error)
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types'
|
|
2
|
+
import { SDKError } from '../../errors/SDKError.js'
|
|
3
|
+
import { BaseError } from '../../errors/baseError.js'
|
|
4
|
+
import { ErrorMessage, LiFiErrorCode } from '../../errors/constants.js'
|
|
5
|
+
import { TransactionError, UnknownError } from '../../errors/errors.js'
|
|
6
|
+
import type { Process } from '../types.js'
|
|
7
|
+
|
|
8
|
+
export const parseSuiErrors = async (
|
|
9
|
+
e: Error,
|
|
10
|
+
step?: LiFiStep,
|
|
11
|
+
process?: Process
|
|
12
|
+
): Promise<SDKError> => {
|
|
13
|
+
if (e instanceof SDKError) {
|
|
14
|
+
e.step = e.step ?? step
|
|
15
|
+
e.process = e.process ?? process
|
|
16
|
+
return e
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const baseError = handleSpecificErrors(e)
|
|
20
|
+
|
|
21
|
+
return new SDKError(baseError, step, process)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const handleSpecificErrors = (e: any) => {
|
|
25
|
+
const isRejection =
|
|
26
|
+
typeof e === 'string'
|
|
27
|
+
? e.toLowerCase().includes('reject')
|
|
28
|
+
: e.message?.toLowerCase().includes('reject')
|
|
29
|
+
|
|
30
|
+
if (isRejection) {
|
|
31
|
+
return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
e.message?.toLowerCase().includes('transaction') &&
|
|
36
|
+
(e.message?.toLowerCase().includes('failed') ||
|
|
37
|
+
e.message?.toLowerCase().includes('error'))
|
|
38
|
+
) {
|
|
39
|
+
return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (e.message?.includes('simulate') || e.message?.includes('simulation')) {
|
|
43
|
+
return new TransactionError(
|
|
44
|
+
LiFiErrorCode.TransactionSimulationFailed,
|
|
45
|
+
e.message,
|
|
46
|
+
e
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (e instanceof BaseError) {
|
|
51
|
+
return e
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return new UnknownError(e.message || ErrorMessage.UnknownError, e)
|
|
55
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ChainId } from '@lifi/types'
|
|
2
|
+
import { SuiClient } from '@mysten/sui/client'
|
|
3
|
+
import { getRpcUrls } from '../rpc.js'
|
|
4
|
+
|
|
5
|
+
const clients = new Map<string, SuiClient>()
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the Sui clients if they haven't been initialized yet.
|
|
9
|
+
* @returns - Promise that resolves when clients are initialized.
|
|
10
|
+
*/
|
|
11
|
+
export const ensureClients = async (): Promise<void> => {
|
|
12
|
+
const rpcUrls = await getRpcUrls(ChainId.SUI)
|
|
13
|
+
for (const rpcUrl of rpcUrls) {
|
|
14
|
+
if (!clients.get(rpcUrl)) {
|
|
15
|
+
const client = new SuiClient({ url: rpcUrl })
|
|
16
|
+
clients.set(rpcUrl, client)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Wrapper around getting the client (RPC provider) for Sui
|
|
23
|
+
* @returns - Sui RPC clients
|
|
24
|
+
*/
|
|
25
|
+
export const getSuiClients = async (): Promise<SuiClient[]> => {
|
|
26
|
+
await ensureClients()
|
|
27
|
+
return Array.from(clients.values())
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Calls a function on the SuiClient instances with retry logic.
|
|
32
|
+
* @param fn - The function to call, which receives a SuiClient instance.
|
|
33
|
+
* @returns - The result of the function call.
|
|
34
|
+
*/
|
|
35
|
+
export async function callSuiWithRetry<R>(
|
|
36
|
+
fn: (client: SuiClient) => Promise<R>
|
|
37
|
+
): Promise<R> {
|
|
38
|
+
// Ensure clients are initialized
|
|
39
|
+
await ensureClients()
|
|
40
|
+
let lastError: any = null
|
|
41
|
+
for (const client of clients.values()) {
|
|
42
|
+
try {
|
|
43
|
+
const result = await fn(client)
|
|
44
|
+
return result
|
|
45
|
+
} catch (error) {
|
|
46
|
+
lastError = error
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Throw the last encountered error
|
|
50
|
+
throw lastError
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChainType } from '@lifi/types'
|
|
2
|
+
import type { WalletWithRequiredFeatures } from '@mysten/wallet-standard'
|
|
3
|
+
import type { SDKProvider, StepExecutorOptions } from '../types.js'
|
|
4
|
+
|
|
5
|
+
export interface SuiProviderOptions {
|
|
6
|
+
getWallet?: () => Promise<WalletWithRequiredFeatures>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SuiProvider extends SDKProvider {
|
|
10
|
+
setOptions(options: SuiProviderOptions): void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function isSui(provider: SDKProvider): provider is SuiProvider {
|
|
14
|
+
return provider.type === ChainType.MVM
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface SuiStepExecutorOptions extends StepExecutorOptions {
|
|
18
|
+
wallet: WalletWithRequiredFeatures
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const SuiTokenShortAddress = '0x2::sui::SUI'
|
|
22
|
+
export const SuiTokenLongAddress =
|
|
23
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
|
package/src/core/checkBalance.ts
CHANGED
|
@@ -27,9 +27,9 @@ export const checkBalance = async (
|
|
|
27
27
|
// adjust amount in slippage limits
|
|
28
28
|
step.action.fromAmount = currentBalance.toString()
|
|
29
29
|
} else {
|
|
30
|
-
const
|
|
30
|
+
const needed = formatUnits(neededBalance, token.decimals)
|
|
31
31
|
const current = formatUnits(currentBalance, token.decimals)
|
|
32
|
-
let errorMessage = `Your ${token.symbol} balance is too low, you try to transfer ${
|
|
32
|
+
let errorMessage = `Your ${token.symbol} balance is too low, you try to transfer ${needed} ${token.symbol}, but your wallet only holds ${current} ${token.symbol}. No funds have been sent.`
|
|
33
33
|
|
|
34
34
|
if (currentBalance !== 0n) {
|
|
35
35
|
errorMessage += `If the problem consists, please delete this transfer and start a new one with a maximum of ${current} ${token.symbol}.`
|
package/src/core/rpc.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const getRpcUrl = async (chainId: ChainId): Promise<string> => {
|
|
|
9
9
|
export const getRpcUrls = async (chainId: ChainId): Promise<string[]> => {
|
|
10
10
|
const rpcUrls = (await config.getRPCUrls())[chainId]
|
|
11
11
|
if (!rpcUrls?.length) {
|
|
12
|
-
throw new Error(
|
|
12
|
+
throw new Error(`RPC URL not found for chainId: ${chainId}`)
|
|
13
13
|
}
|
|
14
14
|
return rpcUrls
|
|
15
15
|
}
|
package/src/createConfig.ts
CHANGED
|
@@ -20,7 +20,7 @@ function createBaseConfig(options: SDKConfig) {
|
|
|
20
20
|
|
|
21
21
|
export async function createChainsConfig() {
|
|
22
22
|
config.loading = getChains({
|
|
23
|
-
chainTypes: [ChainType.EVM, ChainType.SVM, ChainType.UTXO],
|
|
23
|
+
chainTypes: [ChainType.EVM, ChainType.SVM, ChainType.UTXO, ChainType.MVM],
|
|
24
24
|
})
|
|
25
25
|
.then((chains) => config.setChains(chains))
|
|
26
26
|
.catch()
|
package/src/index.ts
CHANGED
|
@@ -15,10 +15,7 @@ export { isEVM } from './core/EVM/types.js'
|
|
|
15
15
|
export { isBatchingSupported } from './core/EVM/isBatchingSupported.js'
|
|
16
16
|
export { isExtendedChain, convertExtendedChain } from './core/EVM/utils.js'
|
|
17
17
|
export { isRelayerStep, isGaslessStep } from './core/EVM/typeguards.js'
|
|
18
|
-
export type {
|
|
19
|
-
EVMProvider,
|
|
20
|
-
EVMProviderOptions,
|
|
21
|
-
} from './core/EVM/types.js'
|
|
18
|
+
export type { EVMProvider, EVMProviderOptions } from './core/EVM/types.js'
|
|
22
19
|
export { StatusManager } from './core/StatusManager.js'
|
|
23
20
|
export {
|
|
24
21
|
executeRoute,
|
|
@@ -96,11 +93,7 @@ export {
|
|
|
96
93
|
export { getNameServiceAddress } from './services/getNameServiceAddress.js'
|
|
97
94
|
export type { RPCUrls, SDKBaseConfig, SDKConfig } from './types/internal.js'
|
|
98
95
|
export { BaseError } from './errors/baseError.js'
|
|
99
|
-
export {
|
|
100
|
-
ErrorMessage,
|
|
101
|
-
ErrorName,
|
|
102
|
-
LiFiErrorCode,
|
|
103
|
-
} from './errors/constants.js'
|
|
96
|
+
export { ErrorMessage, ErrorName, LiFiErrorCode } from './errors/constants.js'
|
|
104
97
|
export type { ErrorCode } from './errors/constants.js'
|
|
105
98
|
export {
|
|
106
99
|
BalanceError,
|
|
@@ -113,3 +106,6 @@ export {
|
|
|
113
106
|
} from './errors/errors.js'
|
|
114
107
|
export { HTTPError } from './errors/httpError.js'
|
|
115
108
|
export { SDKError } from './errors/SDKError.js'
|
|
109
|
+
export { Sui } from './core/Sui/Sui.js'
|
|
110
|
+
export { isSui } from './core/Sui/types.js'
|
|
111
|
+
export type { SuiProvider, SuiProviderOptions } from './core/Sui/types.js'
|
package/src/services/balance.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Token, TokenAmount } from '@lifi/types'
|
|
2
2
|
import { config } from '../config.js'
|
|
3
3
|
import { ValidationError } from '../errors/errors.js'
|
|
4
4
|
import { isToken } from '../typeguards.js'
|
|
@@ -74,14 +74,9 @@ export const getTokenBalancesByChain = async (
|
|
|
74
74
|
Object.keys(tokensByChain).map(async (chainIdStr) => {
|
|
75
75
|
const chainId = Number.parseInt(chainIdStr)
|
|
76
76
|
const chain = await config.getChainById(chainId)
|
|
77
|
-
const tokenAddress = tokensByChain[chainId][0].address
|
|
78
77
|
const provider = config
|
|
79
78
|
.get()
|
|
80
|
-
.providers.find((provider) =>
|
|
81
|
-
chain.chainType === ChainType.UTXO
|
|
82
|
-
? provider.isAddress(walletAddress)
|
|
83
|
-
: provider.isAddress(tokenAddress)
|
|
84
|
-
)
|
|
79
|
+
.providers.find((provider) => provider.isAddress(walletAddress))
|
|
85
80
|
if (!provider) {
|
|
86
81
|
throw new Error(
|
|
87
82
|
`SDK Token Provider for ${chain.chainType} is not found.`
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '3.
|
|
2
|
+
export const version = '3.7.0-alpha.0'
|