@lifi/sdk 1.7.1 → 2.0.0-beta.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 (76) hide show
  1. package/dist/Lifi.js +97 -85
  2. package/dist/allowance/checkAllowance.js +12 -21
  3. package/dist/allowance/tokenApproval.js +20 -29
  4. package/dist/allowance/utils.js +12 -24
  5. package/dist/balance/checkBalance.js +5 -14
  6. package/dist/balance/getTokenBalance.js +12 -21
  7. package/dist/balance/index.d.ts +11 -0
  8. package/dist/balance/index.js +8 -0
  9. package/dist/balance/utils.d.ts +1 -0
  10. package/dist/balance/utils.js +36 -38
  11. package/dist/cjs/Lifi.js +97 -85
  12. package/dist/cjs/allowance/checkAllowance.js +12 -21
  13. package/dist/cjs/allowance/tokenApproval.js +20 -29
  14. package/dist/cjs/allowance/utils.js +12 -24
  15. package/dist/cjs/balance/checkBalance.js +5 -14
  16. package/dist/cjs/balance/getTokenBalance.js +12 -21
  17. package/dist/cjs/balance/index.d.ts +11 -0
  18. package/dist/cjs/balance/index.js +8 -0
  19. package/dist/cjs/balance/utils.d.ts +1 -0
  20. package/dist/cjs/balance/utils.js +39 -39
  21. package/dist/cjs/connectors.js +17 -25
  22. package/dist/cjs/execution/ExecutionManager.js +27 -33
  23. package/dist/cjs/execution/StatusManager.js +13 -13
  24. package/dist/cjs/execution/StepExecutor.js +8 -14
  25. package/dist/cjs/execution/stepComparison.js +4 -14
  26. package/dist/cjs/execution/switchChain.js +5 -14
  27. package/dist/cjs/execution/utils.js +43 -50
  28. package/dist/cjs/helpers.d.ts +12 -1
  29. package/dist/cjs/helpers.js +68 -19
  30. package/dist/cjs/services/ApiService.d.ts +10 -9
  31. package/dist/cjs/services/ApiService.js +190 -152
  32. package/dist/cjs/services/ApiService.unit.handlers.d.ts +1 -0
  33. package/dist/cjs/services/ApiService.unit.handlers.js +50 -0
  34. package/dist/cjs/services/ChainsService.js +16 -31
  35. package/dist/cjs/services/ConfigService.js +6 -16
  36. package/dist/cjs/typeguards.js +1 -1
  37. package/dist/cjs/types/internal.types.d.ts +4 -1
  38. package/dist/cjs/utils/errors.d.ts +5 -0
  39. package/dist/cjs/utils/errors.js +14 -1
  40. package/dist/cjs/utils/multicall.js +6 -15
  41. package/dist/cjs/utils/parseError.d.ts +2 -2
  42. package/dist/cjs/utils/parseError.js +36 -38
  43. package/dist/cjs/utils/preRestart.js +5 -7
  44. package/dist/cjs/utils/utils.d.ts +0 -1
  45. package/dist/cjs/utils/utils.js +21 -28
  46. package/dist/cjs/version.d.ts +1 -1
  47. package/dist/cjs/version.js +1 -1
  48. package/dist/connectors.js +15 -23
  49. package/dist/execution/ExecutionManager.js +27 -33
  50. package/dist/execution/StatusManager.js +11 -11
  51. package/dist/execution/StepExecutor.js +8 -14
  52. package/dist/execution/stepComparison.js +4 -14
  53. package/dist/execution/switchChain.js +5 -14
  54. package/dist/execution/utils.js +43 -50
  55. package/dist/helpers.d.ts +12 -1
  56. package/dist/helpers.js +65 -18
  57. package/dist/services/ApiService.d.ts +10 -9
  58. package/dist/services/ApiService.js +190 -152
  59. package/dist/services/ApiService.unit.handlers.d.ts +1 -0
  60. package/dist/services/ApiService.unit.handlers.js +44 -0
  61. package/dist/services/ChainsService.js +16 -31
  62. package/dist/services/ConfigService.js +6 -16
  63. package/dist/typeguards.js +1 -1
  64. package/dist/types/internal.types.d.ts +4 -1
  65. package/dist/utils/errors.d.ts +5 -0
  66. package/dist/utils/errors.js +12 -0
  67. package/dist/utils/multicall.js +6 -15
  68. package/dist/utils/parseError.d.ts +2 -2
  69. package/dist/utils/parseError.js +36 -38
  70. package/dist/utils/preRestart.js +5 -7
  71. package/dist/utils/utils.d.ts +0 -1
  72. package/dist/utils/utils.js +20 -26
  73. package/dist/version.d.ts +1 -1
  74. package/dist/version.js +1 -1
  75. package/package.json +23 -25
  76. package/CHANGELOG.md +0 -490
