@lifi/sdk 3.6.14 → 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 +5 -3
- 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/_cjs/version.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/_esm/version.js.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/_types/version.d.ts.map +1 -1
- 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,18 @@
|
|
|
1
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the Sui clients if they haven't been initialized yet.
|
|
4
|
+
* @returns - Promise that resolves when clients are initialized.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ensureClients: () => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper around getting the client (RPC provider) for Sui
|
|
9
|
+
* @returns - Sui RPC clients
|
|
10
|
+
*/
|
|
11
|
+
export declare const getSuiClients: () => Promise<SuiClient[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Calls a function on the SuiClient instances with retry logic.
|
|
14
|
+
* @param fn - The function to call, which receives a SuiClient instance.
|
|
15
|
+
* @returns - The result of the function call.
|
|
16
|
+
*/
|
|
17
|
+
export declare function callSuiWithRetry<R>(fn: (client: SuiClient) => Promise<R>): Promise<R>;
|
|
18
|
+
//# sourceMappingURL=suiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suiClient.d.ts","sourceRoot":"","sources":["../../../core/Sui/suiClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAK9C;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,IAAI,CAQlD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,SAAS,EAAE,CAGzD,CAAA;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,EAAE,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,CAAC,CAAC,CAcZ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
|
|
2
|
+
import type { SDKProvider, StepExecutorOptions } from '../types.js';
|
|
3
|
+
export interface SuiProviderOptions {
|
|
4
|
+
getWallet?: () => Promise<WalletWithRequiredFeatures>;
|
|
5
|
+
}
|
|
6
|
+
export interface SuiProvider extends SDKProvider {
|
|
7
|
+
setOptions(options: SuiProviderOptions): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function isSui(provider: SDKProvider): provider is SuiProvider;
|
|
10
|
+
export interface SuiStepExecutorOptions extends StepExecutorOptions {
|
|
11
|
+
wallet: WalletWithRequiredFeatures;
|
|
12
|
+
}
|
|
13
|
+
export declare const SuiTokenShortAddress = "0x2::sui::SUI";
|
|
14
|
+
export declare const SuiTokenLongAddress = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../core/Sui/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEnE,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,0BAA0B,CAAC,CAAA;CACtD;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAA;CAC9C;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,WAAW,GAAG,QAAQ,IAAI,WAAW,CAEpE;AAED,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,MAAM,EAAE,0BAA0B,CAAA;CACnC;AAED,eAAO,MAAM,oBAAoB,kBAAkB,CAAA;AACnD,eAAO,MAAM,mBAAmB,iFACgD,CAAA"}
|
package/src/_types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { isEVM } from './core/EVM/types.js';
|
|
|
7
7
|
export { isBatchingSupported } from './core/EVM/isBatchingSupported.js';
|
|
8
8
|
export { isExtendedChain, convertExtendedChain } from './core/EVM/utils.js';
|
|
9
9
|
export { isRelayerStep, isGaslessStep } from './core/EVM/typeguards.js';
|
|
10
|
-
export type { EVMProvider, EVMProviderOptions
|
|
10
|
+
export type { EVMProvider, EVMProviderOptions } from './core/EVM/types.js';
|
|
11
11
|
export { StatusManager } from './core/StatusManager.js';
|
|
12
12
|
export { executeRoute, getActiveRoute, getActiveRoutes, resumeRoute, stopRouteExecution, updateRouteExecution, } from './core/execution.js';
|
|
13
13
|
export type { AcceptExchangeRateUpdateHook, AcceptSlippageUpdateHook, AcceptSlippageUpdateHookParams, ExchangeRateUpdateParams, Execution, ExecutionOptions, ExecutionStatus, InteractionSettings, LiFiStepExtended, Process, ProcessStatus, ProcessType, RouteExecutionData, RouteExecutionDataDictionary, RouteExecutionDictionary, RouteExtended, SDKProvider, StepExecutor, StepExecutorOptions, StepExtended, SwitchChainHook, TransactionParameters, TransactionRequestParameters, TransactionRequestUpdateHook, UpdateRouteHook, } from './core/types.js';
|
|
@@ -28,9 +28,12 @@ export { getTokenBalance, getTokenBalances, getTokenBalancesByChain, } from './s
|
|
|
28
28
|
export { getNameServiceAddress } from './services/getNameServiceAddress.js';
|
|
29
29
|
export type { RPCUrls, SDKBaseConfig, SDKConfig } from './types/internal.js';
|
|
30
30
|
export { BaseError } from './errors/baseError.js';
|
|
31
|
-
export { ErrorMessage, ErrorName, LiFiErrorCode
|
|
31
|
+
export { ErrorMessage, ErrorName, LiFiErrorCode } from './errors/constants.js';
|
|
32
32
|
export type { ErrorCode } from './errors/constants.js';
|
|
33
33
|
export { BalanceError, ProviderError, RPCError, ServerError, TransactionError, UnknownError, ValidationError, } from './errors/errors.js';
|
|
34
34
|
export { HTTPError } from './errors/httpError.js';
|
|
35
35
|
export { SDKError } from './errors/SDKError.js';
|
|
36
|
+
export { Sui } from './core/Sui/Sui.js';
|
|
37
|
+
export { isSui } from './core/Sui/types.js';
|
|
38
|
+
export type { SuiProvider, SuiProviderOptions } from './core/Sui/types.js';
|
|
36
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EACL,iBAAiB,EACjB,0BAA0B,GAC3B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACvE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../services/balance.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../services/balance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAKrD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,eAAe,MAAM,EACrB,OAAO,KAAK,KACX,OAAO,CAAC,WAAW,GAAG,IAAI,CAG5B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,eAAe,MAAM,EACrB,QAAQ,KAAK,EAAE,KACd,OAAO,CAAC,WAAW,EAAE,CAkBvB,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAClC,eAAe,MAAM,EACrB,eAAe;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,CAAA;CAAE,KAC5C,OAAO,CAAC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAAA;CAAE,CAuC9C,CAAA"}
|
package/src/_types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,cAAc,CAAA;AAC/B,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,cAAc,CAAA;AAC/B,eAAO,MAAM,OAAO,kBAAkB,CAAA"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {} from '@lifi/types'
|
|
2
1
|
import type { SignerWalletAdapter } from '@solana/wallet-adapter-base'
|
|
3
2
|
import { VersionedTransaction } from '@solana/web3.js'
|
|
4
3
|
import { withTimeout } from 'viem'
|
|
@@ -10,19 +9,12 @@ import { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'
|
|
|
10
9
|
import { BaseStepExecutor } from '../BaseStepExecutor.js'
|
|
11
10
|
import { checkBalance } from '../checkBalance.js'
|
|
12
11
|
import { stepComparison } from '../stepComparison.js'
|
|
13
|
-
import type {
|
|
14
|
-
LiFiStepExtended,
|
|
15
|
-
StepExecutorOptions,
|
|
16
|
-
TransactionParameters,
|
|
17
|
-
} from '../types.js'
|
|
12
|
+
import type { LiFiStepExtended, TransactionParameters } from '../types.js'
|
|
18
13
|
import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js'
|
|
19
14
|
import { callSolanaWithRetry } from './connection.js'
|
|
20
15
|
import { parseSolanaErrors } from './parseSolanaErrors.js'
|
|
21
16
|
import { sendAndConfirmTransaction } from './sendAndConfirmTransaction.js'
|
|
22
|
-
|
|
23
|
-
export interface SolanaStepExecutorOptions extends StepExecutorOptions {
|
|
24
|
-
walletAdapter: SignerWalletAdapter
|
|
25
|
-
}
|
|
17
|
+
import type { SolanaStepExecutorOptions } from './types.js'
|
|
26
18
|
|
|
27
19
|
export class SolanaStepExecutor extends BaseStepExecutor {
|
|
28
20
|
private walletAdapter: SignerWalletAdapter
|
package/src/core/Solana/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChainType } from '@lifi/types'
|
|
2
2
|
import type { SignerWalletAdapter } from '@solana/wallet-adapter-base'
|
|
3
|
-
import type { SDKProvider } from '../types.js'
|
|
3
|
+
import type { SDKProvider, StepExecutorOptions } from '../types.js'
|
|
4
4
|
|
|
5
5
|
export interface SolanaProviderOptions {
|
|
6
6
|
getWalletAdapter?: () => Promise<SignerWalletAdapter>
|
|
@@ -14,4 +14,8 @@ export function isSolana(provider: SDKProvider): provider is SolanaProvider {
|
|
|
14
14
|
return provider.type === ChainType.SVM
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export interface SolanaStepExecutorOptions extends StepExecutorOptions {
|
|
18
|
+
walletAdapter: SignerWalletAdapter
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
export const TokenProgramAddress = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
|
|
@@ -116,7 +116,7 @@ export class StatusManager {
|
|
|
116
116
|
* @param step The step that should contain the new process.
|
|
117
117
|
* @param type Type of the process. Used to identify already existing processes.
|
|
118
118
|
* @param chainId Chain Id of the process.
|
|
119
|
-
* @param status By default created
|
|
119
|
+
* @param status By default created process is set to the STARTED status. We can override new process with the needed status.
|
|
120
120
|
* @returns Returns process.
|
|
121
121
|
*/
|
|
122
122
|
findOrCreateProcess = ({
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ChainType } from '@lifi/types'
|
|
2
|
+
import { isValidSuiAddress } from '@mysten/sui/utils'
|
|
3
|
+
import type { StepExecutorOptions } from '../types.js'
|
|
4
|
+
import { SuiStepExecutor } from './SuiStepExecutor.js'
|
|
5
|
+
import { getSuiBalance } from './getSuiBalance.js'
|
|
6
|
+
import { getSuiNSAddress } from './getSuiNSAddress.js'
|
|
7
|
+
import type { SuiProvider, SuiProviderOptions } from './types.js'
|
|
8
|
+
|
|
9
|
+
export function Sui(options?: SuiProviderOptions): SuiProvider {
|
|
10
|
+
const _options: SuiProviderOptions = options ?? {}
|
|
11
|
+
return {
|
|
12
|
+
get type() {
|
|
13
|
+
return ChainType.MVM
|
|
14
|
+
},
|
|
15
|
+
isAddress: isValidSuiAddress,
|
|
16
|
+
resolveAddress: getSuiNSAddress,
|
|
17
|
+
getBalance: getSuiBalance,
|
|
18
|
+
async getStepExecutor(
|
|
19
|
+
options: StepExecutorOptions
|
|
20
|
+
): Promise<SuiStepExecutor> {
|
|
21
|
+
if (!_options.getWallet) {
|
|
22
|
+
throw new Error('getWallet is not provided.')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const wallet = await _options.getWallet()
|
|
26
|
+
|
|
27
|
+
const executor = new SuiStepExecutor({
|
|
28
|
+
wallet,
|
|
29
|
+
routeId: options.routeId,
|
|
30
|
+
executionOptions: {
|
|
31
|
+
...options.executionOptions,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return executor
|
|
36
|
+
},
|
|
37
|
+
setOptions(options: SuiProviderOptions) {
|
|
38
|
+
Object.assign(_options, options)
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type WalletWithRequiredFeatures,
|
|
3
|
+
signAndExecuteTransaction,
|
|
4
|
+
} from '@mysten/wallet-standard'
|
|
5
|
+
import { config } from '../../config.js'
|
|
6
|
+
import { LiFiErrorCode } from '../../errors/constants.js'
|
|
7
|
+
import { TransactionError } from '../../errors/errors.js'
|
|
8
|
+
import { getStepTransaction } from '../../services/api.js'
|
|
9
|
+
import { BaseStepExecutor } from '../BaseStepExecutor.js'
|
|
10
|
+
import { checkBalance } from '../checkBalance.js'
|
|
11
|
+
import { stepComparison } from '../stepComparison.js'
|
|
12
|
+
import type { LiFiStepExtended, TransactionParameters } from '../types.js'
|
|
13
|
+
import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js'
|
|
14
|
+
import { parseSuiErrors } from './parseSuiErrors.js'
|
|
15
|
+
import { callSuiWithRetry } from './suiClient.js'
|
|
16
|
+
import type { SuiStepExecutorOptions } from './types.js'
|
|
17
|
+
|
|
18
|
+
export class SuiStepExecutor extends BaseStepExecutor {
|
|
19
|
+
private wallet: WalletWithRequiredFeatures
|
|
20
|
+
|
|
21
|
+
constructor(options: SuiStepExecutorOptions) {
|
|
22
|
+
super(options)
|
|
23
|
+
this.wallet = options.wallet
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
checkWallet = (step: LiFiStepExtended) => {
|
|
27
|
+
// Prevent execution of the quote by wallet different from the one which requested the quote
|
|
28
|
+
if (
|
|
29
|
+
!this.wallet.accounts?.some?.(
|
|
30
|
+
(account) => account.address === step.action.fromAddress
|
|
31
|
+
)
|
|
32
|
+
) {
|
|
33
|
+
throw new TransactionError(
|
|
34
|
+
LiFiErrorCode.WalletChangedDuringExecution,
|
|
35
|
+
'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
executeStep = async (step: LiFiStepExtended): Promise<LiFiStepExtended> => {
|
|
41
|
+
step.execution = this.statusManager.initExecutionObject(step)
|
|
42
|
+
|
|
43
|
+
const fromChain = await config.getChainById(step.action.fromChainId)
|
|
44
|
+
const toChain = await config.getChainById(step.action.toChainId)
|
|
45
|
+
|
|
46
|
+
const isBridgeExecution = fromChain.id !== toChain.id
|
|
47
|
+
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
48
|
+
|
|
49
|
+
let process = this.statusManager.findOrCreateProcess({
|
|
50
|
+
step,
|
|
51
|
+
type: currentProcessType,
|
|
52
|
+
chainId: fromChain.id,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
if (process.status !== 'DONE') {
|
|
56
|
+
try {
|
|
57
|
+
process = this.statusManager.updateProcess(
|
|
58
|
+
step,
|
|
59
|
+
process.type,
|
|
60
|
+
'STARTED'
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
// Check balance
|
|
64
|
+
await checkBalance(step.action.fromAddress!, step)
|
|
65
|
+
|
|
66
|
+
// Create new transaction
|
|
67
|
+
if (!step.transactionRequest) {
|
|
68
|
+
const { execution, ...stepBase } = step
|
|
69
|
+
const updatedStep = await getStepTransaction(stepBase)
|
|
70
|
+
const comparedStep = await stepComparison(
|
|
71
|
+
this.statusManager,
|
|
72
|
+
step,
|
|
73
|
+
updatedStep,
|
|
74
|
+
this.allowUserInteraction,
|
|
75
|
+
this.executionOptions
|
|
76
|
+
)
|
|
77
|
+
Object.assign(step, {
|
|
78
|
+
...comparedStep,
|
|
79
|
+
execution: step.execution,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!step.transactionRequest?.data) {
|
|
84
|
+
throw new TransactionError(
|
|
85
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
86
|
+
'Unable to prepare transaction.'
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
process = this.statusManager.updateProcess(
|
|
91
|
+
step,
|
|
92
|
+
process.type,
|
|
93
|
+
'ACTION_REQUIRED'
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if (!this.allowUserInteraction) {
|
|
97
|
+
return step
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let transactionRequest: TransactionParameters = {
|
|
101
|
+
data: step.transactionRequest.data,
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.executionOptions?.updateTransactionRequestHook) {
|
|
105
|
+
const customizedTransactionRequest: TransactionParameters =
|
|
106
|
+
await this.executionOptions.updateTransactionRequestHook({
|
|
107
|
+
requestType: 'transaction',
|
|
108
|
+
...transactionRequest,
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
transactionRequest = {
|
|
112
|
+
...transactionRequest,
|
|
113
|
+
...customizedTransactionRequest,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const transactionRequestData = transactionRequest.data
|
|
118
|
+
|
|
119
|
+
if (!transactionRequestData) {
|
|
120
|
+
throw new TransactionError(
|
|
121
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
122
|
+
'Unable to prepare transaction.'
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
this.checkWallet(step)
|
|
127
|
+
|
|
128
|
+
// We give users 2 minutes to sign the transaction
|
|
129
|
+
const signedTx = await signAndExecuteTransaction(this.wallet, {
|
|
130
|
+
account: this.wallet.accounts.find(
|
|
131
|
+
(account) => account.address === step.action.fromAddress
|
|
132
|
+
)!,
|
|
133
|
+
chain: 'sui:mainnet',
|
|
134
|
+
transaction: {
|
|
135
|
+
toJSON: async () => transactionRequestData,
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
process = this.statusManager.updateProcess(
|
|
140
|
+
step,
|
|
141
|
+
process.type,
|
|
142
|
+
'PENDING'
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
const result = await callSuiWithRetry((client) =>
|
|
146
|
+
client.waitForTransaction({
|
|
147
|
+
digest: signedTx.digest,
|
|
148
|
+
options: {
|
|
149
|
+
showEffects: true,
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if (result.effects?.status.status !== 'success') {
|
|
155
|
+
throw new TransactionError(
|
|
156
|
+
LiFiErrorCode.TransactionFailed,
|
|
157
|
+
`Transaction failed: ${result.effects?.status.error}`
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Transaction has been confirmed and we can update the process
|
|
162
|
+
process = this.statusManager.updateProcess(
|
|
163
|
+
step,
|
|
164
|
+
process.type,
|
|
165
|
+
'PENDING',
|
|
166
|
+
{
|
|
167
|
+
txHash: result.digest,
|
|
168
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}txblock/${result.digest}`,
|
|
169
|
+
}
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
if (isBridgeExecution) {
|
|
173
|
+
process = this.statusManager.updateProcess(step, process.type, 'DONE')
|
|
174
|
+
}
|
|
175
|
+
} catch (e: any) {
|
|
176
|
+
const error = await parseSuiErrors(e, step, process)
|
|
177
|
+
process = this.statusManager.updateProcess(
|
|
178
|
+
step,
|
|
179
|
+
process.type,
|
|
180
|
+
'FAILED',
|
|
181
|
+
{
|
|
182
|
+
error: {
|
|
183
|
+
message: error.cause.message,
|
|
184
|
+
code: error.code,
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
this.statusManager.updateExecution(step, 'FAILED')
|
|
189
|
+
throw error
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await waitForDestinationChainTransaction(
|
|
194
|
+
step,
|
|
195
|
+
process,
|
|
196
|
+
fromChain,
|
|
197
|
+
toChain,
|
|
198
|
+
this.statusManager
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
return step
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Token, TokenAmount } from '@lifi/types'
|
|
2
|
+
import { withDedupe } from '../../utils/withDedupe.js'
|
|
3
|
+
import { callSuiWithRetry } from './suiClient.js'
|
|
4
|
+
import { SuiTokenLongAddress, SuiTokenShortAddress } from './types.js'
|
|
5
|
+
|
|
6
|
+
export async function getSuiBalance(
|
|
7
|
+
walletAddress: string,
|
|
8
|
+
tokens: Token[]
|
|
9
|
+
): Promise<TokenAmount[]> {
|
|
10
|
+
if (tokens.length === 0) {
|
|
11
|
+
return []
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { chainId } = tokens[0]
|
|
15
|
+
for (const token of tokens) {
|
|
16
|
+
if (token.chainId !== chainId) {
|
|
17
|
+
console.warn('Requested tokens have to be on the same chain.')
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return getSuiBalanceDefault(chainId, tokens, walletAddress)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const getSuiBalanceDefault = async (
|
|
25
|
+
_chainId: number,
|
|
26
|
+
tokens: Token[],
|
|
27
|
+
walletAddress: string
|
|
28
|
+
): Promise<TokenAmount[]> => {
|
|
29
|
+
const [coins, checkpoint] = await Promise.allSettled([
|
|
30
|
+
withDedupe(
|
|
31
|
+
() =>
|
|
32
|
+
callSuiWithRetry((client) =>
|
|
33
|
+
client.getAllBalances({
|
|
34
|
+
owner: walletAddress,
|
|
35
|
+
})
|
|
36
|
+
),
|
|
37
|
+
{ id: `${getSuiBalanceDefault.name}.getAllBalances` }
|
|
38
|
+
),
|
|
39
|
+
withDedupe(
|
|
40
|
+
() =>
|
|
41
|
+
callSuiWithRetry((client) =>
|
|
42
|
+
client.getLatestCheckpointSequenceNumber()
|
|
43
|
+
),
|
|
44
|
+
{ id: `${getSuiBalanceDefault.name}.getLatestCheckpointSequenceNumber` }
|
|
45
|
+
),
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
const coinsResult = coins.status === 'fulfilled' ? coins.value : []
|
|
49
|
+
const blockNumber =
|
|
50
|
+
checkpoint.status === 'fulfilled' ? BigInt(checkpoint.value) : 0n
|
|
51
|
+
|
|
52
|
+
const walletTokenAmounts = coinsResult.reduce(
|
|
53
|
+
(tokenAmounts, coin) => {
|
|
54
|
+
const amount = BigInt(coin.totalBalance)
|
|
55
|
+
if (amount > 0n) {
|
|
56
|
+
tokenAmounts[coin.coinType] = amount
|
|
57
|
+
}
|
|
58
|
+
return tokenAmounts
|
|
59
|
+
},
|
|
60
|
+
{} as Record<string, bigint>
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const suiTokenBalance = coinsResult.find(
|
|
64
|
+
(coin) => coin.coinType === SuiTokenShortAddress
|
|
65
|
+
)
|
|
66
|
+
if (suiTokenBalance?.totalBalance) {
|
|
67
|
+
walletTokenAmounts[SuiTokenLongAddress] = BigInt(
|
|
68
|
+
suiTokenBalance.totalBalance
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tokenAmounts: TokenAmount[] = tokens.map((token) => {
|
|
73
|
+
if (walletTokenAmounts[token.address]) {
|
|
74
|
+
return {
|
|
75
|
+
...token,
|
|
76
|
+
amount: walletTokenAmounts[token.address],
|
|
77
|
+
blockNumber,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
...token,
|
|
82
|
+
blockNumber,
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
return tokenAmounts
|
|
86
|
+
}
|
|
@@ -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'
|