@lifi/sdk 1.0.2 → 1.1.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 +17 -0
- package/dist/Lifi.d.ts +15 -1
- package/dist/Lifi.js +25 -10
- package/dist/execution/StatusManager.d.ts +3 -1
- package/dist/execution/StatusManager.js +16 -1
- package/dist/execution/bridges/bridge.execute.js +63 -45
- package/dist/execution/exchanges/swap.execute.js +68 -50
- package/dist/execution/stepComparison.d.ts +14 -0
- package/dist/execution/stepComparison.js +81 -0
- package/dist/execution/utils.d.ts +1 -0
- package/dist/execution/utils.js +12 -1
- package/dist/services/ApiService.d.ts +3 -2
- package/dist/services/ApiService.js +126 -72
- package/dist/services/ConfigService.js +1 -0
- package/dist/types/internal.types.d.ts +13 -3
- package/dist/utils/errors.d.ts +3 -1
- package/dist/utils/errors.js +2 -0
- package/dist/utils/parseError.d.ts +1 -0
- package/dist/utils/parseError.js +40 -26
- package/dist/utils/preRestart.d.ts +2 -0
- package/dist/utils/preRestart.js +34 -0
- package/package.json +2 -2
|
@@ -1,4 +1,15 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -49,6 +60,7 @@ var parseError_1 = require("../../utils/parseError");
|
|
|
49
60
|
var utils_1 = require("../../utils/utils");
|
|
50
61
|
var allowance_execute_1 = require("../allowance.execute");
|
|
51
62
|
var balanceCheck_execute_1 = require("../balanceCheck.execute");
|
|
63
|
+
var stepComparison_1 = require("../stepComparison");
|
|
52
64
|
var switchChain_1 = require("../switchChain");
|
|
53
65
|
var utils_2 = require("../utils");
|
|
54
66
|
var SwapExecutionManager = /** @class */ (function () {
|
|
@@ -61,10 +73,10 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
61
73
|
this.execute = function (_a) {
|
|
62
74
|
var signer = _a.signer, step = _a.step, statusManager = _a.statusManager, settings = _a.settings;
|
|
63
75
|
return __awaiter(_this, void 0, void 0, function () {
|
|
64
|
-
var action, estimate, chainsService, fromChain, swapProcess, tx, personalizedStep, transactionRequest, updatedSigner, e_1, error, receipt, e_2, error, statusResponse, e_3;
|
|
65
|
-
var
|
|
66
|
-
return __generator(this, function (
|
|
67
|
-
switch (
|
|
76
|
+
var action, estimate, chainsService, fromChain, swapProcess, tx, personalizedStep, updatedStep, _b, transactionRequest, updatedSigner, e_1, error, receipt, e_2, error, statusResponse, e_3;
|
|
77
|
+
var _c, _d, _e, _f;
|
|
78
|
+
return __generator(this, function (_g) {
|
|
79
|
+
switch (_g.label) {
|
|
68
80
|
case 0:
|
|
69
81
|
action = step.action, estimate = step.estimate;
|
|
70
82
|
step.execution = statusManager.initExecutionObject(step);
|
|
@@ -73,23 +85,23 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
73
85
|
// Approval
|
|
74
86
|
];
|
|
75
87
|
case 1:
|
|
76
|
-
fromChain =
|
|
88
|
+
fromChain = _g.sent();
|
|
77
89
|
if (!(action.fromToken.address !== ethers_1.constants.AddressZero)) return [3 /*break*/, 3];
|
|
78
90
|
return [4 /*yield*/, (0, allowance_execute_1.checkAllowance)(signer, step, fromChain, action.fromToken, action.fromAmount, estimate.approvalAddress, statusManager, settings.infiniteApproval, this.shouldContinue)];
|
|
79
91
|
case 2:
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
_g.sent();
|
|
93
|
+
_g.label = 3;
|
|
82
94
|
case 3:
|
|
83
95
|
swapProcess = statusManager.findOrCreateProcess('SWAP', step);
|
|
84
|
-
|
|
96
|
+
_g.label = 4;
|
|
85
97
|
case 4:
|
|
86
|
-
|
|
98
|
+
_g.trys.push([4, 14, , 16]);
|
|
87
99
|
if (!swapProcess.txHash) return [3 /*break*/, 6];
|
|
88
100
|
return [4 /*yield*/, (0, getProvider_1.getProvider)(signer).getTransaction(swapProcess.txHash)];
|
|
89
101
|
case 5:
|
|
90
102
|
// -> restore existing tx
|
|
91
|
-
tx =
|
|
92
|
-
return [3 /*break*/,
|
|
103
|
+
tx = _g.sent();
|
|
104
|
+
return [3 /*break*/, 13];
|
|
93
105
|
case 6:
|
|
94
106
|
// -> check balance
|
|
95
107
|
return [4 /*yield*/, (0, balanceCheck_execute_1.balanceCheck)(signer, step)
|
|
@@ -97,19 +109,24 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
97
109
|
];
|
|
98
110
|
case 7:
|
|
99
111
|
// -> check balance
|
|
100
|
-
|
|
112
|
+
_g.sent();
|
|
101
113
|
return [4 /*yield*/, (0, utils_1.personalizeStep)(signer, step)];
|
|
102
114
|
case 8:
|
|
103
|
-
personalizedStep =
|
|
115
|
+
personalizedStep = _g.sent();
|
|
104
116
|
return [4 /*yield*/, ApiService_1.default.getStepTransaction(personalizedStep)];
|
|
105
117
|
case 9:
|
|
106
|
-
|
|
118
|
+
updatedStep = _g.sent();
|
|
119
|
+
_b = [{}];
|
|
120
|
+
return [4 /*yield*/, (0, stepComparison_1.stepComparison)(statusManager, personalizedStep, updatedStep, settings.acceptSlippageUpdateHook, this.shouldContinue)];
|
|
121
|
+
case 10:
|
|
122
|
+
step = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_g.sent())])), { execution: step.execution }]);
|
|
123
|
+
transactionRequest = step.transactionRequest;
|
|
107
124
|
if (!transactionRequest) {
|
|
108
125
|
throw new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
109
126
|
}
|
|
110
127
|
return [4 /*yield*/, (0, switchChain_1.switchChain)(signer, statusManager, step, settings.switchChainHook, this.shouldContinue)];
|
|
111
|
-
case
|
|
112
|
-
updatedSigner =
|
|
128
|
+
case 11:
|
|
129
|
+
updatedSigner = _g.sent();
|
|
113
130
|
if (!updatedSigner) {
|
|
114
131
|
// chain switch was not successful, stop execution here
|
|
115
132
|
return [2 /*return*/, step.execution];
|
|
@@ -121,16 +138,16 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
121
138
|
return [2 /*return*/, step.execution]; // stop before user interaction is needed
|
|
122
139
|
}
|
|
123
140
|
return [4 /*yield*/, signer.sendTransaction(transactionRequest)];
|
|
124
|
-
case
|
|
141
|
+
case 12:
|
|
125
142
|
// -> submit tx
|
|
126
|
-
tx =
|
|
127
|
-
|
|
128
|
-
case
|
|
129
|
-
case 13:
|
|
130
|
-
e_1 = _f.sent();
|
|
131
|
-
return [4 /*yield*/, (0, parseError_1.parseError)(e_1, step, swapProcess)];
|
|
143
|
+
tx = _g.sent();
|
|
144
|
+
_g.label = 13;
|
|
145
|
+
case 13: return [3 /*break*/, 16];
|
|
132
146
|
case 14:
|
|
133
|
-
|
|
147
|
+
e_1 = _g.sent();
|
|
148
|
+
return [4 /*yield*/, (0, parseError_1.parseError)(e_1, step, swapProcess)];
|
|
149
|
+
case 15:
|
|
150
|
+
error = _g.sent();
|
|
134
151
|
statusManager.updateProcess(step, swapProcess.type, 'FAILED', {
|
|
135
152
|
error: {
|
|
136
153
|
message: error.message,
|
|
@@ -140,22 +157,22 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
140
157
|
});
|
|
141
158
|
statusManager.updateExecution(step, 'FAILED');
|
|
142
159
|
throw error;
|
|
143
|
-
case
|
|
160
|
+
case 16:
|
|
144
161
|
// Wait for Transaction
|
|
145
162
|
statusManager.updateProcess(step, swapProcess.type, 'PENDING', {
|
|
146
163
|
txLink: fromChain.metamask.blockExplorerUrls[0] + 'tx/' + tx.hash,
|
|
147
164
|
txHash: tx.hash,
|
|
148
165
|
});
|
|
149
|
-
|
|
150
|
-
case 16:
|
|
151
|
-
_f.trys.push([16, 18, , 22]);
|
|
152
|
-
return [4 /*yield*/, tx.wait()];
|
|
166
|
+
_g.label = 17;
|
|
153
167
|
case 17:
|
|
154
|
-
|
|
155
|
-
return [
|
|
168
|
+
_g.trys.push([17, 19, , 23]);
|
|
169
|
+
return [4 /*yield*/, tx.wait()];
|
|
156
170
|
case 18:
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
receipt = _g.sent();
|
|
172
|
+
return [3 /*break*/, 23];
|
|
173
|
+
case 19:
|
|
174
|
+
e_2 = _g.sent();
|
|
175
|
+
if (!(e_2.code === 'TRANSACTION_REPLACED' && e_2.replacement)) return [3 /*break*/, 20];
|
|
159
176
|
receipt = e_2.replacement;
|
|
160
177
|
statusManager.updateProcess(step, swapProcess.type, 'PENDING', {
|
|
161
178
|
txHash: e_2.replacement.hash,
|
|
@@ -163,10 +180,10 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
163
180
|
'tx/' +
|
|
164
181
|
e_2.replacement.hash,
|
|
165
182
|
});
|
|
166
|
-
return [3 /*break*/,
|
|
167
|
-
case
|
|
168
|
-
case
|
|
169
|
-
error =
|
|
183
|
+
return [3 /*break*/, 22];
|
|
184
|
+
case 20: return [4 /*yield*/, (0, parseError_1.parseError)(e_2)];
|
|
185
|
+
case 21:
|
|
186
|
+
error = _g.sent();
|
|
170
187
|
statusManager.updateProcess(step, swapProcess.type, 'FAILED', {
|
|
171
188
|
error: {
|
|
172
189
|
message: error.message,
|
|
@@ -176,18 +193,18 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
176
193
|
});
|
|
177
194
|
statusManager.updateExecution(step, 'FAILED');
|
|
178
195
|
throw error;
|
|
179
|
-
case
|
|
180
|
-
case
|
|
181
|
-
|
|
196
|
+
case 22: return [3 /*break*/, 23];
|
|
197
|
+
case 23:
|
|
198
|
+
_g.trys.push([23, 25, , 26]);
|
|
182
199
|
if (!swapProcess.txHash) {
|
|
183
200
|
throw new Error('Transaction hash is undefined.');
|
|
184
201
|
}
|
|
185
202
|
return [4 /*yield*/, (0, utils_2.waitForReceivingTransaction)(swapProcess.txHash, statusManager, swapProcess.type, step)];
|
|
186
|
-
case 23:
|
|
187
|
-
statusResponse = _f.sent();
|
|
188
|
-
return [3 /*break*/, 25];
|
|
189
203
|
case 24:
|
|
190
|
-
|
|
204
|
+
statusResponse = _g.sent();
|
|
205
|
+
return [3 /*break*/, 26];
|
|
206
|
+
case 25:
|
|
207
|
+
e_3 = _g.sent();
|
|
191
208
|
statusManager.updateProcess(step, swapProcess.type, 'FAILED', {
|
|
192
209
|
error: {
|
|
193
210
|
code: errors_1.LifiErrorCode.TransactionFailed,
|
|
@@ -197,18 +214,19 @@ var SwapExecutionManager = /** @class */ (function () {
|
|
|
197
214
|
});
|
|
198
215
|
statusManager.updateExecution(step, 'FAILED');
|
|
199
216
|
throw e_3;
|
|
200
|
-
case
|
|
217
|
+
case 26:
|
|
201
218
|
statusManager.updateProcess(step, swapProcess.type, 'DONE', {
|
|
202
|
-
txHash: (
|
|
219
|
+
txHash: (_c = statusResponse.receiving) === null || _c === void 0 ? void 0 : _c.txHash,
|
|
203
220
|
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
204
221
|
'tx/' +
|
|
205
|
-
((
|
|
222
|
+
((_d = statusResponse.receiving) === null || _d === void 0 ? void 0 : _d.txHash),
|
|
206
223
|
});
|
|
207
224
|
statusManager.updateExecution(step, 'DONE', {
|
|
208
225
|
fromAmount: statusResponse.sending.amount,
|
|
209
|
-
toAmount: (
|
|
210
|
-
toToken: (
|
|
211
|
-
|
|
226
|
+
toAmount: (_e = statusResponse.receiving) === null || _e === void 0 ? void 0 : _e.amount,
|
|
227
|
+
toToken: (_f = statusResponse.receiving) === null || _f === void 0 ? void 0 : _f.token,
|
|
228
|
+
gasUsed: statusResponse.sending.gasUsed,
|
|
229
|
+
gasPrice: statusResponse.sending.gasPrice,
|
|
212
230
|
});
|
|
213
231
|
// DONE
|
|
214
232
|
return [2 /*return*/, step.execution];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StatusManager } from '.';
|
|
2
|
+
import { AcceptSlippageUpdateHook, Step } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* This method checks whether the new and updated Step meets the required slippage conditions.
|
|
5
|
+
* If yes it returns the updated Step.
|
|
6
|
+
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts.
|
|
7
|
+
*
|
|
8
|
+
* @param statusManager
|
|
9
|
+
* @param oldStep
|
|
10
|
+
* @param newStep
|
|
11
|
+
* @param acceptSlippageUpdateHook
|
|
12
|
+
* @param allowUserInteraction
|
|
13
|
+
*/
|
|
14
|
+
export declare const stepComparison: (statusManager: StatusManager, oldStep: Step, newStep: Step, acceptSlippageUpdateHook: AcceptSlippageUpdateHook, allowUserInteraction: boolean) => Promise<Step>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.stepComparison = void 0;
|
|
40
|
+
var errors_1 = require("../utils/errors");
|
|
41
|
+
var parseError_1 = require("../utils/parseError");
|
|
42
|
+
var utils_1 = require("./utils");
|
|
43
|
+
/**
|
|
44
|
+
* This method checks whether the new and updated Step meets the required slippage conditions.
|
|
45
|
+
* If yes it returns the updated Step.
|
|
46
|
+
* If no and if user interaction is allowed it triggers the acceptSlippageUpdateHook. If no user interaction is allowed it aborts.
|
|
47
|
+
*
|
|
48
|
+
* @param statusManager
|
|
49
|
+
* @param oldStep
|
|
50
|
+
* @param newStep
|
|
51
|
+
* @param acceptSlippageUpdateHook
|
|
52
|
+
* @param allowUserInteraction
|
|
53
|
+
*/
|
|
54
|
+
var stepComparison = function (statusManager, oldStep, newStep, acceptSlippageUpdateHook, allowUserInteraction) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var allowStepUpdate;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
if ((0, utils_1.updatedStepMeetsSlippageConditions)(oldStep, newStep)) {
|
|
60
|
+
return [2 /*return*/, statusManager.updateStepInRoute(newStep)];
|
|
61
|
+
}
|
|
62
|
+
if (!allowUserInteraction) return [3 /*break*/, 2];
|
|
63
|
+
return [4 /*yield*/, acceptSlippageUpdateHook({
|
|
64
|
+
oldToAmount: oldStep.estimate.toAmount,
|
|
65
|
+
newToAmount: newStep.estimate.toAmount,
|
|
66
|
+
toToken: newStep.action.toToken,
|
|
67
|
+
oldSlippage: oldStep.action.slippage,
|
|
68
|
+
newSlippage: newStep.action.slippage,
|
|
69
|
+
})];
|
|
70
|
+
case 1:
|
|
71
|
+
allowStepUpdate = _a.sent();
|
|
72
|
+
_a.label = 2;
|
|
73
|
+
case 2:
|
|
74
|
+
if (!allowStepUpdate) {
|
|
75
|
+
throw new errors_1.TransactionError(errors_1.LifiErrorCode.SlippageNotMet, 'Slippage conditions not met!', (0, parseError_1.getSlippageNotMetMessage)(oldStep));
|
|
76
|
+
}
|
|
77
|
+
return [2 /*return*/, statusManager.updateStepInRoute(newStep)];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}); };
|
|
81
|
+
exports.stepComparison = stepComparison;
|
|
@@ -3,3 +3,4 @@ import { StatusManager } from '..';
|
|
|
3
3
|
export declare function waitForReceivingTransaction(txHash: string, statusManager: StatusManager, processType: ProcessType, step: Step): Promise<StatusResponse>;
|
|
4
4
|
export declare function getProcessMessage(type: ProcessType, status: Status): string | undefined;
|
|
5
5
|
export declare function getSubstatusMessage(status: StatusMessage, substatus?: Substatus): string | undefined;
|
|
6
|
+
export declare function updatedStepMeetsSlippageConditions(oldStep: Step, newStep: Step): boolean;
|
package/dist/execution/utils.js
CHANGED
|
@@ -39,7 +39,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0;
|
|
42
|
+
exports.updatedStepMeetsSlippageConditions = exports.getSubstatusMessage = exports.getProcessMessage = exports.waitForReceivingTransaction = void 0;
|
|
43
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
43
44
|
var ApiService_1 = __importDefault(require("../services/ApiService"));
|
|
44
45
|
var errors_1 = require("../utils/errors");
|
|
45
46
|
var utils_1 = require("../utils/utils");
|
|
@@ -173,3 +174,13 @@ function getSubstatusMessage(status, substatus) {
|
|
|
173
174
|
return message;
|
|
174
175
|
}
|
|
175
176
|
exports.getSubstatusMessage = getSubstatusMessage;
|
|
177
|
+
function updatedStepMeetsSlippageConditions(oldStep, newStep) {
|
|
178
|
+
var setSlippage = new bignumber_js_1.default(oldStep.action.slippage);
|
|
179
|
+
var oldEstimatedToAmount = new bignumber_js_1.default(oldStep.estimate.toAmountMin);
|
|
180
|
+
var newEstimatedToAmount = new bignumber_js_1.default(newStep.estimate.toAmountMin);
|
|
181
|
+
var amountDifference = oldEstimatedToAmount.minus(newEstimatedToAmount);
|
|
182
|
+
var actualSlippage = amountDifference.dividedBy(oldEstimatedToAmount);
|
|
183
|
+
return (newEstimatedToAmount.gte(oldEstimatedToAmount) &&
|
|
184
|
+
actualSlippage.lte(setSlippage));
|
|
185
|
+
}
|
|
186
|
+
exports.updatedStepMeetsSlippageConditions = updatedStepMeetsSlippageConditions;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { GetStatusRequest, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
1
|
+
import { ContractCallQuoteRequest, GetStatusRequest, QuoteRequest, RequestOptions, TokensRequest, TokensResponse } from '@lifi/types';
|
|
2
2
|
import { ChainId, ChainKey, PossibilitiesRequest, PossibilitiesResponse, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, ToolsRequest, ToolsResponse } from '../types';
|
|
3
3
|
declare const _default: {
|
|
4
4
|
getPossibilities: (request?: PossibilitiesRequest | undefined, options?: RequestOptions | undefined) => Promise<PossibilitiesResponse>;
|
|
5
5
|
getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions | undefined) => Promise<Token>;
|
|
6
|
-
getQuote: (
|
|
6
|
+
getQuote: (request: QuoteRequest, options?: RequestOptions | undefined) => Promise<Step>;
|
|
7
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions | undefined) => Promise<Step>;
|
|
7
8
|
getStatus: ({ bridge, fromChain, toChain, txHash }: GetStatusRequest, options?: RequestOptions | undefined) => Promise<StatusResponse>;
|
|
8
9
|
getChains: (options?: RequestOptions | undefined) => Promise<import("@lifi/types").EVMChain[]>;
|
|
9
10
|
getRoutes: (request: RoutesRequest, options?: RequestOptions | undefined) => Promise<RoutesResponse>;
|
|
@@ -117,73 +117,126 @@ var getToken = function (chain, token, options) { return __awaiter(void 0, void
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
}); };
|
|
120
|
-
var getQuote = function (
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!toChain) {
|
|
140
|
-
throw new errors_1.ValidationError('Required parameter "toChain" is missing.');
|
|
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."));
|
|
141
139
|
}
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
179
|
+
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."));
|
|
144
199
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
});
|
|
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 + 'quoteContractCall', 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*/];
|
|
233
|
+
}
|
|
181
234
|
});
|
|
182
|
-
};
|
|
235
|
+
}); };
|
|
183
236
|
var getStatus = function (_a, options) {
|
|
184
237
|
var bridge = _a.bridge, fromChain = _a.fromChain, toChain = _a.toChain, txHash = _a.txHash;
|
|
185
238
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
186
|
-
var configService, config, result,
|
|
239
|
+
var configService, config, result, e_5;
|
|
187
240
|
return __generator(this, function (_b) {
|
|
188
241
|
switch (_b.label) {
|
|
189
242
|
case 0:
|
|
@@ -217,15 +270,15 @@ var getStatus = function (_a, options) {
|
|
|
217
270
|
result = _b.sent();
|
|
218
271
|
return [2 /*return*/, result.data];
|
|
219
272
|
case 3:
|
|
220
|
-
|
|
221
|
-
throw (0, parseError_1.parseBackendError)(
|
|
273
|
+
e_5 = _b.sent();
|
|
274
|
+
throw (0, parseError_1.parseBackendError)(e_5);
|
|
222
275
|
case 4: return [2 /*return*/];
|
|
223
276
|
}
|
|
224
277
|
});
|
|
225
278
|
});
|
|
226
279
|
};
|
|
227
280
|
var getChains = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
228
|
-
var configService, config, result,
|
|
281
|
+
var configService, config, result, e_6;
|
|
229
282
|
return __generator(this, function (_a) {
|
|
230
283
|
switch (_a.label) {
|
|
231
284
|
case 0:
|
|
@@ -241,14 +294,14 @@ var getChains = function (options) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
241
294
|
result = _a.sent();
|
|
242
295
|
return [2 /*return*/, result.data.chains];
|
|
243
296
|
case 3:
|
|
244
|
-
|
|
245
|
-
throw (0, parseError_1.parseBackendError)(
|
|
297
|
+
e_6 = _a.sent();
|
|
298
|
+
throw (0, parseError_1.parseBackendError)(e_6);
|
|
246
299
|
case 4: return [2 /*return*/];
|
|
247
300
|
}
|
|
248
301
|
});
|
|
249
302
|
}); };
|
|
250
303
|
var getRoutes = function (request, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
251
|
-
var configService, config, result,
|
|
304
|
+
var configService, config, result, e_7;
|
|
252
305
|
return __generator(this, function (_a) {
|
|
253
306
|
switch (_a.label) {
|
|
254
307
|
case 0:
|
|
@@ -269,14 +322,14 @@ var getRoutes = function (request, options) { return __awaiter(void 0, void 0, v
|
|
|
269
322
|
result = _a.sent();
|
|
270
323
|
return [2 /*return*/, result.data];
|
|
271
324
|
case 3:
|
|
272
|
-
|
|
273
|
-
throw (0, parseError_1.parseBackendError)(
|
|
325
|
+
e_7 = _a.sent();
|
|
326
|
+
throw (0, parseError_1.parseBackendError)(e_7);
|
|
274
327
|
case 4: return [2 /*return*/];
|
|
275
328
|
}
|
|
276
329
|
});
|
|
277
330
|
}); };
|
|
278
331
|
var getStepTransaction = function (step, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
279
|
-
var configService, config, result,
|
|
332
|
+
var configService, config, result, e_8;
|
|
280
333
|
return __generator(this, function (_a) {
|
|
281
334
|
switch (_a.label) {
|
|
282
335
|
case 0:
|
|
@@ -297,8 +350,8 @@ var getStepTransaction = function (step, options) { return __awaiter(void 0, voi
|
|
|
297
350
|
result = _a.sent();
|
|
298
351
|
return [2 /*return*/, result.data];
|
|
299
352
|
case 3:
|
|
300
|
-
|
|
301
|
-
throw (0, parseError_1.parseBackendError)(
|
|
353
|
+
e_8 = _a.sent();
|
|
354
|
+
throw (0, parseError_1.parseBackendError)(e_8);
|
|
302
355
|
case 4: return [2 /*return*/];
|
|
303
356
|
}
|
|
304
357
|
});
|
|
@@ -341,6 +394,7 @@ exports.default = {
|
|
|
341
394
|
getPossibilities: getPossibilities,
|
|
342
395
|
getToken: getToken,
|
|
343
396
|
getQuote: getQuote,
|
|
397
|
+
getContractCallQuote: getContractCallQuote,
|
|
344
398
|
getStatus: getStatus,
|
|
345
399
|
getChains: getChains,
|
|
346
400
|
getRoutes: getRoutes,
|
|
@@ -41,6 +41,7 @@ var DefaultExecutionSettings = {
|
|
|
41
41
|
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
|
|
42
42
|
updateCallback: function () { },
|
|
43
43
|
switchChainHook: function () { return Promise.resolve(undefined); },
|
|
44
|
+
acceptSlippageUpdateHook: function () { return Promise.resolve(undefined); },
|
|
44
45
|
infiniteApproval: false,
|
|
45
46
|
};
|
|
46
47
|
var ConfigService = /** @class */ (function () {
|