@lifi/sdk 2.0.0-beta.1 → 2.0.0-beta.11
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 → LiFi.d.ts} +19 -63
- package/dist/{Lifi.js → LiFi.js} +19 -212
- package/dist/allowance/checkAllowance.d.ts +2 -2
- package/dist/allowance/checkAllowance.js +16 -2
- package/dist/allowance/utils.d.ts +2 -1
- package/dist/allowance/utils.js +7 -2
- package/dist/balance/checkBalance.d.ts +2 -2
- package/dist/balance/index.d.ts +1 -1
- package/dist/cjs/{Lifi.d.ts → LiFi.d.ts} +19 -63
- package/dist/cjs/{Lifi.js → LiFi.js} +22 -213
- package/dist/cjs/allowance/checkAllowance.d.ts +2 -2
- package/dist/cjs/allowance/checkAllowance.js +16 -2
- package/dist/cjs/allowance/utils.d.ts +2 -1
- package/dist/cjs/allowance/utils.js +7 -2
- package/dist/cjs/balance/checkBalance.d.ts +2 -2
- package/dist/cjs/balance/index.d.ts +1 -1
- package/dist/cjs/connectors.d.ts +1 -1
- package/dist/cjs/connectors.js +7 -9
- package/dist/cjs/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/cjs/execution/RouteExecutionManager.js +220 -0
- package/dist/cjs/execution/StatusManager.d.ts +12 -12
- package/dist/cjs/execution/StatusManager.js +5 -5
- package/dist/cjs/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/cjs/execution/{ExecutionManager.js → StepExecutionManager.js} +11 -3
- package/dist/cjs/execution/StepExecutor.d.ts +4 -4
- package/dist/cjs/execution/StepExecutor.js +17 -9
- package/dist/cjs/execution/stepComparison.d.ts +3 -3
- package/dist/cjs/execution/stepComparison.js +2 -5
- package/dist/cjs/execution/switchChain.d.ts +2 -2
- package/dist/cjs/execution/utils.d.ts +3 -3
- package/dist/cjs/helpers.d.ts +5 -7
- package/dist/cjs/helpers.js +10 -30
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/request.d.ts +9 -0
- package/dist/cjs/request.js +60 -0
- package/dist/cjs/services/ApiService.d.ts +8 -7
- package/dist/cjs/services/ApiService.js +52 -31
- package/dist/cjs/services/ConfigService.js +6 -2
- package/dist/cjs/typeguards.d.ts +2 -2
- package/dist/cjs/types/internal.types.d.ts +54 -10
- package/dist/cjs/utils/errors.d.ts +20 -1
- package/dist/cjs/utils/errors.js +23 -1
- package/dist/cjs/utils/parseError.d.ts +4 -4
- package/dist/cjs/utils/parseError.js +29 -12
- package/dist/cjs/utils/utils.d.ts +3 -3
- 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 +7 -9
- package/dist/execution/RouteExecutionManager.d.ts +65 -0
- package/dist/execution/RouteExecutionManager.js +213 -0
- package/dist/execution/StatusManager.d.ts +12 -12
- package/dist/execution/StatusManager.js +5 -5
- package/dist/execution/{ExecutionManager.d.ts → StepExecutionManager.d.ts} +1 -1
- package/dist/execution/{ExecutionManager.js → StepExecutionManager.js} +9 -1
- package/dist/execution/StepExecutor.d.ts +4 -4
- package/dist/execution/StepExecutor.js +17 -9
- package/dist/execution/stepComparison.d.ts +3 -3
- package/dist/execution/stepComparison.js +2 -5
- package/dist/execution/switchChain.d.ts +2 -2
- package/dist/execution/utils.d.ts +3 -3
- package/dist/helpers.d.ts +5 -7
- package/dist/helpers.js +9 -29
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -3
- package/dist/request.d.ts +9 -0
- package/dist/request.js +53 -0
- package/dist/services/ApiService.d.ts +8 -7
- package/dist/services/ApiService.js +43 -22
- package/dist/services/ConfigService.js +7 -2
- package/dist/typeguards.d.ts +2 -2
- package/dist/types/internal.types.d.ts +54 -10
- package/dist/utils/errors.d.ts +20 -1
- package/dist/utils/errors.js +22 -0
- package/dist/utils/parseError.d.ts +4 -4
- package/dist/utils/parseError.js +30 -13
- package/dist/utils/utils.d.ts +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -15
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ContractCallQuoteRequest, ExtendedChain, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions,
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private configService;
|
|
5
|
+
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
6
|
+
import { Config, ConfigUpdate, RevokeTokenData } from './types';
|
|
7
|
+
export declare class LiFi extends RouteExecutionManager {
|
|
9
8
|
private chainsService;
|
|
10
9
|
constructor(configUpdate?: ConfigUpdate);
|
|
11
10
|
/**
|
|
@@ -50,13 +49,13 @@ export default class LIFI {
|
|
|
50
49
|
* @param {QuoteRequest} request - The configuration of the requested quote
|
|
51
50
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
52
51
|
*/
|
|
53
|
-
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<
|
|
52
|
+
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
54
53
|
/**
|
|
55
54
|
* Get a quote for a destination contract call
|
|
56
55
|
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
57
56
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
58
57
|
*/
|
|
59
|
-
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<
|
|
58
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
60
59
|
/**
|
|
61
60
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
62
61
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
@@ -83,73 +82,24 @@ export default class LIFI {
|
|
|
83
82
|
getChains: () => Promise<ExtendedChain[]>;
|
|
84
83
|
/**
|
|
85
84
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
86
|
-
* @param {RoutesRequest}
|
|
85
|
+
* @param {RoutesRequest} request - A description of the transfer.
|
|
87
86
|
* @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
|
|
88
87
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
89
88
|
*/
|
|
90
89
|
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
91
90
|
/**
|
|
92
91
|
* Get the transaction data for a single step of a route
|
|
93
|
-
* @param {
|
|
92
|
+
* @param {LifiStep} step - The step object.
|
|
94
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
95
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
96
95
|
*/
|
|
97
|
-
getStepTransaction: (step:
|
|
96
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
|
|
98
97
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {
|
|
101
|
-
* @
|
|
102
|
-
*/
|
|
103
|
-
stopExecution: (route: Route) => Route;
|
|
104
|
-
/**
|
|
105
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
106
|
-
* @param {Route} route - A route that is currently in execution.
|
|
107
|
-
* @deprecated use updateRouteExecution instead.
|
|
108
|
-
*/
|
|
109
|
-
moveExecutionToBackground: (route: Route) => void;
|
|
110
|
-
/**
|
|
111
|
-
* Updates route execution to background or foreground state.
|
|
112
|
-
* @param {Route} route - A route that is currently in execution.
|
|
113
|
-
* @param {boolean} settings - An object with execution settings.
|
|
114
|
-
*/
|
|
115
|
-
updateRouteExecution: (route: Route, settings: Pick<ExecutionSettings, 'executeInBackground'>) => void;
|
|
116
|
-
/**
|
|
117
|
-
* Execute a route.
|
|
118
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
119
|
-
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
120
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
121
|
-
* @return {Promise<Route>} The executed route.
|
|
122
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
123
|
-
*/
|
|
124
|
-
executeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
125
|
-
/**
|
|
126
|
-
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
127
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
128
|
-
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
129
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
130
|
-
* @return {Promise<Route>} The executed route.
|
|
131
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
132
|
-
*/
|
|
133
|
-
resumeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
134
|
-
private executeSteps;
|
|
135
|
-
/**
|
|
136
|
-
* Update the ExecutionSettings for an active route.
|
|
137
|
-
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
138
|
-
* @param {Route} route - The active route that gets the new execution settings.
|
|
139
|
-
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
140
|
-
*/
|
|
141
|
-
updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Get the list of active routes.
|
|
144
|
-
* @return {Route[]} A list of routes.
|
|
145
|
-
*/
|
|
146
|
-
getActiveRoutes: () => Route[];
|
|
147
|
-
/**
|
|
148
|
-
* Return the current route information for given route. The route has to be active.
|
|
149
|
-
* @param {Route} route - A route object.
|
|
150
|
-
* @return {Route} The updated route.
|
|
98
|
+
* Get gas recommendation for a certain chain
|
|
99
|
+
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
100
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
151
101
|
*/
|
|
152
|
-
|
|
102
|
+
getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
|
|
153
103
|
/**
|
|
154
104
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
155
105
|
* @param {string} walletAddress - A wallet address.
|
|
@@ -205,3 +155,9 @@ export default class LIFI {
|
|
|
205
155
|
*/
|
|
206
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
207
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get all the available connections for swap/bridging tokens
|
|
160
|
+
* @param connectionRequest ConnectionsRequest
|
|
161
|
+
* @returns ConnectionsResponse
|
|
162
|
+
*/
|
|
163
|
+
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|
package/dist/{Lifi.js → LiFi.js}
RENAMED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { approveToken, bulkGetTokenApproval, getTokenApproval, revokeTokenApproval, } from './allowance';
|
|
2
2
|
import * as balance from './balance';
|
|
3
3
|
import { getRpcProvider } from './connectors';
|
|
4
|
-
import {
|
|
5
|
-
import { StepExecutor } from './execution/StepExecutor';
|
|
4
|
+
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
6
5
|
import { checkPackageUpdates } from './helpers';
|
|
7
6
|
import ApiService from './services/ApiService';
|
|
8
7
|
import ChainsService from './services/ChainsService';
|
|
9
|
-
import ConfigService from './services/ConfigService';
|
|
10
8
|
import { isToken } from './typeguards';
|
|
11
9
|
import { ValidationError } from './utils/errors';
|
|
12
|
-
import { handlePreRestart } from './utils/preRestart';
|
|
13
10
|
import { name, version } from './version';
|
|
14
|
-
export
|
|
11
|
+
export class LiFi extends RouteExecutionManager {
|
|
15
12
|
constructor(configUpdate) {
|
|
16
|
-
|
|
13
|
+
super(configUpdate);
|
|
17
14
|
/**
|
|
18
15
|
* Get the current configuration of the SDK
|
|
19
16
|
* @return {Config} - The config object
|
|
@@ -113,7 +110,7 @@ export default class LIFI {
|
|
|
113
110
|
};
|
|
114
111
|
/**
|
|
115
112
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
116
|
-
* @param {RoutesRequest}
|
|
113
|
+
* @param {RoutesRequest} request - A description of the transfer.
|
|
117
114
|
* @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
|
|
118
115
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
119
116
|
*/
|
|
@@ -122,7 +119,7 @@ export default class LIFI {
|
|
|
122
119
|
};
|
|
123
120
|
/**
|
|
124
121
|
* Get the transaction data for a single step of a route
|
|
125
|
-
* @param {
|
|
122
|
+
* @param {LifiStep} step - The step object.
|
|
126
123
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
127
124
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
128
125
|
*/
|
|
@@ -130,206 +127,12 @@ export default class LIFI {
|
|
|
130
127
|
return ApiService.getStepTransaction(step, options);
|
|
131
128
|
};
|
|
132
129
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @param {
|
|
135
|
-
* @
|
|
136
|
-
*/
|
|
137
|
-
this.stopExecution = (route) => {
|
|
138
|
-
if (!this.activeRouteDictionary[route.id]) {
|
|
139
|
-
return route;
|
|
140
|
-
}
|
|
141
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
142
|
-
for (const executor of executionData.executors) {
|
|
143
|
-
executor.setInteraction({
|
|
144
|
-
allowInteraction: false,
|
|
145
|
-
allowUpdates: false,
|
|
146
|
-
stopExecution: true,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
delete this.activeRouteDictionary[route.id];
|
|
150
|
-
return route;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
154
|
-
* @param {Route} route - A route that is currently in execution.
|
|
155
|
-
* @deprecated use updateRouteExecution instead.
|
|
156
|
-
*/
|
|
157
|
-
this.moveExecutionToBackground = (route) => {
|
|
158
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
159
|
-
if (!executionData) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
for (const executor of executionData.executors) {
|
|
163
|
-
executor.setInteraction({ allowInteraction: false, allowUpdates: true });
|
|
164
|
-
}
|
|
165
|
-
executionData.settings = {
|
|
166
|
-
...executionData.settings,
|
|
167
|
-
executeInBackground: true,
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Updates route execution to background or foreground state.
|
|
172
|
-
* @param {Route} route - A route that is currently in execution.
|
|
173
|
-
* @param {boolean} settings - An object with execution settings.
|
|
174
|
-
*/
|
|
175
|
-
this.updateRouteExecution = (route, settings) => {
|
|
176
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
177
|
-
if (!executionData) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
for (const executor of executionData.executors) {
|
|
181
|
-
executor.setInteraction({
|
|
182
|
-
allowInteraction: !settings.executeInBackground,
|
|
183
|
-
allowUpdates: true,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
// Update active route settings so we know what the current state of execution is
|
|
187
|
-
executionData.settings = {
|
|
188
|
-
...executionData.settings,
|
|
189
|
-
...settings,
|
|
190
|
-
};
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Execute a route.
|
|
194
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
195
|
-
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
196
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
197
|
-
* @return {Promise<Route>} The executed route.
|
|
198
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
199
|
-
*/
|
|
200
|
-
this.executeRoute = async (signer, route, settings) => {
|
|
201
|
-
// Deep clone to prevent side effects
|
|
202
|
-
const clonedRoute = structuredClone(route);
|
|
203
|
-
// Check if route is already running
|
|
204
|
-
if (this.activeRouteDictionary[clonedRoute.id]) {
|
|
205
|
-
// TODO: maybe inform user why nothing happens?
|
|
206
|
-
return this.activeRouteDictionary[clonedRoute.id].executionPromise;
|
|
207
|
-
}
|
|
208
|
-
const executionPromise = this.executeSteps(signer, clonedRoute, settings);
|
|
209
|
-
this.activeRouteDictionary[clonedRoute.id] = {
|
|
210
|
-
...this.activeRouteDictionary[clonedRoute.id],
|
|
211
|
-
executionPromise,
|
|
212
|
-
};
|
|
213
|
-
return executionPromise;
|
|
214
|
-
};
|
|
215
|
-
/**
|
|
216
|
-
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
217
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
218
|
-
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
219
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
220
|
-
* @return {Promise<Route>} The executed route.
|
|
221
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
222
|
-
*/
|
|
223
|
-
this.resumeRoute = async (signer, route, settings) => {
|
|
224
|
-
// Deep clone to prevent side effects
|
|
225
|
-
const clonedRoute = structuredClone(route);
|
|
226
|
-
const { executionData, executionPromise } = this.activeRouteDictionary[clonedRoute.id];
|
|
227
|
-
if (executionData) {
|
|
228
|
-
const executionHalted = executionData.executors.some((executor) => executor.executionStopped);
|
|
229
|
-
if (!executionHalted) {
|
|
230
|
-
// Check if we want to resume route execution in the background
|
|
231
|
-
this.updateRouteExecution(route, {
|
|
232
|
-
executeInBackground: settings?.executeInBackground,
|
|
233
|
-
});
|
|
234
|
-
return executionPromise;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
handlePreRestart(clonedRoute);
|
|
238
|
-
const newExecutionPromise = this.executeSteps(signer, clonedRoute, settings);
|
|
239
|
-
this.activeRouteDictionary[clonedRoute.id] = {
|
|
240
|
-
...this.activeRouteDictionary[clonedRoute.id],
|
|
241
|
-
executionPromise: newExecutionPromise,
|
|
242
|
-
};
|
|
243
|
-
return newExecutionPromise;
|
|
244
|
-
};
|
|
245
|
-
this.executeSteps = async (signer, route, settings) => {
|
|
246
|
-
const config = this.configService.getConfig();
|
|
247
|
-
const updatedExecutionData = {
|
|
248
|
-
route,
|
|
249
|
-
executors: [],
|
|
250
|
-
settings: { ...config.defaultExecutionSettings, ...settings },
|
|
251
|
-
};
|
|
252
|
-
this.activeRouteDictionary[route.id].executionData = {
|
|
253
|
-
...updatedExecutionData,
|
|
254
|
-
};
|
|
255
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
256
|
-
const statusManager = new StatusManager(route, executionData.settings, (route) => {
|
|
257
|
-
if (this.activeRouteDictionary[route.id]) {
|
|
258
|
-
executionData.route = route;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
// Loop over steps and execute them
|
|
262
|
-
for (let index = 0; index < route.steps.length; index++) {
|
|
263
|
-
const { executionData } = this.activeRouteDictionary[route.id];
|
|
264
|
-
// Check if execution has stopped in the meantime
|
|
265
|
-
if (!executionData) {
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
const step = route.steps[index];
|
|
269
|
-
const previousStep = route.steps[index - 1];
|
|
270
|
-
// Check if the step is already done
|
|
271
|
-
//
|
|
272
|
-
if (step.execution?.status === 'DONE') {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
// Update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
|
|
276
|
-
if (previousStep?.execution?.toAmount) {
|
|
277
|
-
step.action.fromAmount = previousStep.execution.toAmount;
|
|
278
|
-
}
|
|
279
|
-
try {
|
|
280
|
-
const stepExecutor = new StepExecutor(statusManager, executionData.settings);
|
|
281
|
-
executionData.executors.push(stepExecutor);
|
|
282
|
-
// Check if we want to execute this step in the background
|
|
283
|
-
this.updateRouteExecution(route, executionData.settings);
|
|
284
|
-
const executedStep = await stepExecutor.executeStep(signer, step);
|
|
285
|
-
// We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
|
|
286
|
-
if (executedStep.execution?.status !== 'DONE') {
|
|
287
|
-
this.stopExecution(route);
|
|
288
|
-
}
|
|
289
|
-
// Execution stopped during the current step, we don't want to continue to the next step so we return already
|
|
290
|
-
if (stepExecutor.executionStopped) {
|
|
291
|
-
return route;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch (e) {
|
|
295
|
-
this.stopExecution(route);
|
|
296
|
-
throw e;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
// Clean up after the execution
|
|
300
|
-
delete this.activeRouteDictionary[route.id];
|
|
301
|
-
return route;
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Update the ExecutionSettings for an active route.
|
|
305
|
-
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
306
|
-
* @param {Route} route - The active route that gets the new execution settings.
|
|
307
|
-
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
308
|
-
*/
|
|
309
|
-
this.updateExecutionSettings = (settings, route) => {
|
|
310
|
-
if (!this.activeRouteDictionary[route.id]) {
|
|
311
|
-
throw new ValidationError("Can't set ExecutionSettings for the inactive route.");
|
|
312
|
-
}
|
|
313
|
-
const config = this.configService.getConfig();
|
|
314
|
-
this.activeRouteDictionary[route.id].executionData.settings = {
|
|
315
|
-
...config.defaultExecutionSettings,
|
|
316
|
-
...settings,
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
/**
|
|
320
|
-
* Get the list of active routes.
|
|
321
|
-
* @return {Route[]} A list of routes.
|
|
322
|
-
*/
|
|
323
|
-
this.getActiveRoutes = () => {
|
|
324
|
-
return Object.values(this.activeRouteDictionary).map((dict) => dict.executionData.route);
|
|
325
|
-
};
|
|
326
|
-
/**
|
|
327
|
-
* Return the current route information for given route. The route has to be active.
|
|
328
|
-
* @param {Route} route - A route object.
|
|
329
|
-
* @return {Route} The updated route.
|
|
130
|
+
* Get gas recommendation for a certain chain
|
|
131
|
+
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
132
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
330
133
|
*/
|
|
331
|
-
this.
|
|
332
|
-
return
|
|
134
|
+
this.getGasRecommendation = async (request, options) => {
|
|
135
|
+
return ApiService.getGasRecommendation(request, options);
|
|
333
136
|
};
|
|
334
137
|
/**
|
|
335
138
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
@@ -413,11 +216,6 @@ export default class LIFI {
|
|
|
413
216
|
this.revokeTokenApproval = (request) => {
|
|
414
217
|
return revokeTokenApproval(request);
|
|
415
218
|
};
|
|
416
|
-
this.configService = ConfigService.getInstance();
|
|
417
|
-
if (configUpdate) {
|
|
418
|
-
// Update API urls before we request chains
|
|
419
|
-
this.configService.updateConfig(configUpdate);
|
|
420
|
-
}
|
|
421
219
|
this.chainsService = ChainsService.getInstance();
|
|
422
220
|
this.chainsService.getChains().then((chains) => {
|
|
423
221
|
this.configService.updateChains(chains);
|
|
@@ -425,3 +223,12 @@ export default class LIFI {
|
|
|
425
223
|
checkPackageUpdates(name, version, configUpdate?.disableVersionCheck);
|
|
426
224
|
}
|
|
427
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Get all the available connections for swap/bridging tokens
|
|
228
|
+
* @param connectionRequest ConnectionsRequest
|
|
229
|
+
* @returns ConnectionsResponse
|
|
230
|
+
*/
|
|
231
|
+
export const getConnections = async (connectionRequest) => {
|
|
232
|
+
const connections = await ApiService.getAvailableConnections(connectionRequest);
|
|
233
|
+
return connections;
|
|
234
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
2
|
import { StatusManager } from '../execution/StatusManager';
|
|
3
|
-
import { Chain, InternalExecutionSettings,
|
|
4
|
-
export declare const checkAllowance: (signer: Signer, step:
|
|
3
|
+
import { Chain, InternalExecutionSettings, LifiStep } from '../types';
|
|
4
|
+
export declare const checkAllowance: (signer: Signer, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean) => Promise<void>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
1
|
import BigNumber from 'bignumber.js';
|
|
3
2
|
import { constants } from 'ethers';
|
|
4
3
|
import { getApproved, setApproval } from '../allowance/utils';
|
|
@@ -17,7 +16,22 @@ export const checkAllowance = async (signer, step, statusManager, settings, chai
|
|
|
17
16
|
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
18
17
|
}
|
|
19
18
|
else {
|
|
20
|
-
const
|
|
19
|
+
const approvalRequest = {
|
|
20
|
+
from: step.action.fromToken.address,
|
|
21
|
+
to: step.estimate.approvalAddress,
|
|
22
|
+
};
|
|
23
|
+
if (settings.updateTransactionRequest) {
|
|
24
|
+
const config = await settings.updateTransactionRequest(approvalRequest);
|
|
25
|
+
approvalRequest.gasLimit = config.gasLimit;
|
|
26
|
+
approvalRequest.gasPrice = config.gasPrice;
|
|
27
|
+
}
|
|
28
|
+
if (!approvalRequest.from) {
|
|
29
|
+
throw new Error('Missing Signer address');
|
|
30
|
+
}
|
|
31
|
+
if (!approvalRequest.to) {
|
|
32
|
+
throw new Error('Missing ERC20 contract address');
|
|
33
|
+
}
|
|
34
|
+
const approved = await getApproved(signer, approvalRequest.from, approvalRequest.to, approvalRequest);
|
|
21
35
|
if (new BigNumber(step.action.fromAmount).gt(approved)) {
|
|
22
36
|
if (!allowUserInteraction) {
|
|
23
37
|
return;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
2
|
import { ChainId, Token } from '@lifi/types';
|
|
2
3
|
import BigNumber from 'bignumber.js';
|
|
3
4
|
import { ContractTransaction, Signer } from 'ethers';
|
|
4
5
|
import { RevokeTokenData } from '../types';
|
|
5
|
-
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
|
|
6
|
+
export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string, transactionRequest?: TransactionRequest) => Promise<BigNumber>;
|
|
6
7
|
export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string) => Promise<ContractTransaction>;
|
|
7
8
|
export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
|
|
8
9
|
token: Token;
|
package/dist/allowance/utils.js
CHANGED
|
@@ -4,11 +4,16 @@ import ChainsService from '../services/ChainsService';
|
|
|
4
4
|
import { ERC20_ABI } from '../types';
|
|
5
5
|
import { ServerError } from '../utils/errors';
|
|
6
6
|
import { fetchDataUsingMulticall } from '../utils/multicall';
|
|
7
|
-
export const getApproved = async (signer, tokenAddress, contractAddress) => {
|
|
7
|
+
export const getApproved = async (signer, tokenAddress, contractAddress, transactionRequest) => {
|
|
8
8
|
const signerAddress = await signer.getAddress();
|
|
9
9
|
const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
|
|
10
10
|
try {
|
|
11
|
-
const approved = await erc20.allowance(signerAddress, contractAddress
|
|
11
|
+
const approved = await erc20.allowance(signerAddress, contractAddress, {
|
|
12
|
+
gasLimit: transactionRequest?.gasLimit,
|
|
13
|
+
gasPrice: transactionRequest?.gasPrice,
|
|
14
|
+
maxFeePerGas: transactionRequest?.maxFeePerGas,
|
|
15
|
+
maxPriorityFeePerGas: transactionRequest?.maxPriorityFeePerGas,
|
|
16
|
+
});
|
|
12
17
|
return new BigNumber(approved.toString());
|
|
13
18
|
}
|
|
14
19
|
catch (e) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
|
-
import {
|
|
3
|
-
export declare const checkBalance: (signer: ethers.Signer, step:
|
|
2
|
+
import { LifiStep } from '..';
|
|
3
|
+
export declare const checkBalance: (signer: ethers.Signer, step: LifiStep, depth?: number) => Promise<void>;
|
package/dist/balance/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './checkBalance';
|
|
2
2
|
export * from './getTokenBalance';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").
|
|
4
|
+
checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
|
|
5
5
|
getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
|
|
6
6
|
getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
|
|
7
7
|
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
-
import { ChainId, ChainKey, ContractCallQuoteRequest, ExtendedChain, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions,
|
|
2
|
+
import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
3
|
import { Signer } from 'ethers';
|
|
4
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private configService;
|
|
5
|
+
import { RouteExecutionManager } from './execution/RouteExecutionManager';
|
|
6
|
+
import { Config, ConfigUpdate, RevokeTokenData } from './types';
|
|
7
|
+
export declare class LiFi extends RouteExecutionManager {
|
|
9
8
|
private chainsService;
|
|
10
9
|
constructor(configUpdate?: ConfigUpdate);
|
|
11
10
|
/**
|
|
@@ -50,13 +49,13 @@ export default class LIFI {
|
|
|
50
49
|
* @param {QuoteRequest} request - The configuration of the requested quote
|
|
51
50
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
52
51
|
*/
|
|
53
|
-
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<
|
|
52
|
+
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
54
53
|
/**
|
|
55
54
|
* Get a quote for a destination contract call
|
|
56
55
|
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
57
56
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
58
57
|
*/
|
|
59
|
-
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<
|
|
58
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
|
|
60
59
|
/**
|
|
61
60
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
62
61
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
@@ -83,73 +82,24 @@ export default class LIFI {
|
|
|
83
82
|
getChains: () => Promise<ExtendedChain[]>;
|
|
84
83
|
/**
|
|
85
84
|
* Get a set of routes for a request that describes a transfer of tokens.
|
|
86
|
-
* @param {RoutesRequest}
|
|
85
|
+
* @param {RoutesRequest} request - A description of the transfer.
|
|
87
86
|
* @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
|
|
88
87
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
89
88
|
*/
|
|
90
89
|
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
91
90
|
/**
|
|
92
91
|
* Get the transaction data for a single step of a route
|
|
93
|
-
* @param {
|
|
92
|
+
* @param {LifiStep} step - The step object.
|
|
94
93
|
* @return {Promise<Step>} The step populated with the transaction data.
|
|
95
94
|
* @throws {LifiError} Throws a LifiError if request fails.
|
|
96
95
|
*/
|
|
97
|
-
getStepTransaction: (step:
|
|
96
|
+
getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
|
|
98
97
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {
|
|
101
|
-
* @
|
|
102
|
-
*/
|
|
103
|
-
stopExecution: (route: Route) => Route;
|
|
104
|
-
/**
|
|
105
|
-
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
106
|
-
* @param {Route} route - A route that is currently in execution.
|
|
107
|
-
* @deprecated use updateRouteExecution instead.
|
|
108
|
-
*/
|
|
109
|
-
moveExecutionToBackground: (route: Route) => void;
|
|
110
|
-
/**
|
|
111
|
-
* Updates route execution to background or foreground state.
|
|
112
|
-
* @param {Route} route - A route that is currently in execution.
|
|
113
|
-
* @param {boolean} settings - An object with execution settings.
|
|
114
|
-
*/
|
|
115
|
-
updateRouteExecution: (route: Route, settings: Pick<ExecutionSettings, 'executeInBackground'>) => void;
|
|
116
|
-
/**
|
|
117
|
-
* Execute a route.
|
|
118
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
119
|
-
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
120
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
121
|
-
* @return {Promise<Route>} The executed route.
|
|
122
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
123
|
-
*/
|
|
124
|
-
executeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
125
|
-
/**
|
|
126
|
-
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
127
|
-
* @param {Signer} signer - The signer required to send the transactions.
|
|
128
|
-
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
129
|
-
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
130
|
-
* @return {Promise<Route>} The executed route.
|
|
131
|
-
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
132
|
-
*/
|
|
133
|
-
resumeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
134
|
-
private executeSteps;
|
|
135
|
-
/**
|
|
136
|
-
* Update the ExecutionSettings for an active route.
|
|
137
|
-
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
138
|
-
* @param {Route} route - The active route that gets the new execution settings.
|
|
139
|
-
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
140
|
-
*/
|
|
141
|
-
updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Get the list of active routes.
|
|
144
|
-
* @return {Route[]} A list of routes.
|
|
145
|
-
*/
|
|
146
|
-
getActiveRoutes: () => Route[];
|
|
147
|
-
/**
|
|
148
|
-
* Return the current route information for given route. The route has to be active.
|
|
149
|
-
* @param {Route} route - A route object.
|
|
150
|
-
* @return {Route} The updated route.
|
|
98
|
+
* Get gas recommendation for a certain chain
|
|
99
|
+
* @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
|
|
100
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
151
101
|
*/
|
|
152
|
-
|
|
102
|
+
getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
|
|
153
103
|
/**
|
|
154
104
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
155
105
|
* @param {string} walletAddress - A wallet address.
|
|
@@ -205,3 +155,9 @@ export default class LIFI {
|
|
|
205
155
|
*/
|
|
206
156
|
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
207
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get all the available connections for swap/bridging tokens
|
|
160
|
+
* @param connectionRequest ConnectionsRequest
|
|
161
|
+
* @returns ConnectionsResponse
|
|
162
|
+
*/
|
|
163
|
+
export declare const getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
|