@lifi/sdk 1.1.2 → 1.1.5

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 (96) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/Lifi.js +179 -285
  3. package/dist/allowance/index.js +56 -148
  4. package/dist/allowance/utils.js +51 -116
  5. package/dist/balances/index.js +29 -92
  6. package/dist/balances/utils.js +108 -218
  7. package/dist/cjs/Lifi.d.ts +200 -0
  8. package/dist/cjs/Lifi.js +376 -0
  9. package/dist/cjs/allowance/index.d.ts +22 -0
  10. package/dist/cjs/allowance/index.js +78 -0
  11. package/dist/cjs/allowance/utils.d.ts +14 -0
  12. package/dist/cjs/allowance/utils.js +82 -0
  13. package/dist/cjs/balances/index.d.ts +11 -0
  14. package/dist/cjs/balances/index.js +46 -0
  15. package/dist/cjs/balances/utils.d.ts +5 -0
  16. package/dist/cjs/balances/utils.js +150 -0
  17. package/dist/cjs/connectors.d.ts +6 -0
  18. package/dist/cjs/connectors.js +77 -0
  19. package/dist/cjs/execution/StatusManager.d.ts +65 -0
  20. package/dist/cjs/execution/StatusManager.js +167 -0
  21. package/dist/cjs/execution/StepExecutor.d.ts +15 -0
  22. package/dist/cjs/execution/StepExecutor.js +74 -0
  23. package/dist/cjs/execution/allowance.execute.d.ts +4 -0
  24. package/dist/cjs/execution/allowance.execute.js +97 -0
  25. package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
  26. package/dist/cjs/execution/balanceCheck.execute.js +48 -0
  27. package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
  28. package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
  29. package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
  30. package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
  31. package/dist/cjs/execution/index.d.ts +1 -0
  32. package/dist/cjs/execution/index.js +17 -0
  33. package/dist/cjs/execution/stepComparison.d.ts +14 -0
  34. package/dist/cjs/execution/stepComparison.js +46 -0
  35. package/dist/cjs/execution/switchChain.d.ts +16 -0
  36. package/dist/cjs/execution/switchChain.js +58 -0
  37. package/dist/cjs/execution/utils.d.ts +6 -0
  38. package/dist/cjs/execution/utils.js +137 -0
  39. package/dist/cjs/helpers.d.ts +18 -0
  40. package/dist/cjs/helpers.js +54 -0
  41. package/dist/cjs/index.d.ts +6 -0
  42. package/dist/cjs/index.js +27 -0
  43. package/dist/cjs/services/ApiService.d.ts +15 -0
  44. package/dist/cjs/services/ApiService.js +272 -0
  45. package/dist/cjs/services/ChainsService.d.ts +11 -0
  46. package/dist/cjs/services/ChainsService.js +54 -0
  47. package/dist/cjs/services/ConfigService.d.ts +23 -0
  48. package/dist/cjs/services/ConfigService.js +98 -0
  49. package/dist/cjs/typeguards.d.ts +4 -0
  50. package/dist/cjs/typeguards.js +53 -0
  51. package/dist/cjs/types/ERC20.d.ts +22 -0
  52. package/dist/cjs/types/ERC20.js +53 -0
  53. package/dist/cjs/types/index.d.ts +4 -0
  54. package/dist/cjs/types/index.js +22 -0
  55. package/dist/cjs/types/internal.types.d.ts +85 -0
  56. package/dist/cjs/types/internal.types.js +2 -0
  57. package/dist/cjs/utils/errors.d.ts +75 -0
  58. package/dist/cjs/utils/errors.js +115 -0
  59. package/dist/cjs/utils/getProvider.d.ts +3 -0
  60. package/dist/cjs/utils/getProvider.js +11 -0
  61. package/dist/cjs/utils/multicall.d.ts +10 -0
  62. package/dist/cjs/utils/multicall.js +77 -0
  63. package/dist/cjs/utils/multicallAbi.json +313 -0
  64. package/dist/cjs/utils/parseError.d.ts +38 -0
  65. package/dist/cjs/utils/parseError.js +141 -0
  66. package/dist/cjs/utils/preRestart.d.ts +2 -0
  67. package/dist/cjs/utils/preRestart.js +31 -0
  68. package/dist/cjs/utils/utils.d.ts +26 -0
  69. package/dist/cjs/utils/utils.js +120 -0
  70. package/dist/connectors.js +50 -133
  71. package/dist/execution/StatusManager.js +34 -41
  72. package/dist/execution/StepExecutor.js +54 -123
  73. package/dist/execution/allowance.execute.js +76 -142
  74. package/dist/execution/balanceCheck.execute.js +29 -74
  75. package/dist/execution/bridges/bridge.execute.js +132 -221
  76. package/dist/execution/exchanges/swap.execute.js +142 -225
  77. package/dist/execution/index.js +1 -17
  78. package/dist/execution/stepComparison.js +22 -61
  79. package/dist/execution/switchChain.js +33 -81
  80. package/dist/execution/utils.js +60 -119
  81. package/dist/helpers.js +15 -53
  82. package/dist/index.js +6 -25
  83. package/dist/services/ApiService.js +248 -385
  84. package/dist/services/ChainsService.js +29 -89
  85. package/dist/services/ConfigService.js +47 -86
  86. package/dist/typeguards.js +13 -21
  87. package/dist/types/ERC20.js +1 -4
  88. package/dist/types/index.js +4 -22
  89. package/dist/types/internal.types.js +1 -2
  90. package/dist/utils/errors.js +47 -93
  91. package/dist/utils/getProvider.js +3 -7
  92. package/dist/utils/multicall.js +61 -117
  93. package/dist/utils/parseError.js +73 -141
  94. package/dist/utils/preRestart.js +14 -21
  95. package/dist/utils/utils.js +47 -130
  96. package/package.json +34 -11
