@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.
Files changed (103) hide show
  1. package/package.json +6 -4
  2. package/src/_cjs/core/EVM/isBatchingSupported.js +2 -19
  3. package/src/_cjs/core/EVM/isBatchingSupported.js.map +1 -1
  4. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  5. package/src/_cjs/core/Solana/types.js.map +1 -1
  6. package/src/_cjs/core/Sui/Sui.js +37 -0
  7. package/src/_cjs/core/Sui/Sui.js.map +1 -0
  8. package/src/_cjs/core/Sui/SuiStepExecutor.js +117 -0
  9. package/src/_cjs/core/Sui/SuiStepExecutor.js.map +1 -0
  10. package/src/_cjs/core/Sui/getSuiBalance.js +54 -0
  11. package/src/_cjs/core/Sui/getSuiBalance.js.map +1 -0
  12. package/src/_cjs/core/Sui/getSuiNSAddress.js +32 -0
  13. package/src/_cjs/core/Sui/getSuiNSAddress.js.map +1 -0
  14. package/src/_cjs/core/Sui/parseSuiErrors.js +38 -0
  15. package/src/_cjs/core/Sui/parseSuiErrors.js.map +1 -0
  16. package/src/_cjs/core/Sui/suiClient.js +38 -0
  17. package/src/_cjs/core/Sui/suiClient.js.map +1 -0
  18. package/src/_cjs/core/Sui/types.js +11 -0
  19. package/src/_cjs/core/Sui/types.js.map +1 -0
  20. package/src/_cjs/core/checkBalance.js +2 -2
  21. package/src/_cjs/core/checkBalance.js.map +1 -1
  22. package/src/_cjs/core/rpc.js +1 -1
  23. package/src/_cjs/core/rpc.js.map +1 -1
  24. package/src/_cjs/createConfig.js +1 -1
  25. package/src/_cjs/createConfig.js.map +1 -1
  26. package/src/_cjs/index.js +5 -1
  27. package/src/_cjs/index.js.map +1 -1
  28. package/src/_cjs/services/balance.js +1 -5
  29. package/src/_cjs/services/balance.js.map +1 -1
  30. package/src/_cjs/version.js +1 -1
  31. package/src/_esm/core/EVM/isBatchingSupported.js +1 -17
  32. package/src/_esm/core/EVM/isBatchingSupported.js.map +1 -1
  33. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  34. package/src/_esm/core/Solana/types.js.map +1 -1
  35. package/src/_esm/core/StatusManager.js +1 -1
  36. package/src/_esm/core/Sui/Sui.js +34 -0
  37. package/src/_esm/core/Sui/Sui.js.map +1 -0
  38. package/src/_esm/core/Sui/SuiStepExecutor.js +118 -0
  39. package/src/_esm/core/Sui/SuiStepExecutor.js.map +1 -0
  40. package/src/_esm/core/Sui/getSuiBalance.js +51 -0
  41. package/src/_esm/core/Sui/getSuiBalance.js.map +1 -0
  42. package/src/_esm/core/Sui/getSuiNSAddress.js +29 -0
  43. package/src/_esm/core/Sui/getSuiNSAddress.js.map +1 -0
  44. package/src/_esm/core/Sui/parseSuiErrors.js +34 -0
  45. package/src/_esm/core/Sui/parseSuiErrors.js.map +1 -0
  46. package/src/_esm/core/Sui/suiClient.js +47 -0
  47. package/src/_esm/core/Sui/suiClient.js.map +1 -0
  48. package/src/_esm/core/Sui/types.js +7 -0
  49. package/src/_esm/core/Sui/types.js.map +1 -0
  50. package/src/_esm/core/checkBalance.js +2 -2
  51. package/src/_esm/core/checkBalance.js.map +1 -1
  52. package/src/_esm/core/rpc.js +1 -1
  53. package/src/_esm/core/rpc.js.map +1 -1
  54. package/src/_esm/createConfig.js +1 -1
  55. package/src/_esm/createConfig.js.map +1 -1
  56. package/src/_esm/index.js +3 -1
  57. package/src/_esm/index.js.map +1 -1
  58. package/src/_esm/services/balance.js +1 -5
  59. package/src/_esm/services/balance.js.map +1 -1
  60. package/src/_esm/version.js +1 -1
  61. package/src/_types/core/EVM/isBatchingSupported.d.ts +1 -3
  62. package/src/_types/core/EVM/isBatchingSupported.d.ts.map +1 -1
  63. package/src/_types/core/Solana/SolanaStepExecutor.d.ts +2 -5
  64. package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
  65. package/src/_types/core/Solana/types.d.ts +4 -1
  66. package/src/_types/core/Solana/types.d.ts.map +1 -1
  67. package/src/_types/core/StatusManager.d.ts +1 -1
  68. package/src/_types/core/Sui/Sui.d.ts +3 -0
  69. package/src/_types/core/Sui/Sui.d.ts.map +1 -0
  70. package/src/_types/core/Sui/SuiStepExecutor.d.ts +10 -0
  71. package/src/_types/core/Sui/SuiStepExecutor.d.ts.map +1 -0
  72. package/src/_types/core/Sui/getSuiBalance.d.ts +3 -0
  73. package/src/_types/core/Sui/getSuiBalance.d.ts.map +1 -0
  74. package/src/_types/core/Sui/getSuiNSAddress.d.ts +2 -0
  75. package/src/_types/core/Sui/getSuiNSAddress.d.ts.map +1 -0
  76. package/src/_types/core/Sui/parseSuiErrors.d.ts +5 -0
  77. package/src/_types/core/Sui/parseSuiErrors.d.ts.map +1 -0
  78. package/src/_types/core/Sui/suiClient.d.ts +18 -0
  79. package/src/_types/core/Sui/suiClient.d.ts.map +1 -0
  80. package/src/_types/core/Sui/types.d.ts +15 -0
  81. package/src/_types/core/Sui/types.d.ts.map +1 -0
  82. package/src/_types/index.d.ts +5 -2
  83. package/src/_types/index.d.ts.map +1 -1
  84. package/src/_types/services/balance.d.ts +1 -1
  85. package/src/_types/services/balance.d.ts.map +1 -1
  86. package/src/_types/version.d.ts +1 -1
  87. package/src/core/EVM/isBatchingSupported.ts +2 -41
  88. package/src/core/Solana/SolanaStepExecutor.ts +2 -10
  89. package/src/core/Solana/types.ts +5 -1
  90. package/src/core/StatusManager.ts +1 -1
  91. package/src/core/Sui/Sui.ts +41 -0
  92. package/src/core/Sui/SuiStepExecutor.ts +203 -0
  93. package/src/core/Sui/getSuiBalance.ts +86 -0
  94. package/src/core/Sui/getSuiNSAddress.ts +40 -0
  95. package/src/core/Sui/parseSuiErrors.ts +55 -0
  96. package/src/core/Sui/suiClient.ts +51 -0
  97. package/src/core/Sui/types.ts +23 -0
  98. package/src/core/checkBalance.ts +2 -2
  99. package/src/core/rpc.ts +1 -1
  100. package/src/createConfig.ts +1 -1
  101. package/src/index.ts +5 -9
  102. package/src/services/balance.ts +2 -7
  103. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