@@ -1,64 +1,61 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import axios from 'axios';
1
+ import { request } from '../helpers';
11
2
  import { isRoutesRequest, isStep } from '../typeguards';
12
3
  import { ValidationError } from '../utils/errors';
13
4
  import { parseBackendError } from '../utils/parseError';
14
5
  import ConfigService from './ConfigService';
15
- const getPossibilities = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
16
- if (!request) {
17
- request = {};
6
+ const getPossibilities = async (requestConfig, options) => {
7
+ if (!requestConfig) {
8
+ requestConfig = {};
18
9
  }
19
- const configService = ConfigService.getInstance();
20
- const config = configService.getConfig();
10
+ const config = ConfigService.getInstance().getConfig();
21
11
  // apply defaults
22
- request.bridges = request.bridges || config.defaultRouteOptions.bridges;
23
- request.exchanges = request.exchanges || config.defaultRouteOptions.exchanges;
12
+ if (requestConfig.bridges || config.defaultRouteOptions.bridges) {
13
+ requestConfig.bridges =
14
+ requestConfig.bridges || config.defaultRouteOptions.bridges;
15
+ }
16
+ if (requestConfig.exchanges || config.defaultRouteOptions.exchanges) {
17
+ requestConfig.exchanges =
18
+ requestConfig.exchanges || config.defaultRouteOptions.exchanges;
19
+ }
24
20
  // send request
25
21
  try {
26
- const result = yield axios.post(config.apiUrl + 'advanced/possibilities', request, {
27
- signal: options === null || options === void 0 ? void 0 : options.signal,
22
+ const response = await request(`${config.apiUrl}/advanced/possibilities`, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ },
27
+ body: JSON.stringify(requestConfig),
28
+ signal: options?.signal,
28
29
  });
29
- return result.data;
30
+ return response;
30
31
  }
31
32
  catch (e) {
32
- throw parseBackendError(e);
33
+ throw await parseBackendError(e);
33
34
  }
34
- });
35
- const getToken = (chain, token, options) => __awaiter(void 0, void 0, void 0, function* () {
35
+ };
36
+ const getToken = async (chain, token, options) => {
36
37
  if (!chain) {
37
38
  throw new ValidationError('Required parameter "chain" is missing.');
38
39
  }
39
40
  if (!token) {
40
41
  throw new ValidationError('Required parameter "token" is missing.');
41
42
  }
42
- const configService = ConfigService.getInstance();
43
- const config = configService.getConfig();
43
+ const config = ConfigService.getInstance().getConfig();
44
44
  try {
45
- const result = yield axios.get(config.apiUrl + 'token', {
46
- params: {
47
- chain,
48
- token,
49
- },
50
- signal: options === null || options === void 0 ? void 0 : options.signal,
45
+ const response = await request(`${config.apiUrl}/token?${new URLSearchParams({
46
+ chain,
47
+ token,
48
+ })}`, {
49
+ signal: options?.signal,
51
50
  });
52
- return result.data;
51
+ return response;
53
52
  }
54
53
  catch (e) {
55
- throw parseBackendError(e);
54
+ throw await parseBackendError(e);
56
55
  }
57
- });
58
- const getQuote = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
59
- var _a, _b, _c, _d, _e, _f;
60
- const configService = ConfigService.getInstance();
61
- const config = configService.getConfig();
56
+ };
57
+ const getQuote = async (requestConfig, options) => {
58
+ const config = ConfigService.getInstance().getConfig();
62
59
  // validation
63
60
  const requiredParameters = [
64
61
  'fromChain',
@@ -69,44 +66,46 @@ const getQuote = (request, options) => __awaiter(void 0, void 0, void 0, functio
69
66
  'toToken',
70
67
  ];
71
68
  requiredParameters.forEach((requiredParameter) => {
72
- if (!request[requiredParameter]) {
69
+ if (!requestConfig[requiredParameter]) {
73
70
  throw new ValidationError(`Required parameter "${requiredParameter}" is missing.`);
74
71
  }
75
72
  });
76
73
  // apply defaults
77
- request.order = request.order || config.defaultRouteOptions.order;
78
- request.slippage = request.slippage || config.defaultRouteOptions.slippage;
79
- request.integrator =
80
- request.integrator || config.defaultRouteOptions.integrator;
81
- request.referrer = request.referrer || config.defaultRouteOptions.referrer;
82
- request.fee = request.fee || config.defaultRouteOptions.fee;
83
- request.allowBridges =
84
- request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
85
- request.denyBridges =
86
- request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
87
- request.preferBridges =
88
- request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
89
- request.allowExchanges =
90
- request.allowExchanges || ((_d = config.defaultRouteOptions.exchanges) === null || _d === void 0 ? void 0 : _d.allow);
91
- request.denyExchanges =
92
- request.denyExchanges || ((_e = config.defaultRouteOptions.exchanges) === null || _e === void 0 ? void 0 : _e.deny);
93
- request.preferExchanges =
94
- request.preferExchanges || ((_f = config.defaultRouteOptions.exchanges) === null || _f === void 0 ? void 0 : _f.prefer);
74
+ requestConfig.order = requestConfig.order || config.defaultRouteOptions.order;
75
+ requestConfig.slippage =
76
+ requestConfig.slippage || config.defaultRouteOptions.slippage;
77
+ requestConfig.integrator =
78
+ requestConfig.integrator || config.defaultRouteOptions.integrator;
79
+ requestConfig.referrer =
80
+ requestConfig.referrer || config.defaultRouteOptions.referrer;
81
+ requestConfig.fee = requestConfig.fee || config.defaultRouteOptions.fee;
82
+ requestConfig.allowBridges =
83
+ requestConfig.allowBridges || config.defaultRouteOptions.bridges?.allow;
84
+ requestConfig.denyBridges =
85
+ requestConfig.denyBridges || config.defaultRouteOptions.bridges?.deny;
86
+ requestConfig.preferBridges =
87
+ requestConfig.preferBridges || config.defaultRouteOptions.bridges?.prefer;
88
+ requestConfig.allowExchanges =
89
+ requestConfig.allowExchanges || config.defaultRouteOptions.exchanges?.allow;
90
+ requestConfig.denyExchanges =
91
+ requestConfig.denyExchanges || config.defaultRouteOptions.exchanges?.deny;
92
+ requestConfig.preferExchanges =
93
+ requestConfig.preferExchanges ||
94
+ config.defaultRouteOptions.exchanges?.prefer;
95
+ Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
96
+ delete requestConfig[key]);
95
97
  try {
96
- const result = yield axios.get(config.apiUrl + 'quote', {
97
- params: request,
98
- signal: options === null || options === void 0 ? void 0 : options.signal,
98
+ const response = await request(`${config.apiUrl}/quote?${new URLSearchParams(requestConfig)}`, {
99
+ signal: options?.signal,
99
100
  });
100
- return result.data;
101
+ return response;
101
102
  }
102
103
  catch (e) {
103
- throw parseBackendError(e);
104
+ throw await parseBackendError(e);
104
105
  }
105
- });
106
- const getContractCallQuote = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
107
- var _g, _h, _j, _k, _l, _m;
108
- const configService = ConfigService.getInstance();
109
- const config = configService.getConfig();
106
+ };
107
+ const getContractCallQuote = async (requestConfig, options) => {
108
+ const config = ConfigService.getInstance().getConfig();
110
109
  // validation
111
110
  const requiredParameters = [
112
111
  'fromChain',
@@ -120,41 +119,49 @@ const getContractCallQuote = (request, options) => __awaiter(void 0, void 0, voi
120
119
  'toContractGasLimit',
121
120
  ];
122
121
  requiredParameters.forEach((requiredParameter) => {
123
- if (!request[requiredParameter]) {
122
+ if (!requestConfig[requiredParameter]) {
124
123
  throw new ValidationError(`Required parameter "${requiredParameter}" is missing.`);
125
124
  }
126
125
  });
127
126
  // apply defaults
128
127
  // option.order is not used in this endpoint
129
- request.slippage = request.slippage || config.defaultRouteOptions.slippage;
130
- request.integrator =
131
- request.integrator || config.defaultRouteOptions.integrator;
132
- request.referrer = request.referrer || config.defaultRouteOptions.referrer;
133
- request.fee = request.fee || config.defaultRouteOptions.fee;
134
- request.allowBridges =
135
- request.allowBridges || ((_g = config.defaultRouteOptions.bridges) === null || _g === void 0 ? void 0 : _g.allow);
136
- request.denyBridges =
137
- request.denyBridges || ((_h = config.defaultRouteOptions.bridges) === null || _h === void 0 ? void 0 : _h.deny);
138
- request.preferBridges =
139
- request.preferBridges || ((_j = config.defaultRouteOptions.bridges) === null || _j === void 0 ? void 0 : _j.prefer);
140
- request.allowExchanges =
141
- request.allowExchanges || ((_k = config.defaultRouteOptions.exchanges) === null || _k === void 0 ? void 0 : _k.allow);
142
- request.denyExchanges =
143
- request.denyExchanges || ((_l = config.defaultRouteOptions.exchanges) === null || _l === void 0 ? void 0 : _l.deny);
144
- request.preferExchanges =
145
- request.preferExchanges || ((_m = config.defaultRouteOptions.exchanges) === null || _m === void 0 ? void 0 : _m.prefer);
128
+ requestConfig.slippage =
129
+ requestConfig.slippage || config.defaultRouteOptions.slippage;
130
+ requestConfig.integrator =
131
+ requestConfig.integrator || config.defaultRouteOptions.integrator;
132
+ requestConfig.referrer =
133
+ requestConfig.referrer || config.defaultRouteOptions.referrer;
134
+ requestConfig.fee = requestConfig.fee || config.defaultRouteOptions.fee;
135
+ requestConfig.allowBridges =
136
+ requestConfig.allowBridges || config.defaultRouteOptions.bridges?.allow;
137
+ requestConfig.denyBridges =
138
+ requestConfig.denyBridges || config.defaultRouteOptions.bridges?.deny;
139
+ requestConfig.preferBridges =
140
+ requestConfig.preferBridges || config.defaultRouteOptions.bridges?.prefer;
141
+ requestConfig.allowExchanges =
142
+ requestConfig.allowExchanges || config.defaultRouteOptions.exchanges?.allow;
143
+ requestConfig.denyExchanges =
144
+ requestConfig.denyExchanges || config.defaultRouteOptions.exchanges?.deny;
145
+ requestConfig.preferExchanges =
146
+ requestConfig.preferExchanges ||
147
+ config.defaultRouteOptions.exchanges?.prefer;
146
148
  // send request
147
149
  try {
148
- const result = yield axios.post(config.apiUrl + 'quote/contractCall', request, {
149
- signal: options === null || options === void 0 ? void 0 : options.signal,
150
+ const response = await request(`${config.apiUrl}/quote/contractCall`, {
151
+ method: 'POST',
152
+ headers: {
153
+ 'Content-Type': 'application/json',
154
+ },
155
+ body: JSON.stringify(requestConfig),
156
+ signal: options?.signal,
150
157
  });
151
- return result.data;
158
+ return response;
152
159
  }
153
160
  catch (e) {
154
- throw parseBackendError(e);
161
+ throw await parseBackendError(e);
155
162
  }
156
- });
157
- const getStatus = ({ bridge, fromChain, toChain, txHash }, options) => __awaiter(void 0, void 0, void 0, function* () {
163
+ };
164
+ const getStatus = async ({ bridge, fromChain, toChain, txHash }, options) => {
158
165
  if (fromChain !== toChain && !bridge) {
159
166
  throw new ValidationError('Parameter "bridge" is required for cross chain transfers.');
160
167
  }
@@ -167,101 +174,132 @@ const getStatus = ({ bridge, fromChain, toChain, txHash }, options) => __awaiter
167
174
  if (!txHash) {
168
175
  throw new ValidationError('Required parameter "txHash" is missing.');
169
176
  }
170
- const configService = ConfigService.getInstance();
171
- const config = configService.getConfig();
177
+ const config = ConfigService.getInstance().getConfig();
172
178
  try {
173
- const result = yield axios.get(config.apiUrl + 'status', {
174
- params: {
175
- bridge,
176
- fromChain,
177
- toChain,
178
- txHash,
179
- },
180
- signal: options === null || options === void 0 ? void 0 : options.signal,
179
+ const response = await request(`${config.apiUrl}/status?${new URLSearchParams({
180
+ bridge,
181
+ fromChain,
182
+ toChain,
183
+ txHash,
184
+ })}`, {
185
+ signal: options?.signal,
181
186
  });
182
- return result.data;
187
+ return response;
183
188
  }
184
189
  catch (e) {
185
- throw parseBackendError(e);
190
+ throw await parseBackendError(e);
186
191
  }
187
- });
188
- const getChains = (options) => __awaiter(void 0, void 0, void 0, function* () {
189
- const configService = ConfigService.getInstance();
190
- const config = configService.getConfig();
192
+ };
193
+ const getChains = async (options) => {
194
+ const config = ConfigService.getInstance().getConfig();
191
195
  try {
192
- const result = yield axios.get(config.apiUrl + 'chains', {
193
- signal: options === null || options === void 0 ? void 0 : options.signal,
196
+ const response = await request(`${config.apiUrl}/chains`, {
197
+ signal: options?.signal,
194
198
  });
195
- return result.data.chains;
199
+ return response.chains;
196
200
  }
197
201
  catch (e) {
198
- throw parseBackendError(e);
202
+ throw await parseBackendError(e);
199
203
  }
200
- });
201
- const getRoutes = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
202
- if (!isRoutesRequest(request)) {
204
+ };
205
+ const getRoutes = async (requestConfig, options) => {
206
+ if (!isRoutesRequest(requestConfig)) {
203
207
  throw new ValidationError('Invalid routes request.');
204
208
  }
205
- const configService = ConfigService.getInstance();
206
- const config = configService.getConfig();
209
+ const config = ConfigService.getInstance().getConfig();
207
210
  // apply defaults
208
- request.options = Object.assign(Object.assign({}, config.defaultRouteOptions), request.options);
211
+ requestConfig.options = {
212
+ ...config.defaultRouteOptions,
213
+ ...requestConfig.options,
214
+ };
209
215
  // send request
210
216
  try {
211
- const result = yield axios.post(config.apiUrl + 'advanced/routes', request, {
212
- signal: options === null || options === void 0 ? void 0 : options.signal,
217
+ const response = await request(`${config.apiUrl}/advanced/routes`, {
218
+ method: 'POST',
219
+ headers: {
220
+ 'Content-Type': 'application/json',
221
+ },
222
+ body: JSON.stringify(requestConfig),
223
+ signal: options?.signal,
213
224
  });
214
- return result.data;
225
+ return response;
215
226
  }
216
227
  catch (e) {
217
- throw parseBackendError(e);
228
+ throw await parseBackendError(e);
218
229
  }
219
- });
220
- const getStepTransaction = (step, options) => __awaiter(void 0, void 0, void 0, function* () {
230
+ };
231
+ const getStepTransaction = async (step, options) => {
221
232
  if (!isStep(step)) {
222
233
  // While the validation fails for some users we should not enforce it
223
234
  // eslint-disable-next-line no-console
224
235
  console.warn('SDK Validation: Invalid Step', step);
225
236
  }
226
- const configService = ConfigService.getInstance();
227
- const config = configService.getConfig();
237
+ const config = ConfigService.getInstance().getConfig();
228
238
  try {
229
- const result = yield axios.post(config.apiUrl + 'advanced/stepTransaction', step, {
230
- signal: options === null || options === void 0 ? void 0 : options.signal,
239
+ const response = await request(`${config.apiUrl}/advanced/stepTransaction`, {
240
+ method: 'POST',
241
+ headers: {
242
+ 'Content-Type': 'application/json',
243
+ },
244
+ body: JSON.stringify(step),
245
+ signal: options?.signal,
231
246
  });
232
- return result.data;
247
+ return response;
233
248
  }
234
249
  catch (e) {
235
- throw parseBackendError(e);
236
- }
237
- });
238
- const getTools = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
239
- const configService = ConfigService.getInstance();
240
- const config = configService.getConfig();
241
- const r = yield axios.get(config.apiUrl + 'tools', {
242
- params: request,
243
- signal: options === null || options === void 0 ? void 0 : options.signal,
250
+ throw await parseBackendError(e);
251
+ }
252
+ };
253
+ const getTools = async (requestConfig, options) => {
254
+ const config = ConfigService.getInstance().getConfig();
255
+ if (requestConfig) {
256
+ Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
257
+ delete requestConfig[key]);
258
+ }
259
+ const response = await request(`${config.apiUrl}/tools?${new URLSearchParams(requestConfig)}`, {
260
+ signal: options?.signal,
244
261
  });
245
- return r.data;
246
- });
247
- const getTokens = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
248
- const configService = ConfigService.getInstance();
249
- const config = configService.getConfig();
250
- const r = yield axios.get(config.apiUrl + 'tokens', {
251
- params: request,
252
- signal: options === null || options === void 0 ? void 0 : options.signal,
262
+ return response;
263
+ };
264
+ const getTokens = async (requestConfig, options) => {
265
+ const config = ConfigService.getInstance().getConfig();
266
+ if (requestConfig) {
267
+ Object.keys(requestConfig).forEach((key) => !requestConfig[key] &&
268
+ delete requestConfig[key]);
269
+ }
270
+ const response = await request(`${config.apiUrl}/tokens?${new URLSearchParams(requestConfig)}`, {
271
+ signal: options?.signal,
253
272
  });
254
- return r.data;
255
- });
273
+ return response;
274
+ };
275
+ const getGasRecommendation = async ({ chainId, fromChain, fromToken }, options) => {
276
+ const config = ConfigService.getInstance().getConfig();
277
+ if (!chainId) {
278
+ throw new ValidationError('Required parameter "chainId" is missing.');
279
+ }
280
+ try {
281
+ const response = await request(`${config.apiUrl}/gas/suggestion/${chainId}?${new URLSearchParams({
282
+ fromChain,
283
+ fromToken,
284
+ })}`, {
285
+ signal: options?.signal,
286
+ });
287
+ return response;
288
+ }
289
+ catch (e) {
290
+ throw await parseBackendError(e);
291
+ }
292
+ };
256
293
  export default {
294
+ getChains,
295
+ getContractCallQuote,
296
+ getGasRecommendation,
257
297
  getPossibilities,
258
- getToken,
259
298
  getQuote,
260
- getContractCallQuote,
261
- getStatus,
262
- getChains,
263
299
  getRoutes,
300
+ getStatus,
264
301
  getStepTransaction,
265
- getTools,
302
+ getToken,
266
303
  getTokens,
304
+ getTools,
267
305
  };
@@ -0,0 +1 @@
1
+ export declare const handlers: import("msw").RestHandler<import("msw/lib/glossary-de6278a9").M<import("msw/lib/glossary-de6278a9").h>>[];
@@ -0,0 +1,44 @@
1
+ import { ChainId, CoinKey, findDefaultToken } from '@lifi/types';
2
+ import { rest } from 'msw';
3
+ import ConfigService from './ConfigService';
4
+ const config = ConfigService.getInstance().getConfig();
5
+ export const handlers = [
6
+ rest.post(`${config.apiUrl}/advanced/routes`, async (request, response, context) => {
7
+ const data = await request.json();
8
+ if (isNaN(parseFloat(data.fromAmount))) {
9
+ return response(context.status(500), context.json({ message: `Oops` }));
10
+ }
11
+ return response(context.json({}));
12
+ }),
13
+ rest.post(`${config.apiUrl}/advanced/possibilities`, async (request, response, context) => {
14
+ return response(context.json({}));
15
+ }),
16
+ rest.get(`${config.apiUrl}/token`, async (request, response, context) => {
17
+ return response(context.json({}));
18
+ }),
19
+ rest.get(`${config.apiUrl}/quote`, async (request, response, context) => {
20
+ return response(context.json({}));
21
+ }),
22
+ rest.get(`${config.apiUrl}/status`, async (request, response, context) => {
23
+ return response(context.json({}));
24
+ }),
25
+ rest.get(`${config.apiUrl}/chains`, async (request, response, context) => {
26
+ return response(context.json({ chains: [{ id: 1 }] }));
27
+ }),
28
+ rest.get(`${config.apiUrl}/tools`, async (request, response, context) => {
29
+ return response(context.json({ bridges: [], exchanges: [] }));
30
+ }),
31
+ rest.get(`${config.apiUrl}/tokens`, async (request, response, context) => {
32
+ return response(context.json({
33
+ tokens: {
34
+ [ChainId.ETH]: [findDefaultToken(CoinKey.ETH, ChainId.ETH)],
35
+ },
36
+ }));
37
+ }),
38
+ rest.post(`${config.apiUrl}/advanced/stepTransaction`, async (request, response, context) => {
39
+ return response(context.json({}));
40
+ }),
41
+ rest.get(`${config.apiUrl}/gas/suggestion/${ChainId.OPT}`, async (request, response, context) => {
42
+ return response(context.json({}));
43
+ }),
44
+ ];
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { ValidationError } from '../utils/errors';
11
2
  import ApiService from './ApiService';
12
3
  export default class ChainsService {
@@ -14,10 +5,8 @@ export default class ChainsService {
14
5
  this.chains = [];
15
6
  this.loadingPromise = this.loadAvailableChains();
16
7
  }
17
- loadAvailableChains() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- this.chains = yield ApiService.getChains();
20
- });
8
+ async loadAvailableChains() {
9
+ this.chains = await ApiService.getChains();
21
10
  }
22
11
  static getInstance() {
23
12
  if (!this.instance) {
@@ -25,24 +14,20 @@ export default class ChainsService {
25
14
  }
26
15
  return this.instance;
27
16
  }
28
- getChainById(chainId) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- if (this.loadingPromise) {
31
- yield this.loadingPromise;
32
- }
33
- const chain = this.chains.find((chain) => chain.id === chainId);
34
- if (!chain) {
35
- throw new ValidationError(`Unknown chainId passed: ${chainId}.`);
36
- }
37
- return chain;
38
- });
17
+ async getChainById(chainId) {
18
+ if (this.loadingPromise) {
19
+ await this.loadingPromise;
20
+ }
21
+ const chain = this.chains.find((chain) => chain.id === chainId);
22
+ if (!chain) {
23
+ throw new ValidationError(`Unknown chainId passed: ${chainId}.`);
24
+ }
25
+ return chain;
39
26
  }
40
- getChains() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (this.loadingPromise) {
43
- yield this.loadingPromise;
44
- }
45
- return this.chains;
46
- });
27
+ async getChains() {
28
+ if (this.loadingPromise) {
29
+ await this.loadingPromise;
30
+ }
31
+ return this.chains;
47
32
  }
48
33
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { ChainId, } from '../types';
11
2
  const DefaultExecutionSettings = {
12
3
  /* eslint-disable-next-line @typescript-eslint/no-empty-function */
@@ -31,10 +22,10 @@ export default class ConfigService {
31
22
  * This call waits for all setup promises to be done.
32
23
  * Use this if you need access to chain data (RPCs or multicalls)
33
24
  */
34
- this.getConfigAsync = () => __awaiter(this, void 0, void 0, function* () {
35
- yield this.setupPromise;
25
+ this.getConfigAsync = async () => {
26
+ await this.setupPromise;
36
27
  return this.config;
37
- });
28
+ };
38
29
  this.updateConfig = (configUpdate) => {
39
30
  // API
40
31
  this.config.apiUrl = configUpdate.apiUrl || this.config.apiUrl;
@@ -49,11 +40,10 @@ export default class ConfigService {
49
40
  return this.config;
50
41
  };
51
42
  this.updateChains = (chains) => {
52
- var _a, _b;
53
43
  for (const chain of chains) {
54
44
  const chainId = chain.id;
55
45
  // set RPCs if they were not configured by the user before
56
- if (!((_a = this.config.rpcs[chainId]) === null || _a === void 0 ? void 0 : _a.length)) {
46
+ if (!this.config.rpcs[chainId]?.length) {
57
47
  this.config.rpcs[chainId] = chain.metamask.rpcUrls;
58
48
  }
59
49
  // set multicall addresses if they exist and were not configured by the user before
@@ -61,7 +51,7 @@ export default class ConfigService {
61
51
  this.config.multicallAddresses[chainId] = chain.multicallAddress;
62
52
  }
63
53
  }
64
- (_b = this.resolveSetupPromise) === null || _b === void 0 ? void 0 : _b.call(this);
54
+ this.resolveSetupPromise?.();
65
55
  return this.config;
66
56
  };
67
57
  this.config = ConfigService.getDefaultConfig();
@@ -88,7 +78,7 @@ export default class ConfigService {
88
78
  }
89
79
  ConfigService.getDefaultConfig = () => {
90
80
  return {
91
- apiUrl: 'https://li.quest/v1/',
81
+ apiUrl: 'https://li.quest/v1',
92
82
  rpcs: ConfigService.chainIdToObject([]),
93
83
  multicallAddresses: ConfigService.chainIdToObject(undefined),
94
84
  defaultExecutionSettings: DefaultExecutionSettings,
@@ -10,7 +10,7 @@ export const isRoutesRequest = (routesRequest) => {
10
10
  toTokenAddress !== '' &&
11
11
  (!options || isRoutesOptions(options)));
12
12
  };
13
- const isRoutesOptions = (routeOptions) => !(routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.slippage) || typeof routeOptions.slippage === 'number';
13
+ const isRoutesOptions = (routeOptions) => !routeOptions?.slippage || typeof routeOptions.slippage === 'number';
14
14
  export const isStep = (step) => {
15
15
  const { id, type, tool, action, estimate } = step;
16
16
  return (typeof id === 'string' &&
@@ -72,7 +72,10 @@ export type EnforcedObjectProperties<T> = T & {
72
72
  [P in keyof T]-?: T[P];
73
73
  };
74
74
  export interface ActiveRouteDictionary {
75
- [k: string]: ExecutionData;
75
+ [k: string]: {
76
+ executionData: ExecutionData;
77
+ executionPromise: Promise<Route>;
78
+ };
76
79
  }
77
80
  export type RevokeTokenData = {
78
81
  token: Token;
@@ -77,4 +77,9 @@ export declare class NotFoundError extends LifiError {
77
77
  export declare class UnknownError extends LifiError {
78
78
  constructor(code: ErrorCode, message: string, htmlMessage?: string, stack?: string);
79
79
  }
80
+ export declare class HTTPError extends Error {
81
+ response: Response;
82
+ status: number;
83
+ constructor(response: Response);
84
+ }
80
85
  export {};