@@ -1,15 +1,3 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,386 +7,261 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
20
8
  });
21
9
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
10
+ import axios from 'axios';
11
+ import { isRoutesRequest, isStep } from '../typeguards';
12
+ import { ValidationError } from '../utils/errors';
13
+ import { parseBackendError } from '../utils/parseError';
14
+ import ConfigService from './ConfigService';
15
+ const getPossibilities = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
16
+ if (!request) {
17
+ request = {};
47
18
  }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var axios_1 = __importDefault(require("axios"));
54
- var typeguards_1 = require("../typeguards");
55
- var errors_1 = require("../utils/errors");
56
- var parseError_1 = require("../utils/parseError");
57
- var ConfigService_1 = __importDefault(require("./ConfigService"));
58
- var getPossibilities = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
59
- var configService, config, result, e_1;
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0:
63
- if (!request) {
64
- request = {};
65
- }
66
- configService = ConfigService_1.default.getInstance();
67
- config = configService.getConfig();
68
- // apply defaults
69
- request.bridges = request.bridges || config.defaultRouteOptions.bridges;
70
- request.exchanges = request.exchanges || config.defaultRouteOptions.exchanges;
71
- _a.label = 1;
72
- case 1:
73
- _a.trys.push([1, 3, , 4]);
74
- return [4 /*yield*/, axios_1.default.post(config.apiUrl + 'advanced/possibilities', request, {
75
- signal: options === null || options === void 0 ? void 0 : options.signal,
76
- })];
77
- case 2:
78
- result = _a.sent();
79
- return [2 /*return*/, result.data];
80
- case 3:
81
- e_1 = _a.sent();
82
- throw (0, parseError_1.parseBackendError)(e_1);
83
- case 4: return [2 /*return*/];
84
- }
85
- });
86
- }); };
87
- var getToken = function (chain, token, options) { return __awaiter(void 0, void 0, void 0, function () {
88
- var configService, config, result, e_2;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0:
92
- if (!chain) {
93
- throw new errors_1.ValidationError('Required parameter "chain" is missing.');
94
- }
95
- if (!token) {
96
- throw new errors_1.ValidationError('Required parameter "token" is missing.');
97
- }
98
- configService = ConfigService_1.default.getInstance();
99
- config = configService.getConfig();
100
- _a.label = 1;
101
- case 1:
102
- _a.trys.push([1, 3, , 4]);
103
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'token', {
104
- params: {
105
- chain: chain,
106
- token: token,
107
- },
108
- signal: options === null || options === void 0 ? void 0 : options.signal,
109
- })];
110
- case 2:
111
- result = _a.sent();
112
- return [2 /*return*/, result.data];
113
- case 3:
114
- e_2 = _a.sent();
115
- throw (0, parseError_1.parseBackendError)(e_2);
116
- case 4: return [2 /*return*/];
117
- }
118
- });
119
- }); };
120
- var getQuote = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
121
- var configService, config, requiredParameters, result, e_3;
122
- var _a, _b, _c, _d, _e, _f;
123
- return __generator(this, function (_g) {
124
- switch (_g.label) {
125
- case 0:
126
- configService = ConfigService_1.default.getInstance();
127
- config = configService.getConfig();
128
- requiredParameters = [
129
- 'fromChain',
130
- 'fromToken',
131
- 'fromAddress',
132
- 'fromAmount',
133
- 'toChain',
134
- 'toToken',
135
- ];
136
- requiredParameters.forEach(function (requiredParameter) {
137
- if (!request[requiredParameter]) {
138
- throw new errors_1.ValidationError("Required parameter \"".concat(requiredParameter, "\" is missing."));
139
- }
140
- });
141
- // apply defaults
142
- request.order = request.order || config.defaultRouteOptions.order;
143
- request.slippage = request.slippage || config.defaultRouteOptions.slippage;
144
- request.integrator =
145
- request.integrator || config.defaultRouteOptions.integrator;
146
- request.referrer = request.referrer || config.defaultRouteOptions.referrer;
147
- request.fee = request.fee || config.defaultRouteOptions.fee;
148
- request.allowBridges =
149
- request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
150
- request.denyBridges =
151
- request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
152
- request.preferBridges =
153
- request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
154
- request.allowExchanges =
155
- request.allowExchanges || ((_d = config.defaultRouteOptions.bridges) === null || _d === void 0 ? void 0 : _d.allow);
156
- request.denyExchanges =
157
- request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
158
- request.preferExchanges =
159
- request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
160
- _g.label = 1;
161
- case 1:
162
- _g.trys.push([1, 3, , 4]);
163
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'quote', {
164
- params: request,
165
- signal: options === null || options === void 0 ? void 0 : options.signal,
166
- })];
167
- case 2:
168
- result = _g.sent();
169
- return [2 /*return*/, result.data];
170
- case 3:
171
- e_3 = _g.sent();
172
- throw (0, parseError_1.parseBackendError)(e_3);
173
- case 4: return [2 /*return*/];
174
- }
175
- });
176
- }); };
177
- var getContractCallQuote = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
178
- var configService, config, requiredParameters, result, e_4;
19
+ const configService = ConfigService.getInstance();
20
+ const config = configService.getConfig();
21
+ // apply defaults
22
+ request.bridges = request.bridges || config.defaultRouteOptions.bridges;
23
+ request.exchanges = request.exchanges || config.defaultRouteOptions.exchanges;
24
+ // send request
25
+ try {
26
+ const result = yield axios.post(config.apiUrl + 'advanced/possibilities', request, {
27
+ signal: options === null || options === void 0 ? void 0 : options.signal,
28
+ });
29
+ return result.data;
30
+ }
31
+ catch (e) {
32
+ throw parseBackendError(e);
33
+ }
34
+ });
35
+ const getToken = (chain, token, options) => __awaiter(void 0, void 0, void 0, function* () {
36
+ if (!chain) {
37
+ throw new ValidationError('Required parameter "chain" is missing.');
38
+ }
39
+ if (!token) {
40
+ throw new ValidationError('Required parameter "token" is missing.');
41
+ }
42
+ const configService = ConfigService.getInstance();
43
+ const config = configService.getConfig();
44
+ try {
45
+ const result = yield axios.get(config.apiUrl + 'token', {
46
+ params: {
47
+ chain,
48
+ token,
49
+ },
50
+ signal: options === null || options === void 0 ? void 0 : options.signal,
51
+ });
52
+ return result.data;
53
+ }
54
+ catch (e) {
55
+ throw parseBackendError(e);
56
+ }
57
+ });
58
+ const getQuote = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
179
59
  var _a, _b, _c, _d, _e, _f;
