@lifi/sdk 1.7.2 → 2.0.0-beta.1

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