1
  import type { SignerWalletAdapter } from '@solana/wallet-adapter-base';
2
- import type { SDKProvider } from '../types.js';
2
+ import type { SDKProvider, StepExecutorOptions } from '../types.js';
3
3
  export interface SolanaProviderOptions {
4
4
  getWalletAdapter?: () => Promise<SignerWalletAdapter>;
5
5
  }
@@ -7,5 +7,8 @@ export interface SolanaProvider extends SDKProvider {
7
7
  setOptions(options: SolanaProviderOptions): void;
8
8
  }
9
9
  export declare function isSolana(provider: SDKProvider): provider is SolanaProvider;
10
+ export interface SolanaStepExecutorOptions extends StepExecutorOptions {
11
+ walletAdapter: SignerWalletAdapter;
12
+ }
10
13
  export declare const TokenProgramAddress = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
11
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../core/Solana/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAA;CACtD;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,UAAU,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAA;CACjD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,QAAQ,IAAI,cAAc,CAE1E;AAED,eAAO,MAAM,mBAAmB,gDAAgD,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../core/Solana/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEnE,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,CAAA;CACtD;AAED,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,UAAU,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAA;CACjD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,QAAQ,IAAI,cAAc,CAE1E;AAED,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,aAAa,EAAE,mBAAmB,CAAA;CACnC;AAED,eAAO,MAAM,mBAAmB,gDAAgD,CAAA"}
@@ -43,7 +43,7 @@ export declare class StatusManager {
43
43
  * @param step The step that should contain the new process.
44
44
  * @param type Type of the process. Used to identify already existing processes.
45
45
  * @param chainId Chain Id of the process.
46
- * @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
46
+ * @param status By default created process is set to the STARTED status. We can override new process with the needed status.
47
47
  * @returns Returns process.
48
48
  */
49
49
  findOrCreateProcess: ({ step, type, chainId, status, startedAt, }: FindOrCreateProcessProps) => Process;
@@ -0,0 +1,3 @@
1
+ import type { SuiProvider, SuiProviderOptions } from './types.js';
2
+ export declare function Sui(options?: SuiProviderOptions): SuiProvider;
3
+ //# sourceMappingURL=Sui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sui.d.ts","sourceRoot":"","sources":["../../../core/Sui/Sui.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEjE,wBAAgB,GAAG,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAgC7D"}
@@ -0,0 +1,10 @@
1
+ import { BaseStepExecutor } from '../BaseStepExecutor.js';
2
+ import type { LiFiStepExtended } from '../types.js';
3
+ import type { SuiStepExecutorOptions } from './types.js';
4
+ export declare class SuiStepExecutor extends BaseStepExecutor {
5
+ private wallet;
6
+ constructor(options: SuiStepExecutorOptions);
7
+ checkWallet: (step: LiFiStepExtended) => void;
8
+ executeStep: (step: LiFiStepExtended) => Promise<LiFiStepExtended>;
9
+ }
10
+ //# sourceMappingURL=SuiStepExecutor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuiStepExecutor.d.ts","sourceRoot":"","sources":["../../../core/Sui/SuiStepExecutor.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,aAAa,CAAA;AAI1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAO,CAAC,MAAM,CAA4B;gBAE9B,OAAO,EAAE,sBAAsB;IAK3C,WAAW,GAAI,MAAM,gBAAgB,UAYpC;IAED,WAAW,GAAU,MAAM,gBAAgB,KAAG,OAAO,CAAC,gBAAgB,CAAC,CAkKtE;CACF"}
@@ -0,0 +1,3 @@
1
+ import type { Token, TokenAmount } from '@lifi/types';
2
+ export declare function getSuiBalance(walletAddress: string, tokens: Token[]): Promise<TokenAmount[]>;
3
+ //# sourceMappingURL=getSuiBalance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSuiBalance.d.ts","sourceRoot":"","sources":["../../../core/Sui/getSuiBalance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAKrD,wBAAsB,aAAa,CACjC,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,KAAK,EAAE,GACd,OAAO,CAAC,WAAW,EAAE,CAAC,CAaxB"}
@@ -0,0 +1,2 @@
1
+ export declare function getSuiNSAddress(name: string, rpcUrl?: string): Promise<string | undefined>;
2
+ //# sourceMappingURL=getSuiNSAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSuiNSAddress.d.ts","sourceRoot":"","sources":["../../../core/Sui/getSuiNSAddress.ts"],"names":[],"mappings":"AAKA,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B7B"}
@@ -0,0 +1,5 @@
1
+ import type { LiFiStep } from '@lifi/types';
2
+ import { SDKError } from '../../errors/SDKError.js';
3
+ import type { Process } from '../types.js';
4
+ export declare const parseSuiErrors: (e: Error, step?: LiFiStep, process?: Process) => Promise<SDKError>;
5
+ //# sourceMappingURL=parseSuiErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSuiErrors.d.ts","sourceRoot":"","sources":["../../../core/Sui/parseSuiErrors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAInD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,cAAc,GACzB,GAAG,KAAK,EACR,OAAO,QAAQ,EACf,UAAU,OAAO,KAChB,OAAO,CAAC,QAAQ,CAUlB,CAAA"}
@@ -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"}
@@ -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, } from './core/EVM/types.js';
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, } from './errors/constants.js';
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,EACV,WAAW,EACX,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAC5B,YAA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oBAAoB,EACpB,QAAQ,EACR,eAAe,EACf,SAAS,EACT,SAAS,EACT,kBAAkB,EAClB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,qBAAqB,GACtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAA;AAC3E,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC9E,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { type Token, type TokenAmount } from '@lifi/types';
1
+ import type { Token, TokenAmount } from '@lifi/types';
2
2
  /**
3
3
  * Returns the balances of a specific token a wallet holds across all aggregated chains.
4
4
  * @param walletAddress - A wallet address.
@@ -1 +1 @@
1
- {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../services/balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAKrE;;;;;;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,CA4C9C,CAAA"}
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"}
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "3.6.14-beta.0";
2
+ export declare const version = "3.7.0-alpha.0";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1,50 +1,11 @@
1
1
  import { ChainType } from '@lifi/types'
2
- import type {
3
- Client,
4
- Transport,
5
- WalletCapabilities,
6
- WalletCapabilitiesRecord,
7
- } from 'viem'
8
- import type { GetCapabilitiesParameters, GetCapabilitiesReturnType } from 'viem'
9
- import { parseAccount } from 'viem/accounts'
2
+ import type { Client } from 'viem'
3
+ import { getCapabilities } from 'viem/actions'
10
4
  import { getAction } from 'viem/utils'
11
5
  import { config } from '../../config.js'
12
6
  import { sleep } from '../../utils/sleep.js'
13
7
  import type { EVMProvider } from './types.js'
14
8
 
15
- export async function getCapabilities<
16
- chainId extends number | undefined = undefined,
17
- >(
18
- client: Client<Transport>,
19
- parameters: GetCapabilitiesParameters<chainId> = {}
20
- ): Promise<GetCapabilitiesReturnType<chainId>> {
21
- const { account = client.account, chainId } = parameters
22
-
23
- const account_ = account ? parseAccount(account) : undefined
24
-
25
- const capabilities_raw = await client.request(
26
- {
27
- method: 'wallet_getCapabilities',
28
- params: [account_?.address],
29
- },
30
- {
31
- dedupe: true,
32
- retryCount: 0,
33
- }
34
- )
35
-
36
- const capabilities = {} as WalletCapabilitiesRecord<
37
- WalletCapabilities,
38
- number
39
- >
40
- for (const [key, value] of Object.entries(capabilities_raw)) {
41
- capabilities[Number(key)] = value
42
- }
43
- return (
44
- typeof chainId === 'number' ? capabilities[chainId] : capabilities
45
- ) as never
46
- }
47
-
48
9
  export async function isBatchingSupported({
49
10
  client,
50
11
  chainId,
@@ -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
@@ -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 procces is set to the STARTED status. We can override new process with the needed status.
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
+ }