180
- return __generator(this, function (_g) {
181
- switch (_g.label) {
182
- case 0:
183
- configService = ConfigService_1.default.getInstance();
184
- config = configService.getConfig();
185
- requiredParameters = [
186
- 'fromChain',
187
- 'fromToken',
188
- 'fromAddress',
189
- 'toChain',
190
- 'toToken',
191
- 'toAmount',
192
- 'toContractAddress',
193
- 'toContractCallData',
194
- 'toContractGasLimit',
195
- ];
196
- requiredParameters.forEach(function (requiredParameter) {
197
- if (!request[requiredParameter]) {
198
- throw new errors_1.ValidationError("Required parameter \"".concat(requiredParameter, "\" is missing."));
199
- }
200
- });
201
- // apply defaults
202
- // option.order is not used in this endpoint
203
- request.slippage = request.slippage || config.defaultRouteOptions.slippage;
204
- request.integrator =
205
- request.integrator || config.defaultRouteOptions.integrator;
206
- request.referrer = request.referrer || config.defaultRouteOptions.referrer;
207
- request.fee = request.fee || config.defaultRouteOptions.fee;
208
- request.allowBridges =
209
- request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
210
- request.denyBridges =
211
- request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
212
- request.preferBridges =
213
- request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
214
- request.allowExchanges =
215
- request.allowExchanges || ((_d = config.defaultRouteOptions.bridges) === null || _d === void 0 ? void 0 : _d.allow);
216
- request.denyExchanges =
217
- request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
218
- request.preferExchanges =
219
- request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
220
- _g.label = 1;
221
- case 1:
222
- _g.trys.push([1, 3, , 4]);
223
- return [4 /*yield*/, axios_1.default.post(config.apiUrl + 'quote/contractCall', request, {
224
- signal: options === null || options === void 0 ? void 0 : options.signal,
225
- })];
226
- case 2:
227
- result = _g.sent();
228
- return [2 /*return*/, result.data];
229
- case 3:
230
- e_4 = _g.sent();
231
- throw (0, parseError_1.parseBackendError)(e_4);
232
- case 4: return [2 /*return*/];
60
+ const configService = ConfigService.getInstance();
61
+ const config = configService.getConfig();
62
+ // validation
63
+ const requiredParameters = [
64
+ 'fromChain',
65
+ 'fromToken',
66
+ 'fromAddress',
67
+ 'fromAmount',
68
+ 'toChain',
69
+ 'toToken',
70
+ ];
71
+ requiredParameters.forEach((requiredParameter) => {
72
+ if (!request[requiredParameter]) {
73
+ throw new ValidationError(`Required parameter "${requiredParameter}" is missing.`);
233
74
  }
234
75
  });
235
- }); };
236
- var getStatus = function (_a, options) {
237
- var bridge = _a.bridge, fromChain = _a.fromChain, toChain = _a.toChain, txHash = _a.txHash;
238
- return __awaiter(void 0, void 0, void 0, function () {
239
- var configService, config, result, e_5;
240
- return __generator(this, function (_b) {
241
- switch (_b.label) {
242
- case 0:
243
- if (fromChain !== toChain && !bridge) {
244
- throw new errors_1.ValidationError('Parameter "bridge" is required for cross chain transfers.');
245
- }
246
- if (!fromChain) {
247
- throw new errors_1.ValidationError('Required parameter "fromChain" is missing.');
248
- }
249
- if (!toChain) {
250
- throw new errors_1.ValidationError('Required parameter "toChain" is missing.');
251
- }
252
- if (!txHash) {
253
- throw new errors_1.ValidationError('Required parameter "txHash" is missing.');
254
- }
255
- configService = ConfigService_1.default.getInstance();
256
- config = configService.getConfig();
257
- _b.label = 1;
258
- case 1:
259
- _b.trys.push([1, 3, , 4]);
260
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'status', {
261
- params: {
262
- bridge: bridge,
263
- fromChain: fromChain,
264
- toChain: toChain,
265
- txHash: txHash,
266
- },
267
- signal: options === null || options === void 0 ? void 0 : options.signal,
268
- })];
269
- case 2:
270
- result = _b.sent();
271
- return [2 /*return*/, result.data];
272
- case 3:
273
- e_5 = _b.sent();
274
- throw (0, parseError_1.parseBackendError)(e_5);
275
- case 4: return [2 /*return*/];
276
- }
76
+ // apply defaults
77
+ request.order = request.order || config.defaultRouteOptions.order;
78
+ request.slippage = request.slippage || config.defaultRouteOptions.slippage;
79
+ request.integrator =
80
+ request.integrator || config.defaultRouteOptions.integrator;
81
+ request.referrer = request.referrer || config.defaultRouteOptions.referrer;
82
+ request.fee = request.fee || config.defaultRouteOptions.fee;
83
+ request.allowBridges =
84
+ request.allowBridges || ((_a = config.defaultRouteOptions.bridges) === null || _a === void 0 ? void 0 : _a.allow);
85
+ request.denyBridges =
86
+ request.denyBridges || ((_b = config.defaultRouteOptions.bridges) === null || _b === void 0 ? void 0 : _b.deny);
87
+ request.preferBridges =
88
+ request.preferBridges || ((_c = config.defaultRouteOptions.bridges) === null || _c === void 0 ? void 0 : _c.prefer);
89
+ request.allowExchanges =
90
+ request.allowExchanges || ((_d = config.defaultRouteOptions.bridges) === null || _d === void 0 ? void 0 : _d.allow);
91
+ request.denyExchanges =
92
+ request.denyExchanges || ((_e = config.defaultRouteOptions.bridges) === null || _e === void 0 ? void 0 : _e.deny);
93
+ request.preferExchanges =
94
+ request.preferExchanges || ((_f = config.defaultRouteOptions.bridges) === null || _f === void 0 ? void 0 : _f.prefer);
95
+ try {
96
+ const result = yield axios.get(config.apiUrl + 'quote', {
97
+ params: request,
98
+ signal: options === null || options === void 0 ? void 0 : options.signal,
277
99
  });
278
- });
279
- };
280
- var getChains = function (options) { return __awaiter(void 0, void 0, void 0, function () {
281
- var configService, config, result, e_6;
282
- return __generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- configService = ConfigService_1.default.getInstance();
286
- config = configService.getConfig();
287
- _a.label = 1;
288
- case 1:
289
- _a.trys.push([1, 3, , 4]);
290
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'chains', {
291
- signal: options === null || options === void 0 ? void 0 : options.signal,
292
- })];
293
- case 2:
294
- result = _a.sent();
295
- return [2 /*return*/, result.data.chains];
296
- case 3:
297
- e_6 = _a.sent();
298
- throw (0, parseError_1.parseBackendError)(e_6);
299
- case 4: return [2 /*return*/];
300
- }
301
- });
302
- }); };
303
- var getRoutes = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
304
- var configService, config, result, e_7;
305
- return __generator(this, function (_a) {
306
- switch (_a.label) {
307
- case 0:
308
- if (!(0, typeguards_1.isRoutesRequest)(request)) {
309
- throw new errors_1.ValidationError('Invalid routes request.');
310
- }
311
- configService = ConfigService_1.default.getInstance();
312
- config = configService.getConfig();
313
- // apply defaults
314
- request.options = __assign(__assign({}, config.defaultRouteOptions), request.options);
315
- _a.label = 1;
316
- case 1:
317
- _a.trys.push([1, 3, , 4]);
318
- return [4 /*yield*/, axios_1.default.post(config.apiUrl + 'advanced/routes', request, {
319
- signal: options === null || options === void 0 ? void 0 : options.signal,
320
- })];
321
- case 2:
322
- result = _a.sent();
323
- return [2 /*return*/, result.data];
324
- case 3:
325
- e_7 = _a.sent();
326
- throw (0, parseError_1.parseBackendError)(e_7);
327
- case 4: return [2 /*return*/];
328
- }
329
- });
330
- }); };
331
- var getStepTransaction = function (step, options) { return __awaiter(void 0, void 0, void 0, function () {
332
- var configService, config, result, e_8;
333
- return __generator(this, function (_a) {
334
- switch (_a.label) {
335
- case 0:
336
- if (!(0, typeguards_1.isStep)(step)) {
337
- // While the validation fails for some users we should not enforce it
338
- // eslint-disable-next-line no-console
339
- console.warn('SDK Validation: Invalid Step', step);
340
- }
341
- configService = ConfigService_1.default.getInstance();
342
- config = configService.getConfig();
343
- _a.label = 1;
344
- case 1:
345
- _a.trys.push([1, 3, , 4]);
346
- return [4 /*yield*/, axios_1.default.post(config.apiUrl + 'advanced/stepTransaction', step, {
347
- signal: options === null || options === void 0 ? void 0 : options.signal,
348
- })];
349
- case 2:
350
- result = _a.sent();
351
- return [2 /*return*/, result.data];
352
- case 3:
353
- e_8 = _a.sent();
354
- throw (0, parseError_1.parseBackendError)(e_8);
355
- case 4: return [2 /*return*/];
100
+ return result.data;
101
+ }
102
+ catch (e) {
103
+ throw parseBackendError(e);
104
+ }
105
+ });
106
+ const getContractCallQuote = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
107
+ var _g, _h, _j, _k, _l, _m;
108
+ const configService = ConfigService.getInstance();
109
+ const config = configService.getConfig();
110
+ // validation
111
+ const requiredParameters = [
112
+ 'fromChain',
113
+ 'fromToken',
114
+ 'fromAddress',
115
+ 'toChain',
116
+ 'toToken',
117
+ 'toAmount',
118
+ 'toContractAddress',
119
+ 'toContractCallData',
120
+ 'toContractGasLimit',
121
+ ];
122
+ requiredParameters.forEach((requiredParameter) => {
123
+ if (!request[requiredParameter]) {
124
+ throw new ValidationError(`Required parameter "${requiredParameter}" is missing.`);
356
125
  }
357
126
  });
358
- }); };
359
- var getTools = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
360
- var configService, config, r;
361
- return __generator(this, function (_a) {
362
- switch (_a.label) {
363
- case 0:
364
- configService = ConfigService_1.default.getInstance();
365
- config = configService.getConfig();
366
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'tools', {
367
- params: request,
368
- signal: options === null || options === void 0 ? void 0 : options.signal,
369
- })];
370
- case 1:
371
- r = _a.sent();
372
- return [2 /*return*/, r.data];
373
- }
127
+ // apply defaults
128
+ // option.order is not used in this endpoint
129
+ request.slippage = request.slippage || config.defaultRouteOptions.slippage;
130
+ request.integrator =
131
+ request.integrator || config.defaultRouteOptions.integrator;
132
+ request.referrer = request.referrer || config.defaultRouteOptions.referrer;
133
+ request.fee = request.fee || config.defaultRouteOptions.fee;
134
+ request.allowBridges =
135
+ request.allowBridges || ((_g = config.defaultRouteOptions.bridges) === null || _g === void 0 ? void 0 : _g.allow);
136
+ request.denyBridges =
137
+ request.denyBridges || ((_h = config.defaultRouteOptions.bridges) === null || _h === void 0 ? void 0 : _h.deny);
138
+ request.preferBridges =
139
+ request.preferBridges || ((_j = config.defaultRouteOptions.bridges) === null || _j === void 0 ? void 0 : _j.prefer);
140
+ request.allowExchanges =
141
+ request.allowExchanges || ((_k = config.defaultRouteOptions.bridges) === null || _k === void 0 ? void 0 : _k.allow);
142
+ request.denyExchanges =
143
+ request.denyExchanges || ((_l = config.defaultRouteOptions.bridges) === null || _l === void 0 ? void 0 : _l.deny);
144
+ request.preferExchanges =
145
+ request.preferExchanges || ((_m = config.defaultRouteOptions.bridges) === null || _m === void 0 ? void 0 : _m.prefer);
146
+ // send request
147
+ try {
148
+ const result = yield axios.post(config.apiUrl + 'quote/contractCall', request, {
149
+ signal: options === null || options === void 0 ? void 0 : options.signal,
150
+ });
151
+ return result.data;
152
+ }
153
+ catch (e) {
154
+ throw parseBackendError(e);
155
+ }
156
+ });
157
+ const getStatus = ({ bridge, fromChain, toChain, txHash }, options) => __awaiter(void 0, void 0, void 0, function* () {
158
+ if (fromChain !== toChain && !bridge) {
159
+ throw new ValidationError('Parameter "bridge" is required for cross chain transfers.');
160
+ }
161
+ if (!fromChain) {
162
+ throw new ValidationError('Required parameter "fromChain" is missing.');
163
+ }
164
+ if (!toChain) {
165
+ throw new ValidationError('Required parameter "toChain" is missing.');
166
+ }
167
+ if (!txHash) {
168
+ throw new ValidationError('Required parameter "txHash" is missing.');
169
+ }
170
+ const configService = ConfigService.getInstance();
171
+ const config = configService.getConfig();
172
+ try {
173
+ const result = yield axios.get(config.apiUrl + 'status', {
174
+ params: {
175
+ bridge,
176
+ fromChain,
177
+ toChain,
178
+ txHash,
179
+ },
180
+ signal: options === null || options === void 0 ? void 0 : options.signal,
181
+ });
182
+ return result.data;
183
+ }
184
+ catch (e) {
185
+ throw parseBackendError(e);
186
+ }
187
+ });
188
+ const getChains = (options) => __awaiter(void 0, void 0, void 0, function* () {
189
+ const configService = ConfigService.getInstance();
190
+ const config = configService.getConfig();
191
+ try {
192
+ const result = yield axios.get(config.apiUrl + 'chains', {
193
+ signal: options === null || options === void 0 ? void 0 : options.signal,
194
+ });
195
+ return result.data.chains;
196
+ }
197
+ catch (e) {
198
+ throw parseBackendError(e);
199
+ }
200
+ });
201
+ const getRoutes = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
202
+ if (!isRoutesRequest(request)) {
203
+ throw new ValidationError('Invalid routes request.');
204
+ }
205
+ const configService = ConfigService.getInstance();
206
+ const config = configService.getConfig();
207
+ // apply defaults
208
+ request.options = Object.assign(Object.assign({}, config.defaultRouteOptions), request.options);
209
+ // send request
210
+ try {
211
+ const result = yield axios.post(config.apiUrl + 'advanced/routes', request, {
212
+ signal: options === null || options === void 0 ? void 0 : options.signal,
213
+ });
214
+ return result.data;
215
+ }
216
+ catch (e) {
217
+ throw parseBackendError(e);
218
+ }
219
+ });
220
+ const getStepTransaction = (step, options) => __awaiter(void 0, void 0, void 0, function* () {
221
+ if (!isStep(step)) {
222
+ // While the validation fails for some users we should not enforce it
223
+ // eslint-disable-next-line no-console
224
+ console.warn('SDK Validation: Invalid Step', step);
225
+ }
226
+ const configService = ConfigService.getInstance();
227
+ const config = configService.getConfig();
228
+ try {
229
+ const result = yield axios.post(config.apiUrl + 'advanced/stepTransaction', step, {
230
+ signal: options === null || options === void 0 ? void 0 : options.signal,
231
+ });
232
+ return result.data;
233
+ }
234
+ catch (e) {
235
+ throw parseBackendError(e);
236
+ }
237
+ });
238
+ const getTools = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
239
+ const configService = ConfigService.getInstance();
240
+ const config = configService.getConfig();
241
+ const r = yield axios.get(config.apiUrl + 'tools', {
242
+ params: request,
243
+ signal: options === null || options === void 0 ? void 0 : options.signal,
374
244
  });
