@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.
- 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 +66 -18
- 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 +63 -17
- 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 +22 -24
- 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
|
|
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 = (
|
|
21
|
-
if (!
|
|
22
|
-
|
|
11
|
+
const getPossibilities = async (requestConfig, options) => {
|
|
12
|
+
if (!requestConfig) {
|
|
13
|
+
requestConfig = {};
|
|
23
14
|
}
|
|
24
|
-
const
|
|
25
|
-
const config = configService.getConfig();
|
|
15
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
26
16
|
// apply defaults
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
32
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
48
|
-
const config = configService.getConfig();
|
|
48
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
49
49
|
try {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
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 = (
|
|
64
|
-
|
|
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 (!
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
|
102
|
-
|
|
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
|
|
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 = (
|
|
112
|
-
|
|
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 (!
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
154
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
176
|
-
const config = configService.getConfig();
|
|
182
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
177
183
|
try {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
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) =>
|
|
194
|
-
const
|
|
195
|
-
const config = configService.getConfig();
|
|
197
|
+
};
|
|
198
|
+
const getChains = async (options) => {
|
|
199
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
196
200
|
try {
|
|
197
|
-
const
|
|
198
|
-
signal: options
|
|
201
|
+
const response = await (0, helpers_1.request)(`${config.apiUrl}/chains`, {
|
|
202
|
+
signal: options?.signal,
|
|
199
203
|
});
|
|
200
|
-
return
|
|
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 = (
|
|
207
|
-
if (!(0, typeguards_1.isRoutesRequest)(
|
|
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
|
|
211
|
-
const config = configService.getConfig();
|
|
214
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
212
215
|
// apply defaults
|
|
213
|
-
|
|
216
|
+
requestConfig.options = {
|
|
217
|
+
...config.defaultRouteOptions,
|
|
218
|
+
...requestConfig.options,
|
|
219
|
+
};
|
|
214
220
|
// send request
|
|
215
221
|
try {
|
|
216
|
-
const
|
|
217
|
-
|
|
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
|
|
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) =>
|
|
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
|
|
232
|
-
const config = configService.getConfig();
|
|
242
|
+
const config = ConfigService_1.default.getInstance().getConfig();
|
|
233
243
|
try {
|
|
234
|
-
const
|
|
235
|
-
|
|
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
|
|
252
|
+
return response;
|
|
238
253
|
}
|
|
239
254
|
catch (e) {
|
|
240
|
-
throw (0, parseError_1.parseBackendError)(e);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
const getTools = (
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
251
|
-
}
|
|
252
|
-
const getTokens = (
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 = () =>
|
|
37
|
-
|
|
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 (!
|
|
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
|
-
|
|
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,
|
package/dist/cjs/typeguards.js
CHANGED
|
@@ -14,7 +14,7 @@ const isRoutesRequest = (routesRequest) => {
|
|
|
14
14
|
(!options || isRoutesOptions(options)));
|
|
15
15
|
};
|
|
16
16
|
exports.isRoutesRequest = isRoutesRequest;
|
|
17
|
-
const isRoutesOptions = (routeOptions) => !
|
|
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]:
|
|
75
|
+
[k: string]: {
|
|
76
|
+
executionData: ExecutionData;
|
|
77
|
+
executionPromise: Promise<Route>;
|
|
78
|
+
};
|
|
76
79
|
}
|
|
77
80
|
export type RevokeTokenData = {
|
|
78
81
|
token: Token;
|