@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.
- package/dist/Lifi.js +97 -85
- package/dist/allowance/checkAllowance.js +12 -21
- package/dist/allowance/tokenApproval.js +20 -29
- package/dist/allowance/utils.js +12 -24
- package/dist/balance/checkBalance.js +5 -14
- package/dist/balance/getTokenBalance.js +12 -21
- package/dist/balance/index.d.ts +11 -0
- package/dist/balance/index.js +8 -0
- package/dist/balance/utils.d.ts +1 -0
- package/dist/balance/utils.js +36 -38
- package/dist/cjs/Lifi.js +97 -85
- package/dist/cjs/allowance/checkAllowance.js +12 -21
- package/dist/cjs/allowance/tokenApproval.js +20 -29
- package/dist/cjs/allowance/utils.js +12 -24
- package/dist/cjs/balance/checkBalance.js +5 -14
- package/dist/cjs/balance/getTokenBalance.js +12 -21
- package/dist/cjs/balance/index.d.ts +11 -0
- package/dist/cjs/balance/index.js +8 -0
- package/dist/cjs/balance/utils.d.ts +1 -0
- package/dist/cjs/balance/utils.js +39 -39
- package/dist/cjs/connectors.js +17 -25
- package/dist/cjs/execution/ExecutionManager.js +27 -33
- package/dist/cjs/execution/StatusManager.js +13 -13
- package/dist/cjs/execution/StepExecutor.js +8 -14
- package/dist/cjs/execution/stepComparison.js +4 -14
- package/dist/cjs/execution/switchChain.js +5 -14
- package/dist/cjs/execution/utils.js +43 -50
- package/dist/cjs/helpers.d.ts +12 -1
- package/dist/cjs/helpers.js +68 -19
- package/dist/cjs/services/ApiService.d.ts +10 -9
- package/dist/cjs/services/ApiService.js +190 -152
- package/dist/cjs/services/ApiService.unit.handlers.d.ts +1 -0
- package/dist/cjs/services/ApiService.unit.handlers.js +50 -0
- package/dist/cjs/services/ChainsService.js +16 -31
- package/dist/cjs/services/ConfigService.js +6 -16
- package/dist/cjs/typeguards.js +1 -1
- package/dist/cjs/types/internal.types.d.ts +4 -1
- package/dist/cjs/utils/errors.d.ts +5 -0
- package/dist/cjs/utils/errors.js +14 -1
- package/dist/cjs/utils/multicall.js +6 -15
- package/dist/cjs/utils/parseError.d.ts +2 -2
- package/dist/cjs/utils/parseError.js +36 -38
- package/dist/cjs/utils/preRestart.js +5 -7
- package/dist/cjs/utils/utils.d.ts +0 -1
- package/dist/cjs/utils/utils.js +21 -28
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/connectors.js +15 -23
- package/dist/execution/ExecutionManager.js +27 -33
- package/dist/execution/StatusManager.js +11 -11
- package/dist/execution/StepExecutor.js +8 -14
- package/dist/execution/stepComparison.js +4 -14
- package/dist/execution/switchChain.js +5 -14
- package/dist/execution/utils.js +43 -50
- package/dist/helpers.d.ts +12 -1
- package/dist/helpers.js +65 -18
- package/dist/services/ApiService.d.ts +10 -9
- package/dist/services/ApiService.js +190 -152
- package/dist/services/ApiService.unit.handlers.d.ts +1 -0
- package/dist/services/ApiService.unit.handlers.js +44 -0
- package/dist/services/ChainsService.js +16 -31
- package/dist/services/ConfigService.js +6 -16
- package/dist/typeguards.js +1 -1
- package/dist/types/internal.types.d.ts +4 -1
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +12 -0
- package/dist/utils/multicall.js +6 -15
- package/dist/utils/parseError.d.ts +2 -2
- package/dist/utils/parseError.js +36 -38
- package/dist/utils/preRestart.js +5 -7
- package/dist/utils/utils.d.ts +0 -1
- package/dist/utils/utils.js +20 -26
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +23 -25
- package/CHANGELOG.md +0 -490
|
@@ -1,64 +1,61 @@
|
|
|
1
|
-
|
|
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 = (
|
|
16
|
-
if (!
|
|
17
|
-
|
|
6
|
+
const getPossibilities = async (requestConfig, options) => {
|
|
7
|
+
if (!requestConfig) {
|
|
8
|
+
requestConfig = {};
|
|
18
9
|
}
|
|
19
|
-
const
|
|
20
|
-
const config = configService.getConfig();
|
|
10
|
+
const config = ConfigService.getInstance().getConfig();
|
|
21
11
|
// apply defaults
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
27
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
43
|
-
const config = configService.getConfig();
|
|
43
|
+
const config = ConfigService.getInstance().getConfig();
|
|
44
44
|
try {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
51
|
+
return response;
|
|
53
52
|
}
|
|
54
53
|
catch (e) {
|
|
55
|
-
throw parseBackendError(e);
|
|
54
|
+
throw await parseBackendError(e);
|
|
56
55
|
}
|
|
57
|
-
}
|
|
58
|
-
const getQuote = (
|
|
59
|
-
|
|
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 (!
|
|
69
|
+
if (!requestConfig[requiredParameter]) {
|
|
73
70
|
throw new ValidationError(`Required parameter "${requiredParameter}" is missing.`);
|
|
74
71
|
}
|
|
75
72
|
});
|
|
76
73
|
// apply defaults
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
97
|
-
|
|
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
|
|
101
|
+
return response;
|
|
101
102
|
}
|
|
102
103
|
catch (e) {
|
|
103
|
-
throw parseBackendError(e);
|
|
104
|
+
throw await parseBackendError(e);
|
|
104
105
|
}
|
|
105
|
-
}
|
|
106
|
-
const getContractCallQuote = (
|
|
107
|
-
|
|
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 (!
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
149
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
171
|
-
const config = configService.getConfig();
|
|
177
|
+
const config = ConfigService.getInstance().getConfig();
|
|
172
178
|
try {
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
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) =>
|
|
189
|
-
const
|
|
190
|
-
const config = configService.getConfig();
|
|
192
|
+
};
|
|
193
|
+
const getChains = async (options) => {
|
|
194
|
+
const config = ConfigService.getInstance().getConfig();
|
|
191
195
|
try {
|
|
192
|
-
const
|
|
193
|
-
signal: options
|
|
196
|
+
const response = await request(`${config.apiUrl}/chains`, {
|
|
197
|
+
signal: options?.signal,
|
|
194
198
|
});
|
|
195
|
-
return
|
|
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 = (
|
|
202
|
-
if (!isRoutesRequest(
|
|
204
|
+
};
|
|
205
|
+
const getRoutes = async (requestConfig, options) => {
|
|
206
|
+
if (!isRoutesRequest(requestConfig)) {
|
|
203
207
|
throw new ValidationError('Invalid routes request.');
|
|
204
208
|
}
|
|
205
|
-
const
|
|
206
|
-
const config = configService.getConfig();
|
|
209
|
+
const config = ConfigService.getInstance().getConfig();
|
|
207
210
|
// apply defaults
|
|
208
|
-
|
|
211
|
+
requestConfig.options = {
|
|
212
|
+
...config.defaultRouteOptions,
|
|
213
|
+
...requestConfig.options,
|
|
214
|
+
};
|
|
209
215
|
// send request
|
|
210
216
|
try {
|
|
211
|
-
const
|
|
212
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
227
|
-
const config = configService.getConfig();
|
|
237
|
+
const config = ConfigService.getInstance().getConfig();
|
|
228
238
|
try {
|
|
229
|
-
const
|
|
230
|
-
|
|
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
|
|
247
|
+
return response;
|
|
233
248
|
}
|
|
234
249
|
catch (e) {
|
|
235
|
-
throw parseBackendError(e);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const getTools = (
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
|
246
|
-
}
|
|
247
|
-
const getTokens = (
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 = () =>
|
|
35
|
-
|
|
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 (!
|
|
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
|
-
|
|
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,
|
package/dist/typeguards.js
CHANGED
|
@@ -10,7 +10,7 @@ export const isRoutesRequest = (routesRequest) => {
|
|
|
10
10
|
toTokenAddress !== '' &&
|
|
11
11
|
(!options || isRoutesOptions(options)));
|
|
12
12
|
};
|
|
13
|
-
const isRoutesOptions = (routeOptions) => !
|
|
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]:
|
|
75
|
+
[k: string]: {
|
|
76
|
+
executionData: ExecutionData;
|
|
77
|
+
executionPromise: Promise<Route>;
|
|
78
|
+
};
|
|
76
79
|
}
|
|
77
80
|
export type RevokeTokenData = {
|
|
78
81
|
token: Token;
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -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 {};
|