@lifi/sdk 3.0.0-alpha.6 → 3.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LiFi.d.ts +21 -18
- package/dist/LiFi.js +16 -13
- package/dist/allowance/setAllowance.d.ts +1 -1
- package/dist/cjs/LiFi.d.ts +21 -18
- package/dist/cjs/LiFi.js +17 -14
- package/dist/cjs/allowance/setAllowance.d.ts +1 -1
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/connectors.js +3 -6
- package/dist/cjs/execution/BaseStepExecutor.d.ts +12 -0
- package/dist/cjs/execution/BaseStepExecutor.js +27 -0
- package/dist/cjs/execution/EVMStepExecutor.d.ts +13 -0
- package/dist/cjs/execution/EVMStepExecutor.js +292 -0
- package/dist/cjs/execution/RouteExecutionManager.d.ts +9 -8
- package/dist/cjs/execution/RouteExecutionManager.js +26 -24
- package/dist/cjs/execution/StatusManager.d.ts +8 -7
- package/dist/cjs/execution/StatusManager.js +1 -1
- package/dist/cjs/execution/StepExecutionManager.d.ts +3 -3
- package/dist/cjs/execution/StepExecutionManager.js +8 -8
- package/dist/cjs/execution/checkAllowance.d.ts +3 -2
- package/dist/cjs/execution/checkBalance.d.ts +2 -2
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +1 -0
- package/dist/cjs/execution/multisig.d.ts +2 -2
- package/dist/cjs/execution/multisig.js +2 -5
- package/dist/cjs/execution/prepareRestart.d.ts +2 -3
- package/dist/cjs/execution/prepareRestart.js +2 -2
- package/dist/cjs/execution/stepComparison.d.ts +4 -3
- package/dist/cjs/execution/stepComparison.js +1 -1
- package/dist/cjs/execution/switchChain.d.ts +4 -3
- package/dist/cjs/execution/switchChain.js +1 -0
- package/dist/cjs/{types/internal.types.d.ts → execution/types.d.ts} +33 -96
- package/dist/cjs/execution/utils.d.ts +2 -2
- package/dist/cjs/execution/waitForReceivingTransaction.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +2 -2
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.js +10 -4
- package/dist/cjs/providers/EVM.d.ts +10 -0
- package/dist/cjs/providers/EVM.js +34 -0
- package/dist/cjs/providers/Solana.d.ts +9 -0
- package/dist/cjs/providers/Solana.js +38 -0
- package/dist/cjs/providers/index.d.ts +1 -0
- package/dist/cjs/providers/index.js +17 -0
- package/dist/cjs/providers/types.d.ts +12 -0
- package/dist/cjs/providers/types.js +8 -0
- package/dist/cjs/request.js +12 -9
- package/dist/cjs/services/ApiService.d.ts +4 -5
- package/dist/cjs/services/ApiService.js +15 -18
- package/dist/cjs/services/ChainsService.d.ts +1 -1
- package/dist/cjs/services/ChainsService.js +2 -1
- package/dist/cjs/services/ConfigService.d.ts +9 -6
- package/dist/cjs/services/ConfigService.js +7 -4
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/index.d.ts +1 -3
- package/dist/cjs/types/index.js +1 -5
- package/dist/cjs/types/internal.d.ts +60 -0
- package/dist/cjs/types/internal.js +2 -0
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +3 -6
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.d.ts +1 -1
- package/dist/connectors.js +1 -1
- package/dist/execution/BaseStepExecutor.d.ts +12 -0
- package/dist/execution/BaseStepExecutor.js +23 -0
- package/dist/execution/EVMStepExecutor.d.ts +13 -0
- package/dist/execution/EVMStepExecutor.js +285 -0
- package/dist/execution/RouteExecutionManager.d.ts +9 -8
- package/dist/execution/RouteExecutionManager.js +25 -20
- package/dist/execution/StatusManager.d.ts +8 -7
- package/dist/execution/StatusManager.js +1 -1
- package/dist/execution/StepExecutionManager.d.ts +3 -3
- package/dist/execution/StepExecutionManager.js +6 -6
- package/dist/execution/checkAllowance.d.ts +3 -2
- package/dist/execution/checkBalance.d.ts +2 -2
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.js +1 -0
- package/dist/execution/multisig.d.ts +2 -2
- package/dist/execution/multisig.js +1 -1
- package/dist/execution/prepareRestart.d.ts +2 -3
- package/dist/execution/prepareRestart.js +2 -2
- package/dist/execution/stepComparison.d.ts +4 -3
- package/dist/execution/stepComparison.js +1 -1
- package/dist/execution/switchChain.d.ts +4 -3
- package/dist/execution/switchChain.js +1 -0
- package/dist/{types/internal.types.d.ts → execution/types.d.ts} +33 -96
- package/dist/execution/utils.d.ts +2 -2
- package/dist/execution/waitForReceivingTransaction.d.ts +3 -3
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -2
- package/dist/providers/EVM.d.ts +10 -0
- package/dist/providers/EVM.js +29 -0
- package/dist/providers/Solana.d.ts +9 -0
- package/dist/providers/Solana.js +33 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/types.d.ts +12 -0
- package/dist/providers/types.js +5 -0
- package/dist/request.js +12 -6
- package/dist/services/ApiService.d.ts +4 -5
- package/dist/services/ApiService.js +3 -3
- package/dist/services/ChainsService.d.ts +1 -1
- package/dist/services/ChainsService.js +1 -1
- package/dist/services/ConfigService.d.ts +9 -6
- package/dist/services/ConfigService.js +6 -5
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/index.js +1 -3
- package/dist/types/internal.d.ts +60 -0
- package/dist/types/internal.js +1 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -5
- package/dist/cjs/execution/StepExecutor.d.ts +0 -15
- package/dist/cjs/execution/StepExecutor.js +0 -62
- package/dist/execution/StepExecutor.d.ts +0 -15
- package/dist/execution/StepExecutor.js +0 -58
- /package/dist/cjs/{types/internal.types.js → execution/types.js} +0 -0
- /package/dist/{types/internal.types.js → execution/types.js} +0 -0
|
@@ -9,7 +9,7 @@ import { checkStepSlippageThreshold } from './utils';
|
|
|
9
9
|
* @param newStep
|
|
10
10
|
* @param settings
|
|
11
11
|
* @param allowUserInteraction
|
|
12
|
-
* @returns Return
|
|
12
|
+
* @returns Return LiFiStep
|
|
13
13
|
*/
|
|
14
14
|
export const stepComparison = async (statusManager, oldStep, newStep, settings, allowUserInteraction) => {
|
|
15
15
|
// Check if changed exchange rate is in the range of slippage threshold
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
2
|
import type { WalletClient } from 'viem';
|
|
3
|
-
import type { SwitchChainHook } from '../types';
|
|
4
3
|
import type { StatusManager } from './StatusManager';
|
|
4
|
+
import type { SwitchChainHook } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* This method checks whether the wallet client is configured for the correct chain.
|
|
7
7
|
* If yes it returns the wallet clien.
|
|
@@ -17,5 +17,6 @@ import type { StatusManager } from './StatusManager';
|
|
|
17
17
|
* @param step
|
|
18
18
|
* @param switchChainHook
|
|
19
19
|
* @param allowUserInteraction
|
|
20
|
+
* @returns New WalletClient
|
|
20
21
|
*/
|
|
21
|
-
export declare const switchChain: (walletClient: WalletClient, statusManager: StatusManager, step:
|
|
22
|
+
export declare const switchChain: (walletClient: WalletClient, statusManager: StatusManager, step: LiFiStep, switchChainHook: SwitchChainHook, allowUserInteraction: boolean) => Promise<WalletClient | undefined>;
|
|
@@ -14,6 +14,7 @@ import { LiFiErrorCode, ProviderError } from '../utils/errors';
|
|
|
14
14
|
* @param step
|
|
15
15
|
* @param switchChainHook
|
|
16
16
|
* @param allowUserInteraction
|
|
17
|
+
* @returns New WalletClient
|
|
17
18
|
*/
|
|
18
19
|
export const switchChain = async (walletClient, statusManager, step, switchChainHook, allowUserInteraction) => {
|
|
19
20
|
// if we are already on the correct chain we can proceed directly
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, Route, Token } from '@lifi/types';
|
|
2
2
|
import type { Hash, Hex, WalletClient } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { BaseStepExecutor } from './BaseStepExecutor';
|
|
4
|
+
import type { StatusManager } from './StatusManager';
|
|
5
|
+
export interface StepExecutorOptions {
|
|
6
|
+
statusManager: StatusManager;
|
|
7
|
+
settings: InternalExecutionSettings;
|
|
8
|
+
}
|
|
9
|
+
export interface RouteExecutionData {
|
|
10
|
+
route: Route;
|
|
11
|
+
executors: BaseStepExecutor[];
|
|
12
|
+
settings: InternalExecutionSettings;
|
|
13
|
+
}
|
|
14
|
+
export type RouteExecutionDictionary = Partial<Record<string, RouteExecutionData>>;
|
|
15
|
+
export type RouteExecutionPromiseDictionary = Partial<Record<string, Promise<Route>>>;
|
|
5
16
|
export type TransactionParameters = {
|
|
6
17
|
chainId?: number;
|
|
7
18
|
to?: string;
|
|
@@ -14,59 +25,11 @@ export type TransactionParameters = {
|
|
|
14
25
|
maxFeePerGas?: bigint;
|
|
15
26
|
maxPriorityFeePerGas?: bigint;
|
|
16
27
|
};
|
|
17
|
-
export interface ExecutionParams {
|
|
18
|
-
walletClient: WalletClient;
|
|
19
|
-
step: LifiStep;
|
|
20
|
-
statusManager: StatusManager;
|
|
21
|
-
settings: InternalExecutionSettings;
|
|
22
|
-
}
|
|
23
28
|
export type UpdateRouteHook = (updatedRoute: Route) => void;
|
|
24
29
|
export interface TransactionRequestParameters extends TransactionParameters {
|
|
25
30
|
requestType: 'approve' | 'transaction';
|
|
26
31
|
}
|
|
27
32
|
export type TransactionRequestUpdateHook = (updatedTxRequest: TransactionRequestParameters) => Promise<TransactionParameters>;
|
|
28
|
-
export type Config = {
|
|
29
|
-
apiUrl: string;
|
|
30
|
-
rpcs: Record<ChainId, string[]>;
|
|
31
|
-
multicallAddresses: Record<ChainId, string | undefined>;
|
|
32
|
-
defaultExecutionSettings: InternalExecutionSettings;
|
|
33
|
-
defaultRouteOptions: RouteOptions;
|
|
34
|
-
disableVersionCheck?: boolean;
|
|
35
|
-
userId?: string;
|
|
36
|
-
integrator: string;
|
|
37
|
-
widgetVersion?: string;
|
|
38
|
-
multisig?: MultisigConfig;
|
|
39
|
-
};
|
|
40
|
-
export interface MultisigTxDetails {
|
|
41
|
-
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
42
|
-
txHash?: Hash;
|
|
43
|
-
}
|
|
44
|
-
export interface MultisigTransactionResponse {
|
|
45
|
-
hash: string;
|
|
46
|
-
}
|
|
47
|
-
export interface BaseTransaction {
|
|
48
|
-
to: string;
|
|
49
|
-
value?: bigint;
|
|
50
|
-
data: string;
|
|
51
|
-
}
|
|
52
|
-
export interface MultisigConfig {
|
|
53
|
-
isMultisigWalletClient: boolean;
|
|
54
|
-
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
55
|
-
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
56
|
-
shouldBatchTransactions?: boolean;
|
|
57
|
-
}
|
|
58
|
-
export type ConfigUpdate = {
|
|
59
|
-
apiUrl?: string;
|
|
60
|
-
rpcs?: Record<number, string[]>;
|
|
61
|
-
multicallAddresses?: Record<number, string | undefined>;
|
|
62
|
-
defaultExecutionSettings?: ExecutionSettings;
|
|
63
|
-
defaultRouteOptions?: RouteOptions;
|
|
64
|
-
disableVersionCheck?: boolean;
|
|
65
|
-
userId?: string;
|
|
66
|
-
integrator: string;
|
|
67
|
-
widgetVersion?: string;
|
|
68
|
-
multisigConfig?: MultisigConfig;
|
|
69
|
-
};
|
|
70
33
|
export type SwitchChainHook = (requiredChainId: number) => Promise<WalletClient | undefined>;
|
|
71
34
|
export interface AcceptSlippageUpdateHookParams {
|
|
72
35
|
toToken: Token;
|
|
@@ -82,11 +45,6 @@ export interface ExchangeRateUpdateParams {
|
|
|
82
45
|
newToAmount: string;
|
|
83
46
|
}
|
|
84
47
|
export type AcceptExchangeRateUpdateHook = (params: ExchangeRateUpdateParams) => Promise<boolean | undefined>;
|
|
85
|
-
export interface RouteExecutionData {
|
|
86
|
-
route: Route;
|
|
87
|
-
executors: StepExecutor[];
|
|
88
|
-
settings: InternalExecutionSettings;
|
|
89
|
-
}
|
|
90
48
|
export type ExecutionSettings = Partial<InternalExecutionSettings>;
|
|
91
49
|
export interface InternalExecutionSettings {
|
|
92
50
|
acceptExchangeRateUpdateHook: AcceptExchangeRateUpdateHook;
|
|
@@ -96,50 +54,29 @@ export interface InternalExecutionSettings {
|
|
|
96
54
|
executeInBackground: boolean;
|
|
97
55
|
infiniteApproval: boolean;
|
|
98
56
|
}
|
|
99
|
-
export
|
|
100
|
-
|
|
57
|
+
export interface ExecutionParams {
|
|
58
|
+
walletClient: WalletClient;
|
|
59
|
+
step: LiFiStep;
|
|
60
|
+
statusManager: StatusManager;
|
|
61
|
+
settings: InternalExecutionSettings;
|
|
62
|
+
}
|
|
101
63
|
export interface InteractionSettings {
|
|
102
64
|
allowInteraction?: boolean;
|
|
103
65
|
allowUpdates?: boolean;
|
|
104
|
-
|
|
66
|
+
allowExecution?: boolean;
|
|
105
67
|
}
|
|
106
|
-
export interface
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
gas: number;
|
|
112
|
-
gas_price: number;
|
|
113
|
-
gas_fee_cap: number;
|
|
114
|
-
gas_tip_cap: number;
|
|
115
|
-
cumulative_gas_used: number;
|
|
116
|
-
gas_used: number;
|
|
117
|
-
effective_gas_price: number;
|
|
118
|
-
input: string;
|
|
119
|
-
nonce: number;
|
|
68
|
+
export interface MultisigTxDetails {
|
|
69
|
+
status: 'DONE' | 'FAILED' | 'PENDING' | 'CANCELLED';
|
|
70
|
+
txHash?: Hash;
|
|
71
|
+
}
|
|
72
|
+
export interface BaseTransaction {
|
|
120
73
|
to: string;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
access_list: any;
|
|
124
|
-
status: boolean;
|
|
125
|
-
addresses: string[];
|
|
126
|
-
contract_ids: string[];
|
|
127
|
-
network_id: string;
|
|
128
|
-
timestamp: string;
|
|
129
|
-
function_selector: string;
|
|
130
|
-
l1_block_number: number;
|
|
131
|
-
l1_timestamp: number;
|
|
132
|
-
deposit_tx: boolean;
|
|
133
|
-
system_tx: boolean;
|
|
134
|
-
mint: number;
|
|
135
|
-
sig: Signature;
|
|
136
|
-
error_message: string;
|
|
137
|
-
method: string;
|
|
138
|
-
decoded_input: any;
|
|
139
|
-
call_trace: any;
|
|
74
|
+
value?: bigint;
|
|
75
|
+
data: string;
|
|
140
76
|
}
|
|
141
|
-
export interface
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
77
|
+
export interface MultisigConfig {
|
|
78
|
+
isMultisigWalletClient: boolean;
|
|
79
|
+
getMultisigTransactionDetails: (txHash: Hash, fromChainId: number, updateIntermediateStatus?: () => void) => Promise<MultisigTxDetails>;
|
|
80
|
+
sendBatchTransaction?: (batchTransactions: BaseTransaction[]) => Promise<Hash>;
|
|
81
|
+
shouldBatchTransactions?: boolean;
|
|
145
82
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, ProcessType, Status, StatusMessage, Substatus } from '@lifi/types';
|
|
2
2
|
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
3
3
|
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
4
4
|
/**
|
|
@@ -9,4 +9,4 @@ export declare function getSubstatusMessage(status: StatusMessage, substatus?: S
|
|
|
9
9
|
* @param newStep
|
|
10
10
|
* @returns Boolean
|
|
11
11
|
*/
|
|
12
|
-
export declare function checkStepSlippageThreshold(oldStep:
|
|
12
|
+
export declare function checkStepSlippageThreshold(oldStep: LiFiStep, newStep: LiFiStep): boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { StatusManager } from '
|
|
3
|
-
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step:
|
|
1
|
+
import type { LiFiStep, ProcessType, StatusResponse } from '@lifi/types';
|
|
2
|
+
import type { StatusManager } from './StatusManager';
|
|
3
|
+
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: LiFiStep): Promise<StatusResponse>;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, Route } from '@lifi/types';
|
|
2
2
|
import type { TenderlyResponse } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Returns a random number between min (inclusive) and max (inclusive)
|
|
@@ -14,5 +14,5 @@ export declare const checkPackageUpdates: (packageName?: string, packageVersion?
|
|
|
14
14
|
* @returns - The route to be executed.
|
|
15
15
|
* @throws {ValidationError} Throws a ValidationError if the step has missing values.
|
|
16
16
|
*/
|
|
17
|
-
export declare const convertQuoteToRoute: (step:
|
|
17
|
+
export declare const convertQuoteToRoute: (step: LiFiStep) => Route;
|
|
18
18
|
export declare const fetchTxErrorDetails: (txHash: string, chainId: number) => Promise<TenderlyResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export * from '@lifi/types';
|
|
2
|
+
export { LiFi } from './LiFi';
|
|
1
3
|
export * from './execution';
|
|
2
4
|
export * from './helpers';
|
|
3
|
-
export {
|
|
5
|
+
export { EVM, type EVMProviderOptions } from './providers/EVM';
|
|
6
|
+
export { Solana, type SolanaProviderOptions } from './providers/Solana';
|
|
4
7
|
export * from './types';
|
|
5
8
|
export * from './utils/errors';
|
|
9
|
+
export { ErrorCode, LiFiError } from './utils/errors';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export * from '@lifi/types';
|
|
2
|
+
export { LiFi } from './LiFi';
|
|
2
3
|
export * from './execution';
|
|
3
4
|
export * from './helpers';
|
|
4
|
-
export {
|
|
5
|
+
export { EVM } from './providers/EVM';
|
|
6
|
+
export { Solana } from './providers/Solana';
|
|
5
7
|
export * from './types';
|
|
6
8
|
export * from './utils/errors';
|
|
9
|
+
export { LiFiError } from './utils/errors';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type WalletClient } from 'viem';
|
|
2
|
+
import type { SDKProvider } from './types';
|
|
3
|
+
export interface EVMProviderOptions {
|
|
4
|
+
getWalletClient: () => Promise<WalletClient>;
|
|
5
|
+
}
|
|
6
|
+
export interface EVMProvider extends SDKProvider {
|
|
7
|
+
setOptions(options: EVMProviderOptions): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function EVM(options?: EVMProviderOptions): EVMProvider;
|
|
10
|
+
export declare function isEVM(provider: SDKProvider): provider is EVMProvider;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAddress } from 'viem';
|
|
2
|
+
import { EVMStepExecutor } from '../execution/EVMStepExecutor';
|
|
3
|
+
import { ProviderType } from './types';
|
|
4
|
+
export function EVM(options) {
|
|
5
|
+
let getWalletClient = options?.getWalletClient;
|
|
6
|
+
return {
|
|
7
|
+
get type() {
|
|
8
|
+
return ProviderType.EVM;
|
|
9
|
+
},
|
|
10
|
+
isProviderStep(step) {
|
|
11
|
+
const isProviderStep = isAddress(step.action.fromAddress);
|
|
12
|
+
return isProviderStep;
|
|
13
|
+
},
|
|
14
|
+
async getStepExecutor(options) {
|
|
15
|
+
if (!getWalletClient) {
|
|
16
|
+
throw new Error(`getWalletClient is not provided.`);
|
|
17
|
+
}
|
|
18
|
+
const walletClient = await getWalletClient();
|
|
19
|
+
const executor = new EVMStepExecutor({ walletClient, ...options });
|
|
20
|
+
return executor;
|
|
21
|
+
},
|
|
22
|
+
setOptions(options) {
|
|
23
|
+
getWalletClient = options.getWalletClient;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function isEVM(provider) {
|
|
28
|
+
return provider.type === ProviderType.EVM;
|
|
29
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SDKProvider } from './types';
|
|
2
|
+
export interface SolanaProviderOptions {
|
|
3
|
+
getWalletClient: () => Promise<unknown>;
|
|
4
|
+
}
|
|
5
|
+
export interface SolanaProvider extends SDKProvider {
|
|
6
|
+
setOptions(options: SolanaProviderOptions): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function Solana(options?: SolanaProviderOptions): SolanaProvider;
|
|
9
|
+
export declare function isEVM(provider: SDKProvider): provider is SolanaProvider;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { ProviderType } from './types';
|
|
3
|
+
export function Solana(options) {
|
|
4
|
+
let getWalletClient = options?.getWalletClient;
|
|
5
|
+
return {
|
|
6
|
+
get type() {
|
|
7
|
+
return ProviderType.Solana;
|
|
8
|
+
},
|
|
9
|
+
isProviderStep(step) {
|
|
10
|
+
try {
|
|
11
|
+
const publickKey = new PublicKey(step.action.fromAddress);
|
|
12
|
+
const isProviderStep = PublicKey.isOnCurve(publickKey);
|
|
13
|
+
return isProviderStep;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
async getStepExecutor(options) {
|
|
20
|
+
if (!getWalletClient) {
|
|
21
|
+
throw new Error(`getWalletClient is not provided.`);
|
|
22
|
+
}
|
|
23
|
+
const walletClient = await getWalletClient();
|
|
24
|
+
return null;
|
|
25
|
+
},
|
|
26
|
+
setOptions(options) {
|
|
27
|
+
getWalletClient = options.getWalletClient;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function isEVM(provider) {
|
|
32
|
+
return provider.type === ProviderType.Solana;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LiFiStep } from '@lifi/types';
|
|
2
|
+
import type { BaseStepExecutor } from '../execution/BaseStepExecutor';
|
|
3
|
+
import type { StepExecutorOptions } from '../execution/types';
|
|
4
|
+
export interface SDKProvider {
|
|
5
|
+
readonly type: ProviderType;
|
|
6
|
+
isProviderStep(step: LiFiStep): boolean;
|
|
7
|
+
getStepExecutor(options: StepExecutorOptions): Promise<BaseStepExecutor>;
|
|
8
|
+
}
|
|
9
|
+
export declare enum ProviderType {
|
|
10
|
+
EVM = "EVM",
|
|
11
|
+
Solana = "Solana"
|
|
12
|
+
}
|
package/dist/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ConfigService from './services/ConfigService';
|
|
1
|
+
import { ConfigService } from './services/ConfigService';
|
|
2
2
|
import { HTTPError } from './utils/errors';
|
|
3
3
|
import { wait } from './utils/utils';
|
|
4
4
|
import { version } from './version';
|
|
@@ -8,32 +8,38 @@ export const requestSettings = {
|
|
|
8
8
|
export const request = async (url, options = {
|
|
9
9
|
retries: requestSettings.retries,
|
|
10
10
|
}) => {
|
|
11
|
-
const { userId, integrator, widgetVersion } = ConfigService.getInstance().getConfig();
|
|
11
|
+
const { userId, integrator, widgetVersion, apiKey } = ConfigService.getInstance().getConfig();
|
|
12
12
|
options.retries = options.retries ?? requestSettings.retries;
|
|
13
13
|
try {
|
|
14
14
|
if (!options.skipTrackingHeaders) {
|
|
15
|
+
if (apiKey) {
|
|
16
|
+
options.headers = {
|
|
17
|
+
...options?.headers,
|
|
18
|
+
'x-lifi-api-key': apiKey,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
15
21
|
if (userId) {
|
|
16
22
|
options.headers = {
|
|
17
23
|
...options?.headers,
|
|
18
|
-
'
|
|
24
|
+
'x-lifi-userid': userId,
|
|
19
25
|
};
|
|
20
26
|
}
|
|
21
27
|
if (widgetVersion) {
|
|
22
28
|
options.headers = {
|
|
23
29
|
...options?.headers,
|
|
24
|
-
'
|
|
30
|
+
'x-lifi-widget': widgetVersion,
|
|
25
31
|
};
|
|
26
32
|
}
|
|
27
33
|
if (version) {
|
|
28
34
|
options.headers = {
|
|
29
35
|
...options?.headers,
|
|
30
|
-
'
|
|
36
|
+
'x-lifi-sdk': version,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
// integrator is mandatory during SDK initialization
|
|
34
40
|
options.headers = {
|
|
35
41
|
...options?.headers,
|
|
36
|
-
'
|
|
42
|
+
'x-lifi-integrator': integrator,
|
|
37
43
|
};
|
|
38
44
|
}
|
|
39
45
|
const response = await fetch(url, options);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type { ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest,
|
|
2
|
-
import type { ChainId, ChainKey, ExtendedChain, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
1
|
+
import type { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LiFiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
2
|
declare const _default: {
|
|
4
3
|
getChains: (options?: RequestOptions | undefined) => Promise<ExtendedChain[]>;
|
|
5
|
-
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
4
|
+
getContractCallQuote: (requestConfig: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
6
5
|
getGasRecommendation: ({ chainId, fromChain, fromToken }: GasRecommendationRequest, options?: RequestOptions | undefined) => Promise<GasRecommendationResponse>;
|
|
7
6
|
getPossibilities: (requestConfig?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
8
|
-
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<
|
|
7
|
+
getQuote: (requestConfig: QuoteRequest, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
9
8
|
getRoutes: (requestConfig: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
10
9
|
getStatus: (requestConfig: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
11
|
-
getStepTransaction: (step:
|
|
10
|
+
getStepTransaction: (step: LiFiStep, options?: RequestOptions | undefined) => Promise<LiFiStep>;
|
|
12
11
|
getToken: (chain: ChainId | ChainKey, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
13
12
|
getTokens: (requestConfig?: TokensRequest | undefined, options?: RequestOptions | undefined) => Promise<TokensResponse>;
|
|
14
13
|
getTools: (requestConfig?: ToolsRequest | undefined, options?: RequestOptions | undefined) => Promise<ToolsResponse>;
|
|
@@ -2,7 +2,7 @@ import { request } from '../request';
|
|
|
2
2
|
import { isRoutesRequest, isStep } from '../typeguards';
|
|
3
3
|
import { ValidationError } from '../utils/errors';
|
|
4
4
|
import { parseBackendError } from '../utils/parseError';
|
|
5
|
-
import ConfigService from './ConfigService';
|
|
5
|
+
import { ConfigService } from './ConfigService';
|
|
6
6
|
/**
|
|
7
7
|
* @param requestConfig
|
|
8
8
|
* @param options
|
|
@@ -276,10 +276,10 @@ const getAvailableConnections = async (connectionRequest) => {
|
|
|
276
276
|
url.searchParams.append('fromToken', fromToken);
|
|
277
277
|
}
|
|
278
278
|
if (toChain) {
|
|
279
|
-
url.searchParams.append('
|
|
279
|
+
url.searchParams.append('toChain', toChain);
|
|
280
280
|
}
|
|
281
281
|
if (toToken) {
|
|
282
|
-
url.searchParams.append('
|
|
282
|
+
url.searchParams.append('toToken', toToken);
|
|
283
283
|
}
|
|
284
284
|
const connectionRequestArrayParams = [
|
|
285
285
|
'allowBridges',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Chain
|
|
2
|
-
|
|
1
|
+
import type { Chain } from '@lifi/types';
|
|
2
|
+
import type { SDKConfig, SDKOptions } from '../types';
|
|
3
|
+
export declare class ConfigService {
|
|
3
4
|
private static instance;
|
|
4
5
|
private readonly config;
|
|
5
6
|
private readonly setupPromise;
|
|
@@ -11,13 +12,15 @@ export default class ConfigService {
|
|
|
11
12
|
/**
|
|
12
13
|
* This call immediately returns the current config. It does not make sure that all chain data is already loaded
|
|
13
14
|
* Use this if you need access to basic information like API urls or settings
|
|
15
|
+
* @returns SDKConfig
|
|
14
16
|
*/
|
|
15
|
-
getConfig: () =>
|
|
17
|
+
getConfig: () => SDKConfig;
|
|
16
18
|
/**
|
|
17
19
|
* This call waits for all setup promises to be done.
|
|
18
20
|
* Use this if you need access to chain data (RPCs or multicalls)
|
|
21
|
+
* @returns SDKConfig
|
|
19
22
|
*/
|
|
20
|
-
getConfigAsync: () => Promise<
|
|
21
|
-
updateConfig: (configUpdate: Partial<
|
|
22
|
-
updateChains: (chains: Chain[]) =>
|
|
23
|
+
getConfigAsync: () => Promise<SDKConfig>;
|
|
24
|
+
updateConfig: (configUpdate: Partial<SDKOptions>) => SDKConfig;
|
|
25
|
+
updateChains: (chains: Chain[]) => SDKConfig;
|
|
23
26
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ChainId } from '
|
|
1
|
+
import { ChainId } from '@lifi/types';
|
|
2
2
|
const DefaultExecutionSettings = {
|
|
3
|
-
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
4
3
|
updateRouteHook: () => { },
|
|
5
4
|
switchChainHook: () => Promise.resolve(undefined),
|
|
6
5
|
acceptExchangeRateUpdateHook: () => Promise.resolve(undefined),
|
|
7
6
|
infiniteApproval: false,
|
|
8
7
|
executeInBackground: false,
|
|
9
8
|
};
|
|
10
|
-
class ConfigService {
|
|
9
|
+
export class ConfigService {
|
|
11
10
|
constructor() {
|
|
12
11
|
this.resolveSetupPromise = undefined;
|
|
13
12
|
/**
|
|
14
13
|
* This call immediately returns the current config. It does not make sure that all chain data is already loaded
|
|
15
14
|
* Use this if you need access to basic information like API urls or settings
|
|
15
|
+
* @returns SDKConfig
|
|
16
16
|
*/
|
|
17
17
|
this.getConfig = () => {
|
|
18
18
|
return this.config;
|
|
@@ -20,6 +20,7 @@ class ConfigService {
|
|
|
20
20
|
/**
|
|
21
21
|
* This call waits for all setup promises to be done.
|
|
22
22
|
* Use this if you need access to chain data (RPCs or multicalls)
|
|
23
|
+
* @returns SDKConfig
|
|
23
24
|
*/
|
|
24
25
|
this.getConfigAsync = async () => {
|
|
25
26
|
await this.setupPromise;
|
|
@@ -36,6 +37,7 @@ class ConfigService {
|
|
|
36
37
|
this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
|
|
37
38
|
// OPTIONS
|
|
38
39
|
this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
|
|
40
|
+
this.config.apiKey = configUpdate.apiKey || this.config.apiKey;
|
|
39
41
|
this.config.userId = configUpdate.userId || this.config.userId;
|
|
40
42
|
this.config.integrator = configUpdate.integrator || this.config.integrator;
|
|
41
43
|
this.config.defaultRouteOptions.integrator =
|
|
@@ -44,7 +46,7 @@ class ConfigService {
|
|
|
44
46
|
this.config.integrator;
|
|
45
47
|
this.config.widgetVersion =
|
|
46
48
|
configUpdate.widgetVersion || this.config.widgetVersion;
|
|
47
|
-
this.config.multisig = configUpdate.
|
|
49
|
+
this.config.multisig = configUpdate.multisig || this.config.multisig;
|
|
48
50
|
return this.config;
|
|
49
51
|
};
|
|
50
52
|
this.updateChains = (chains) => {
|
|
@@ -96,4 +98,3 @@ ConfigService.getDefaultConfig = () => {
|
|
|
96
98
|
integrator: 'lifi-sdk',
|
|
97
99
|
};
|
|
98
100
|
};
|
|
99
|
-
export default ConfigService;
|
package/dist/typeguards.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LiFiStep, RoutesRequest, StaticToken } from '@lifi/types';
|
|
2
2
|
export declare const isRoutesRequest: (routesRequest: RoutesRequest) => routesRequest is RoutesRequest;
|
|
3
|
-
export declare const isStep: (step:
|
|
3
|
+
export declare const isStep: (step: LiFiStep) => step is LiFiStep;
|
|
4
4
|
export declare const isToken: (token: StaticToken) => token is StaticToken;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ChainId, RouteOptions } from '@lifi/types';
|
|
2
|
+
import type { ExecutionSettings, InternalExecutionSettings, MultisigConfig } from '../execution/types';
|
|
3
|
+
import type { SDKProvider } from '../providers';
|
|
4
|
+
export interface SDKConfig {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
rpcs: Record<ChainId, string[]>;
|
|
8
|
+
multicallAddresses: Record<ChainId, string | undefined>;
|
|
9
|
+
defaultExecutionSettings: InternalExecutionSettings;
|
|
10
|
+
defaultRouteOptions: RouteOptions;
|
|
11
|
+
disableVersionCheck?: boolean;
|
|
12
|
+
userId?: string;
|
|
13
|
+
integrator: string;
|
|
14
|
+
widgetVersion?: string;
|
|
15
|
+
multisig?: MultisigConfig;
|
|
16
|
+
providers?: SDKProvider[];
|
|
17
|
+
}
|
|
18
|
+
export interface SDKOptions extends Partial<Omit<SDKConfig, 'defaultExecutionSettings' | 'integrator'>> {
|
|
19
|
+
defaultExecutionSettings?: ExecutionSettings;
|
|
20
|
+
integrator: string;
|
|
21
|
+
}
|
|
22
|
+
export interface TenderlyResponse {
|
|
23
|
+
hash: string;
|
|
24
|
+
block_hash: string;
|
|
25
|
+
block_number: number;
|
|
26
|
+
from: string;
|
|
27
|
+
gas: number;
|
|
28
|
+
gas_price: number;
|
|
29
|
+
gas_fee_cap: number;
|
|
30
|
+
gas_tip_cap: number;
|
|
31
|
+
cumulative_gas_used: number;
|
|
32
|
+
gas_used: number;
|
|
33
|
+
effective_gas_price: number;
|
|
34
|
+
input: string;
|
|
35
|
+
nonce: number;
|
|
36
|
+
to: string;
|
|
37
|
+
index: number;
|
|
38
|
+
value: string;
|
|
39
|
+
access_list: unknown;
|
|
40
|
+
status: boolean;
|
|
41
|
+
addresses: string[];
|
|
42
|
+
contract_ids: string[];
|
|
43
|
+
network_id: string;
|
|
44
|
+
timestamp: string;
|
|
45
|
+
function_selector: string;
|
|
46
|
+
l1_block_number: number;
|
|
47
|
+
l1_timestamp: number;
|
|
48
|
+
deposit_tx: boolean;
|
|
49
|
+
system_tx: boolean;
|
|
50
|
+
mint: number;
|
|
51
|
+
sig: {
|
|
52
|
+
v: string;
|
|
53
|
+
r: string;
|
|
54
|
+
s: string;
|
|
55
|
+
};
|
|
56
|
+
error_message: string;
|
|
57
|
+
method: string;
|
|
58
|
+
decoded_input: unknown;
|
|
59
|
+
call_trace: unknown;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|