@lifi/sdk 1.1.4 → 1.2.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/CHANGELOG.md +11 -0
- package/dist/Lifi.js +3 -0
- package/dist/cjs/Lifi.d.ts +200 -0
- package/dist/cjs/Lifi.js +379 -0
- package/dist/cjs/allowance/index.d.ts +22 -0
- package/dist/cjs/allowance/index.js +78 -0
- package/dist/cjs/allowance/utils.d.ts +14 -0
- package/dist/cjs/allowance/utils.js +82 -0
- package/dist/cjs/balances/index.d.ts +11 -0
- package/dist/cjs/balances/index.js +46 -0
- package/dist/cjs/balances/utils.d.ts +5 -0
- package/dist/cjs/balances/utils.js +150 -0
- package/dist/cjs/connectors.d.ts +6 -0
- package/dist/cjs/connectors.js +77 -0
- package/dist/cjs/execution/StatusManager.d.ts +65 -0
- package/dist/cjs/execution/StatusManager.js +167 -0
- package/dist/cjs/execution/StepExecutor.d.ts +15 -0
- package/dist/cjs/execution/StepExecutor.js +74 -0
- package/dist/cjs/execution/allowance.execute.d.ts +4 -0
- package/dist/cjs/execution/allowance.execute.js +97 -0
- package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/cjs/execution/balanceCheck.execute.js +48 -0
- package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
- package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +17 -0
- package/dist/cjs/execution/stepComparison.d.ts +14 -0
- package/dist/cjs/execution/stepComparison.js +46 -0
- package/dist/cjs/execution/switchChain.d.ts +16 -0
- package/dist/cjs/execution/switchChain.js +58 -0
- package/dist/cjs/execution/utils.d.ts +6 -0
- package/dist/cjs/execution/utils.js +137 -0
- package/dist/cjs/helpers.d.ts +19 -0
- package/dist/cjs/helpers.js +88 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/services/ApiService.d.ts +15 -0
- package/dist/cjs/services/ApiService.js +272 -0
- package/dist/cjs/services/ChainsService.d.ts +11 -0
- package/dist/cjs/services/ChainsService.js +54 -0
- package/dist/cjs/services/ConfigService.d.ts +23 -0
- package/dist/cjs/services/ConfigService.js +98 -0
- package/dist/cjs/typeguards.d.ts +4 -0
- package/dist/cjs/typeguards.js +53 -0
- package/dist/cjs/types/ERC20.d.ts +22 -0
- package/dist/cjs/types/ERC20.js +53 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/internal.types.d.ts +87 -0
- package/dist/cjs/types/internal.types.js +2 -0
- package/dist/cjs/utils/errors.d.ts +75 -0
- package/dist/cjs/utils/errors.js +115 -0
- package/dist/cjs/utils/getProvider.d.ts +3 -0
- package/dist/cjs/utils/getProvider.js +11 -0
- package/dist/cjs/utils/multicall.d.ts +10 -0
- package/dist/cjs/utils/multicall.js +77 -0
- package/dist/cjs/utils/multicallAbi.json +313 -0
- package/dist/cjs/utils/parseError.d.ts +38 -0
- package/dist/cjs/utils/parseError.js +141 -0
- package/dist/cjs/utils/preRestart.d.ts +2 -0
- package/dist/cjs/utils/preRestart.js +31 -0
- package/dist/cjs/utils/utils.d.ts +26 -0
- package/dist/cjs/utils/utils.js +120 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +33 -0
- package/dist/types/internal.types.d.ts +2 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +40 -12
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const typeguards_1 = require("../typeguards");
|
|
17
|
+
const errors_1 = require("../utils/errors");
|
|
18
|
+
const parseError_1 = require("../utils/parseError");
|
|
19
|
+
const ConfigService_1 = __importDefault(require("./ConfigService"));
|
|
20
|
+
const getPossibilities = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
if (!request) {
|
|
22
|
+
request = {};
|
|
23
|
+
}
|
|
24
|
+
const configService = ConfigService_1.default.getInstance();
|
|
25
|
+
const config = configService.getConfig();
|
|
26
|
+
// apply defaults
|
|
27
|
+
request.bridges = request.bridges || config.defaultRouteOptions.bridges;
|
|
28
|
+
request.exchanges = request.exchanges || config.defaultRouteOptions.exchanges;
|
|
29
|
+
// send request
|
|
30
|
+
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,
|
|
33
|
+
});
|
|
34
|
+
return result.data;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const getToken = (chain, token, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
if (!chain) {
|
|
42
|
+
throw new errors_1.ValidationError('Required parameter "chain" is missing.');
|
|
43
|
+
}
|
|
44
|
+
if (!token) {
|
|
45
|
+
throw new errors_1.ValidationError('Required parameter "token" is missing.');
|
|
46
|
+
}
|
|
47
|
+
const configService = ConfigService_1.default.getInstance();
|
|
48
|
+
const config = configService.getConfig();
|
|
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,
|
|
56
|
+
});
|
|
57
|
+
return result.data;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
61
|
+
}
|
|
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();
|
|
67
|
+
// validation
|
|
68
|
+
const requiredParameters = [
|
|
69
|
+
'fromChain',
|
|
70
|
+
'fromToken',
|
|
71
|
+
'fromAddress',
|
|
72
|
+
'fromAmount',
|
|
73
|
+
'toChain',
|
|
74
|
+
'toToken',
|
|
75
|
+
];
|
|
76
|
+
requiredParameters.forEach((requiredParameter) => {
|
|
77
|
+
if (!request[requiredParameter]) {
|
|
78
|
+
throw new errors_1.ValidationError(`Required parameter "${requiredParameter}" is missing.`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// 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.bridges) === null || _d === void 0 ? void 0 : _d.allow);
|
|
96
|
+
request.denyExchanges =
|
|
97
|
+
request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
|
|
98
|
+
request.preferExchanges =
|
|
99
|
+
request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
|
|
100
|
+
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,
|
|
104
|
+
});
|
|
105
|
+
return result.data;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
109
|
+
}
|
|
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();
|
|
115
|
+
// validation
|
|
116
|
+
const requiredParameters = [
|
|
117
|
+
'fromChain',
|
|
118
|
+
'fromToken',
|
|
119
|
+
'fromAddress',
|
|
120
|
+
'toChain',
|
|
121
|
+
'toToken',
|
|
122
|
+
'toAmount',
|
|
123
|
+
'toContractAddress',
|
|
124
|
+
'toContractCallData',
|
|
125
|
+
'toContractGasLimit',
|
|
126
|
+
];
|
|
127
|
+
requiredParameters.forEach((requiredParameter) => {
|
|
128
|
+
if (!request[requiredParameter]) {
|
|
129
|
+
throw new errors_1.ValidationError(`Required parameter "${requiredParameter}" is missing.`);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
// apply defaults
|
|
133
|
+
// 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.bridges) === null || _k === void 0 ? void 0 : _k.allow);
|
|
147
|
+
request.denyExchanges =
|
|
148
|
+
request.denyExchanges || ((_l = config.defaultRouteOptions.bridges) === null || _l === void 0 ? void 0 : _l.deny);
|
|
149
|
+
request.preferExchanges =
|
|
150
|
+
request.preferExchanges || ((_m = config.defaultRouteOptions.bridges) === null || _m === void 0 ? void 0 : _m.prefer);
|
|
151
|
+
// send request
|
|
152
|
+
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
|
+
});
|
|
156
|
+
return result.data;
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
const getStatus = ({ bridge, fromChain, toChain, txHash }, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
+
if (fromChain !== toChain && !bridge) {
|
|
164
|
+
throw new errors_1.ValidationError('Parameter "bridge" is required for cross chain transfers.');
|
|
165
|
+
}
|
|
166
|
+
if (!fromChain) {
|
|
167
|
+
throw new errors_1.ValidationError('Required parameter "fromChain" is missing.');
|
|
168
|
+
}
|
|
169
|
+
if (!toChain) {
|
|
170
|
+
throw new errors_1.ValidationError('Required parameter "toChain" is missing.');
|
|
171
|
+
}
|
|
172
|
+
if (!txHash) {
|
|
173
|
+
throw new errors_1.ValidationError('Required parameter "txHash" is missing.');
|
|
174
|
+
}
|
|
175
|
+
const configService = ConfigService_1.default.getInstance();
|
|
176
|
+
const config = configService.getConfig();
|
|
177
|
+
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,
|
|
186
|
+
});
|
|
187
|
+
return result.data;
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
191
|
+
}
|
|
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();
|
|
196
|
+
try {
|
|
197
|
+
const result = yield axios_1.default.get(config.apiUrl + 'chains', {
|
|
198
|
+
signal: options === null || options === void 0 ? void 0 : options.signal,
|
|
199
|
+
});
|
|
200
|
+
return result.data.chains;
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const getRoutes = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
207
|
+
if (!(0, typeguards_1.isRoutesRequest)(request)) {
|
|
208
|
+
throw new errors_1.ValidationError('Invalid routes request.');
|
|
209
|
+
}
|
|
210
|
+
const configService = ConfigService_1.default.getInstance();
|
|
211
|
+
const config = configService.getConfig();
|
|
212
|
+
// apply defaults
|
|
213
|
+
request.options = Object.assign(Object.assign({}, config.defaultRouteOptions), request.options);
|
|
214
|
+
// send request
|
|
215
|
+
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,
|
|
218
|
+
});
|
|
219
|
+
return result.data;
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
throw (0, parseError_1.parseBackendError)(e);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const getStepTransaction = (step, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
226
|
+
if (!(0, typeguards_1.isStep)(step)) {
|
|
227
|
+
// While the validation fails for some users we should not enforce it
|
|
228
|
+
// eslint-disable-next-line no-console
|
|
229
|
+
console.warn('SDK Validation: Invalid Step', step);
|
|
230
|
+
}
|
|
231
|
+
const configService = ConfigService_1.default.getInstance();
|
|
232
|
+
const config = configService.getConfig();
|
|
233
|
+
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,
|
|
236
|
+
});
|
|
237
|
+
return result.data;
|
|
238
|
+
}
|
|
239
|
+
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,
|
|
249
|
+
});
|
|
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,
|
|
258
|
+
});
|
|
259
|
+
return r.data;
|
|
260
|
+
});
|
|
261
|
+
exports.default = {
|
|
262
|
+
getPossibilities,
|
|
263
|
+
getToken,
|
|
264
|
+
getQuote,
|
|
265
|
+
getContractCallQuote,
|
|
266
|
+
getStatus,
|
|
267
|
+
getChains,
|
|
268
|
+
getRoutes,
|
|
269
|
+
getStepTransaction,
|
|
270
|
+
getTools,
|
|
271
|
+
getTokens,
|
|
272
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Chain, ChainId } from '@lifi/types';
|
|
2
|
+
export default class ChainsService {
|
|
3
|
+
private static instance;
|
|
4
|
+
private readonly loadingPromise;
|
|
5
|
+
private chains;
|
|
6
|
+
constructor();
|
|
7
|
+
private loadAvailableChains;
|
|
8
|
+
static getInstance(): ChainsService;
|
|
9
|
+
getChainById(chainId: ChainId): Promise<Chain>;
|
|
10
|
+
getChains(): Promise<Chain[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const errors_1 = require("../utils/errors");
|
|
16
|
+
const ApiService_1 = __importDefault(require("./ApiService"));
|
|
17
|
+
class ChainsService {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.chains = [];
|
|
20
|
+
this.loadingPromise = this.loadAvailableChains();
|
|
21
|
+
}
|
|
22
|
+
loadAvailableChains() {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
this.chains = yield ApiService_1.default.getChains();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
static getInstance() {
|
|
28
|
+
if (!this.instance) {
|
|
29
|
+
this.instance = new ChainsService();
|
|
30
|
+
}
|
|
31
|
+
return this.instance;
|
|
32
|
+
}
|
|
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
|
+
});
|
|
44
|
+
}
|
|
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
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = ChainsService;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Chain, Config, ConfigUpdate } from '../types';
|
|
2
|
+
export default class ConfigService {
|
|
3
|
+
private static instance;
|
|
4
|
+
private readonly config;
|
|
5
|
+
private readonly setupPromise;
|
|
6
|
+
private resolveSetupPromise;
|
|
7
|
+
constructor();
|
|
8
|
+
private static chainIdToObject;
|
|
9
|
+
private static getDefaultConfig;
|
|
10
|
+
static getInstance(): ConfigService;
|
|
11
|
+
/**
|
|
12
|
+
* This call immediately returns the current config. It does not make sure that all chain data is already loaded
|
|
13
|
+
* Use this if you need access to basic information like API urls or settings
|
|
14
|
+
*/
|
|
15
|
+
getConfig: () => Config;
|
|
16
|
+
/**
|
|
17
|
+
* This call waits for all setup promises to be done.
|
|
18
|
+
* Use this if you need access to chain data (RPCs or multicalls)
|
|
19
|
+
*/
|
|
20
|
+
getConfigAsync: () => Promise<Config>;
|
|
21
|
+
updateConfig: (configUpdate: ConfigUpdate) => Config;
|
|
22
|
+
updateChains: (chains: Chain[]) => Config;
|
|
23
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
const DefaultExecutionSettings = {
|
|
14
|
+
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
15
|
+
updateCallback: () => { },
|
|
16
|
+
switchChainHook: () => Promise.resolve(undefined),
|
|
17
|
+
acceptSlippageUpdateHook: () => Promise.resolve(undefined),
|
|
18
|
+
infiniteApproval: false,
|
|
19
|
+
};
|
|
20
|
+
class ConfigService {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.resolveSetupPromise = undefined;
|
|
23
|
+
/**
|
|
24
|
+
* This call immediately returns the current config. It does not make sure that all chain data is already loaded
|
|
25
|
+
* Use this if you need access to basic information like API urls or settings
|
|
26
|
+
*/
|
|
27
|
+
this.getConfig = () => {
|
|
28
|
+
return this.config;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* This call waits for all setup promises to be done.
|
|
32
|
+
* Use this if you need access to chain data (RPCs or multicalls)
|
|
33
|
+
*/
|
|
34
|
+
this.getConfigAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.setupPromise;
|
|
36
|
+
return this.config;
|
|
37
|
+
});
|
|
38
|
+
this.updateConfig = (configUpdate) => {
|
|
39
|
+
// API
|
|
40
|
+
this.config.apiUrl = configUpdate.apiUrl || this.config.apiUrl;
|
|
41
|
+
// RPCS
|
|
42
|
+
this.config.rpcs = Object.assign(this.config.rpcs, configUpdate.rpcs);
|
|
43
|
+
// MULTICALL
|
|
44
|
+
this.config.multicallAddresses = Object.assign(this.config.multicallAddresses, configUpdate.multicallAddresses);
|
|
45
|
+
// SETTINGS
|
|
46
|
+
this.config.defaultExecutionSettings = Object.assign(this.config.defaultExecutionSettings, configUpdate.defaultExecutionSettings);
|
|
47
|
+
// OPTIONS
|
|
48
|
+
this.config.defaultRouteOptions = Object.assign(this.config.defaultRouteOptions, configUpdate.defaultRouteOptions);
|
|
49
|
+
return this.config;
|
|
50
|
+
};
|
|
51
|
+
this.updateChains = (chains) => {
|
|
52
|
+
var _a;
|
|
53
|
+
for (const chain of chains) {
|
|
54
|
+
const chainId = chain.id;
|
|
55
|
+
// set RPCs if they were not configured by the user before
|
|
56
|
+
if (!this.config.rpcs[chainId].length) {
|
|
57
|
+
this.config.rpcs[chainId] = chain.metamask.rpcUrls;
|
|
58
|
+
}
|
|
59
|
+
// set multicall addresses if they exist and were not configured by the user before
|
|
60
|
+
if (chain.multicallAddress && !this.config.multicallAddresses[chainId]) {
|
|
61
|
+
this.config.multicallAddresses[chainId] = chain.multicallAddress;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
(_a = this.resolveSetupPromise) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
65
|
+
return this.config;
|
|
66
|
+
};
|
|
67
|
+
this.config = ConfigService.getDefaultConfig();
|
|
68
|
+
this.setupPromise = new Promise((resolve) => {
|
|
69
|
+
this.resolveSetupPromise = resolve;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
static chainIdToObject(val) {
|
|
73
|
+
const result = {};
|
|
74
|
+
const values = Object.values(types_1.ChainId);
|
|
75
|
+
values.forEach((chainId) => {
|
|
76
|
+
if (typeof chainId !== 'string') {
|
|
77
|
+
result[chainId] = val ? JSON.parse(JSON.stringify(val)) : val;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
static getInstance() {
|
|
83
|
+
if (!this.instance) {
|
|
84
|
+
this.instance = new ConfigService();
|
|
85
|
+
}
|
|
86
|
+
return this.instance;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.default = ConfigService;
|
|
90
|
+
ConfigService.getDefaultConfig = () => {
|
|
91
|
+
return {
|
|
92
|
+
apiUrl: 'https://li.quest/v1/',
|
|
93
|
+
rpcs: ConfigService.chainIdToObject([]),
|
|
94
|
+
multicallAddresses: ConfigService.chainIdToObject(undefined),
|
|
95
|
+
defaultExecutionSettings: DefaultExecutionSettings,
|
|
96
|
+
defaultRouteOptions: {},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RoutesRequest, Step, Token } from './types';
|
|
2
|
+
export declare const isRoutesRequest: (routesRequest: RoutesRequest) => routesRequest is RoutesRequest;
|
|
3
|
+
export declare const isStep: (step: Step) => step is Step;
|
|
4
|
+
export declare const isToken: (token: Token) => token is Token;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isToken = exports.isStep = exports.isRoutesRequest = void 0;
|
|
4
|
+
const isRoutesRequest = (routesRequest) => {
|
|
5
|
+
const { fromChainId, fromAmount, fromTokenAddress, toChainId, toTokenAddress, options, } = routesRequest;
|
|
6
|
+
return (typeof fromChainId === 'number' &&
|
|
7
|
+
typeof fromAmount === 'string' &&
|
|
8
|
+
fromAmount !== '' &&
|
|
9
|
+
typeof fromTokenAddress === 'string' &&
|
|
10
|
+
fromTokenAddress !== '' &&
|
|
11
|
+
typeof toChainId === 'number' &&
|
|
12
|
+
typeof toTokenAddress === 'string' &&
|
|
13
|
+
toTokenAddress !== '' &&
|
|
14
|
+
(!options || isRoutesOptions(options)));
|
|
15
|
+
};
|
|
16
|
+
exports.isRoutesRequest = isRoutesRequest;
|
|
17
|
+
const isRoutesOptions = (routeOptions) => !(routeOptions === null || routeOptions === void 0 ? void 0 : routeOptions.slippage) || typeof routeOptions.slippage === 'number';
|
|
18
|
+
const isStep = (step) => {
|
|
19
|
+
const { id, type, tool, action, estimate } = step;
|
|
20
|
+
return (typeof id === 'string' &&
|
|
21
|
+
['swap', 'cross', 'lifi'].includes(type) &&
|
|
22
|
+
typeof tool === 'string' &&
|
|
23
|
+
isAction(action) &&
|
|
24
|
+
isEstimate(estimate));
|
|
25
|
+
};
|
|
26
|
+
exports.isStep = isStep;
|
|
27
|
+
const isAction = (action) => {
|
|
28
|
+
const { fromChainId, fromAmount, fromToken, toChainId, toToken, slippage } = action;
|
|
29
|
+
return (typeof fromChainId === 'number' &&
|
|
30
|
+
typeof fromAmount === 'string' &&
|
|
31
|
+
fromAmount !== '' &&
|
|
32
|
+
(0, exports.isToken)(fromToken) &&
|
|
33
|
+
typeof toChainId === 'number' &&
|
|
34
|
+
(0, exports.isToken)(toToken) &&
|
|
35
|
+
typeof slippage === 'number');
|
|
36
|
+
};
|
|
37
|
+
const isEstimate = (estimate) => {
|
|
38
|
+
const { fromAmount, toAmount, toAmountMin, approvalAddress } = estimate;
|
|
39
|
+
return (typeof fromAmount === 'string' &&
|
|
40
|
+
fromAmount !== '' &&
|
|
41
|
+
typeof toAmount === 'string' &&
|
|
42
|
+
toAmount !== '' &&
|
|
43
|
+
typeof toAmountMin === 'string' &&
|
|
44
|
+
toAmountMin !== '' &&
|
|
45
|
+
typeof approvalAddress === 'string');
|
|
46
|
+
};
|
|
47
|
+
const isToken = (token) => {
|
|
48
|
+
const { address, decimals, chainId } = token;
|
|
49
|
+
return (typeof address === 'string' &&
|
|
50
|
+
typeof decimals === 'number' &&
|
|
51
|
+
typeof chainId === 'number');
|
|
52
|
+
};
|
|
53
|
+
exports.isToken = isToken;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseContract, BigNumber, BigNumberish, CallOverrides, ContractTransaction, Overrides } from 'ethers';
|
|
2
|
+
export declare const ERC20_ABI: {
|
|
3
|
+
name: string;
|
|
4
|
+
inputs: {
|
|
5
|
+
internalType: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
}[];
|
|
9
|
+
outputs: {
|
|
10
|
+
internalType: string;
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
}[];
|
|
14
|
+
stateMutability: string;
|
|
15
|
+
type: string;
|
|
16
|
+
}[];
|
|
17
|
+
export interface ERC20Contract extends BaseContract {
|
|
18
|
+
allowance(owner: string, spender: string, overrides?: CallOverrides): Promise<BigNumber>;
|
|
19
|
+
approve(spender: string, amount: BigNumberish, overrides?: Overrides & {
|
|
20
|
+
from?: string | Promise<string>;
|
|
21
|
+
}): Promise<ContractTransaction>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERC20_ABI = void 0;
|
|
4
|
+
exports.ERC20_ABI = [
|
|
5
|
+
{
|
|
6
|
+
name: 'approve',
|
|
7
|
+
inputs: [
|
|
8
|
+
{
|
|
9
|
+
internalType: 'address',
|
|
10
|
+
name: 'spender',
|
|
11
|
+
type: 'address',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
internalType: 'uint256',
|
|
15
|
+
name: 'amount',
|
|
16
|
+
type: 'uint256',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
outputs: [
|
|
20
|
+
{
|
|
21
|
+
internalType: 'bool',
|
|
22
|
+
name: '',
|
|
23
|
+
type: 'bool',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
stateMutability: 'nonpayable',
|
|
27
|
+
type: 'function',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'allowance',
|
|
31
|
+
inputs: [
|
|
32
|
+
{
|
|
33
|
+
internalType: 'address',
|
|
34
|
+
name: 'owner',
|
|
35
|
+
type: 'address',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
internalType: 'address',
|
|
39
|
+
name: 'spender',
|
|
40
|
+
type: 'address',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
outputs: [
|
|
44
|
+
{
|
|
45
|
+
internalType: 'uint256',
|
|
46
|
+
name: '',
|
|
47
|
+
type: 'uint256',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
stateMutability: 'view',
|
|
51
|
+
type: 'function',
|
|
52
|
+
},
|
|
53
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LifiError = void 0;
|
|
18
|
+
__exportStar(require("@lifi/types"), exports);
|
|
19
|
+
var errors_1 = require("../utils/errors");
|
|
20
|
+
Object.defineProperty(exports, "LifiError", { enumerable: true, get: function () { return errors_1.LifiError; } });
|
|
21
|
+
__exportStar(require("./ERC20"), exports);
|
|
22
|
+
__exportStar(require("./internal.types"), exports);
|