375
- }); };
376
- var getTokens = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
377
- var configService, config, r;
378
- return __generator(this, function (_a) {
379
- switch (_a.label) {
380
- case 0:
381
- configService = ConfigService_1.default.getInstance();
382
- config = configService.getConfig();
383
- return [4 /*yield*/, axios_1.default.get(config.apiUrl + 'tokens', {
384
- params: request,
385
- signal: options === null || options === void 0 ? void 0 : options.signal,
386
- })];
387
- case 1:
388
- r = _a.sent();
389
- return [2 /*return*/, r.data];
390
- }
245
+ return r.data;
246
+ });
247
+ const getTokens = (request, options) => __awaiter(void 0, void 0, void 0, function* () {
248
+ const configService = ConfigService.getInstance();
249
+ const config = configService.getConfig();
250
+ const r = yield axios.get(config.apiUrl + 'tokens', {
251
+ params: request,
252
+ signal: options === null || options === void 0 ? void 0 : options.signal,
391
253
  });
392
- }); };
393
- exports.default = {
394
- getPossibilities: getPossibilities,
395
- getToken: getToken,
396
- getQuote: getQuote,
397
- getContractCallQuote: getContractCallQuote,
398
- getStatus: getStatus,
399
- getChains: getChains,
400
- getRoutes: getRoutes,
401
- getStepTransaction: getStepTransaction,
402
- getTools: getTools,
403
- getTokens: getTokens,
254
+ return r.data;
255
+ });
256
+ export default {
257
+ getPossibilities,
258
+ getToken,
259
+ getQuote,
260
+ getContractCallQuote,
261
+ getStatus,
262
+ getChains,
263
+ getRoutes,
264
+ getStepTransaction,
265
+ getTools,
266
+ getTokens,
404
267
  };