@lifi/sdk 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -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/allowance.execute.js +9 -9
- package/dist/execution/bridges/bridge.execute.js +70 -52
- package/dist/execution/exchanges/swap.execute.js +75 -57
- package/dist/execution/stepComparison.d.ts +14 -0
- package/dist/execution/stepComparison.js +81 -0
- package/dist/execution/switchChain.js +2 -2
- 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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.1.1](https://github.com/lifinance/sdk/compare/v1.1.0...v1.1.1) (2022-08-03)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* statusmanager reference issue ([#96](https://github.com/lifinance/sdk/issues/96)) ([0e4fe27](https://github.com/lifinance/sdk/commit/0e4fe27c58d4911347cd45163657aa3d8be9066e))
|
|
11
|
+
|
|
12
|
+
## [1.1.0](https://github.com/lifinance/sdk/compare/v1.0.2...v1.1.0) (2022-08-02)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add fee parameter and getContractCallQuote endpoint ([#92](https://github.com/lifinance/sdk/issues/92)) ([56695d6](https://github.com/lifinance/sdk/commit/56695d6026e99951a4518e45d1a4965f7546d204))
|
|
18
|
+
* add gasinformation to execution object ([#91](https://github.com/lifinance/sdk/issues/91)) ([f3a13b4](https://github.com/lifinance/sdk/commit/f3a13b4458db4c5dea245ae56f205a58b6cd00ed))
|
|
19
|
+
* expose get getRpcProvider ([#89](https://github.com/lifinance/sdk/issues/89)) ([750b675](https://github.com/lifinance/sdk/commit/750b675a6dbca0ae18361ee150f292a9ec820dfd))
|
|
20
|
+
* increase gasLimit or gasPrice on restart if necessary ([#90](https://github.com/lifinance/sdk/issues/90)) ([6f947d3](https://github.com/lifinance/sdk/commit/6f947d3b0b326f821fcee448636b65a10ee4f38a))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* build error ([#94](https://github.com/lifinance/sdk/issues/94)) ([810028e](https://github.com/lifinance/sdk/commit/810028e0d2fb7d09dd5b9d5829faab983df5ae5a))
|
|
26
|
+
* failing tests ([#93](https://github.com/lifinance/sdk/issues/93)) ([318ec7b](https://github.com/lifinance/sdk/commit/318ec7ba3bbe21dbcad38baba09ef9fcc38469bd))
|
|
27
|
+
* update execution state ([#88](https://github.com/lifinance/sdk/issues/88)) ([d974263](https://github.com/lifinance/sdk/commit/d9742636f5aeb77a3b4c1db5eecc6c6625812430))
|
|
28
|
+
|
|
29
|
+
### [1.0.2](https://github.com/lifinance/sdk/compare/v1.0.1...v1.0.2) (2022-07-15)
|
|
30
|
+
|
|
5
31
|
### [1.0.1](https://github.com/lifinance/sdk/compare/v1.0.0...v1.0.1) (2022-07-14)
|
|
6
32
|
|
|
7
33
|
|
package/dist/Lifi.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Chain, ChainId, ChainKey, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, Route, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
1
|
+
import { Chain, ChainId, ChainKey, ContractCallQuoteRequest, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, Route, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
2
2
|
import { Signer } from 'ethers';
|
|
3
|
+
import { FallbackProvider } from '@ethersproject/providers';
|
|
3
4
|
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
4
5
|
import { Config, ConfigUpdate, ExecutionSettings, RevokeTokenData } from './types';
|
|
5
6
|
export default class LIFI {
|
|
@@ -17,6 +18,13 @@ export default class LIFI {
|
|
|
17
18
|
* @return {Promise<Config>} - The config object
|
|
18
19
|
*/
|
|
19
20
|
getConfigAsync: () => Promise<Config>;
|
|
21
|
+
/**
|
|
22
|
+
* Get an instance of a provider for a specific cahin
|
|
23
|
+
* @param {number} chainId - Id of the chain the provider is for
|
|
24
|
+
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
25
|
+
* @return {FallbackProvider} The provider for the given chain
|
|
26
|
+
*/
|
|
27
|
+
getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
|
|
20
28
|
/**
|
|
21
29
|
* Set a new confuration for the SDK
|
|
22
30
|
* @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
|
|
@@ -43,6 +51,12 @@ export default class LIFI {
|
|
|
43
51
|
* @throws {LifiError} - Throws a LifiError if request fails
|
|
44
52
|
*/
|
|
45
53
|
getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<Step>;
|
|
54
|
+
/**
|
|
55
|
+
* Get a quote for a destination contract call
|
|
56
|
+
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
57
|
+
* @throws {LifiError} - Throws a LifiError if request fails
|
|
58
|
+
*/
|
|
59
|
+
getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<Step>;
|
|
46
60
|
/**
|
|
47
61
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
48
62
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
package/dist/Lifi.js
CHANGED
|
@@ -52,6 +52,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
var allowance_1 = require("./allowance");
|
|
54
54
|
var balances_1 = __importDefault(require("./balances"));
|
|
55
|
+
var connectors_1 = require("./connectors");
|
|
55
56
|
var StatusManager_1 = require("./execution/StatusManager");
|
|
56
57
|
var StepExecutor_1 = require("./execution/StepExecutor");
|
|
57
58
|
var ApiService_1 = __importDefault(require("./services/ApiService"));
|
|
@@ -59,6 +60,7 @@ var ChainsService_1 = __importDefault(require("./services/ChainsService"));
|
|
|
59
60
|
var ConfigService_1 = __importDefault(require("./services/ConfigService"));
|
|
60
61
|
var typeguards_1 = require("./typeguards");
|
|
61
62
|
var errors_1 = require("./utils/errors");
|
|
63
|
+
var preRestart_1 = require("./utils/preRestart");
|
|
62
64
|
var utils_1 = require("./utils/utils");
|
|
63
65
|
var LIFI = /** @class */ (function () {
|
|
64
66
|
function LIFI(configUpdate) {
|
|
@@ -78,6 +80,16 @@ var LIFI = /** @class */ (function () {
|
|
|
78
80
|
this.getConfigAsync = function () {
|
|
79
81
|
return _this.configService.getConfigAsync();
|
|
80
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Get an instance of a provider for a specific cahin
|
|
85
|
+
* @param {number} chainId - Id of the chain the provider is for
|
|
86
|
+
* @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
|
|
87
|
+
* @return {FallbackProvider} The provider for the given chain
|
|
88
|
+
*/
|
|
89
|
+
this.getRpcProvider = function (chainId, archive) {
|
|
90
|
+
if (archive === void 0) { archive = false; }
|
|
91
|
+
return (0, connectors_1.getRpcProvider)(chainId, archive);
|
|
92
|
+
};
|
|
81
93
|
/**
|
|
82
94
|
* Set a new confuration for the SDK
|
|
83
95
|
* @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
|
|
@@ -118,6 +130,16 @@ var LIFI = /** @class */ (function () {
|
|
|
118
130
|
return [2 /*return*/, ApiService_1.default.getQuote(request, options)];
|
|
119
131
|
});
|
|
120
132
|
}); };
|
|
133
|
+
/**
|
|
134
|
+
* Get a quote for a destination contract call
|
|
135
|
+
* @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
|
|
136
|
+
* @throws {LifiError} - Throws a LifiError if request fails
|
|
137
|
+
*/
|
|
138
|
+
this.getContractCallQuote = function (request, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
139
|
+
return __generator(this, function (_a) {
|
|
140
|
+
return [2 /*return*/, ApiService_1.default.getContractCallQuote(request, options)];
|
|
141
|
+
});
|
|
142
|
+
}); };
|
|
121
143
|
/**
|
|
122
144
|
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
123
145
|
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
@@ -239,9 +261,8 @@ var LIFI = /** @class */ (function () {
|
|
|
239
261
|
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
240
262
|
*/
|
|
241
263
|
this.resumeRoute = function (signer, route, settings) { return __awaiter(_this, void 0, void 0, function () {
|
|
242
|
-
var clonedRoute, activeRoute, executionHalted
|
|
243
|
-
|
|
244
|
-
return __generator(this, function (_c) {
|
|
264
|
+
var clonedRoute, activeRoute, executionHalted;
|
|
265
|
+
return __generator(this, function (_a) {
|
|
245
266
|
clonedRoute = (0, utils_1.deepClone)(route) // deep clone to prevent side effects
|
|
246
267
|
;
|
|
247
268
|
activeRoute = this.activeRouteDictionary[clonedRoute.id];
|
|
@@ -251,13 +272,7 @@ var LIFI = /** @class */ (function () {
|
|
|
251
272
|
return [2 /*return*/, clonedRoute];
|
|
252
273
|
}
|
|
253
274
|
}
|
|
254
|
-
|
|
255
|
-
for (index = 0; index < clonedRoute.steps.length; index++) {
|
|
256
|
-
stepHasFailed = ((_a = clonedRoute.steps[index].execution) === null || _a === void 0 ? void 0 : _a.status) === 'FAILED';
|
|
257
|
-
if (stepHasFailed) {
|
|
258
|
-
(_b = clonedRoute.steps[index].execution) === null || _b === void 0 ? void 0 : _b.process.pop();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
275
|
+
(0, preRestart_1.handlePreRestart)(clonedRoute);
|
|
261
276
|
return [2 /*return*/, this.executeSteps(signer, clonedRoute, settings)];
|
|
262
277
|
});
|
|
263
278
|
}); };
|
|
@@ -3,6 +3,8 @@ interface Receipt {
|
|
|
3
3
|
fromAmount?: string;
|
|
4
4
|
toAmount?: string;
|
|
5
5
|
toToken?: Token;
|
|
6
|
+
gasUsed?: string;
|
|
7
|
+
gasPrice?: string;
|
|
6
8
|
}
|
|
7
9
|
declare type InternalUpdateRouteCallback = (route: Route) => void;
|
|
8
10
|
declare type OptionalParameters = Partial<Pick<Process, 'doneAt' | 'failedAt' | 'txHash' | 'txLink' | 'error' | 'substatus' | 'substatusMessage'>>;
|
|
@@ -57,7 +59,7 @@ export declare class StatusManager {
|
|
|
57
59
|
* @return {void}
|
|
58
60
|
*/
|
|
59
61
|
removeProcess: (step: Step, type: ProcessType) => void;
|
|
60
|
-
|
|
62
|
+
updateStepInRoute: (step: Step) => Step;
|
|
61
63
|
setShouldUpdate(value: boolean): void;
|
|
62
64
|
}
|
|
63
65
|
export {};
|
|
@@ -24,6 +24,7 @@ var StatusManager = /** @class */ (function () {
|
|
|
24
24
|
var currentExecution = step.execution || (0, utils_1.deepClone)(types_1.emptyExecution);
|
|
25
25
|
if (!step.execution) {
|
|
26
26
|
step.execution = currentExecution;
|
|
27
|
+
step.execution.status = 'PENDING';
|
|
27
28
|
_this.updateStepInRoute(step);
|
|
28
29
|
}
|
|
29
30
|
return currentExecution;
|
|
@@ -63,6 +64,9 @@ var StatusManager = /** @class */ (function () {
|
|
|
63
64
|
*/
|
|
64
65
|
this.updateProcess = function (step, type, status, params) {
|
|
65
66
|
var _a;
|
|
67
|
+
if (!step.execution) {
|
|
68
|
+
throw new Error("Can't update an empty step execution.");
|
|
69
|
+
}
|
|
66
70
|
var currentProcess = (_a = step === null || step === void 0 ? void 0 : step.execution) === null || _a === void 0 ? void 0 : _a.process.find(function (p) { return p.type === type; });
|
|
67
71
|
if (!currentProcess) {
|
|
68
72
|
throw new Error("Can't find a process for the given type.");
|
|
@@ -73,10 +77,20 @@ var StatusManager = /** @class */ (function () {
|
|
|
73
77
|
break;
|
|
74
78
|
case 'FAILED':
|
|
75
79
|
currentProcess.doneAt = Date.now();
|
|
80
|
+
step.execution.status = 'FAILED';
|
|
76
81
|
break;
|
|
77
82
|
case 'DONE':
|
|
78
83
|
currentProcess.doneAt = Date.now();
|
|
79
84
|
break;
|
|
85
|
+
case 'PENDING':
|
|
86
|
+
step.execution.status = 'PENDING';
|
|
87
|
+
break;
|
|
88
|
+
case 'ACTION_REQUIRED':
|
|
89
|
+
step.execution.status = 'ACTION_REQUIRED';
|
|
90
|
+
break;
|
|
91
|
+
case 'CHAIN_SWITCH_REQUIRED':
|
|
92
|
+
step.execution.status = 'CHAIN_SWITCH_REQUIRED';
|
|
93
|
+
break;
|
|
80
94
|
default:
|
|
81
95
|
break;
|
|
82
96
|
}
|
|
@@ -108,7 +122,7 @@ var StatusManager = /** @class */ (function () {
|
|
|
108
122
|
};
|
|
109
123
|
this.updateStepInRoute = function (step) {
|
|
110
124
|
if (!_this.shouldUpdate) {
|
|
111
|
-
return;
|
|
125
|
+
return step;
|
|
112
126
|
}
|
|
113
127
|
var stepIndex = _this.route.steps.findIndex(function (routeStep) { return routeStep.id === step.id; });
|
|
114
128
|
if (stepIndex === -1) {
|
|
@@ -117,6 +131,7 @@ var StatusManager = /** @class */ (function () {
|
|
|
117
131
|
_this.route.steps[stepIndex] = Object.assign(_this.route.steps[stepIndex], step);
|
|
118
132
|
_this.settings.updateCallback(_this.route);
|
|
119
133
|
_this.internalUpdateRouteCallback(_this.route);
|
|
134
|
+
return _this.route.steps[stepIndex];
|
|
120
135
|
};
|
|
121
136
|
this.route = route;
|
|
122
137
|
this.settings = settings;
|
|
@@ -60,15 +60,15 @@ var checkAllowance = function (signer, step, chain, token, amount, spenderAddres
|
|
|
60
60
|
case 1:
|
|
61
61
|
_a.trys.push([1, 10, , 15]);
|
|
62
62
|
if (!allowanceProcess.txHash) return [3 /*break*/, 3];
|
|
63
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'PENDING');
|
|
63
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING');
|
|
64
64
|
return [4 /*yield*/, (0, getProvider_1.getProvider)(signer).waitForTransaction(allowanceProcess.txHash)];
|
|
65
65
|
case 2:
|
|
66
66
|
_a.sent();
|
|
67
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
67
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
68
68
|
return [3 /*break*/, 9];
|
|
69
69
|
case 3:
|
|
70
70
|
if (!(allowanceProcess.status === 'DONE')) return [3 /*break*/, 4];
|
|
71
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
71
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
72
72
|
return [3 /*break*/, 9];
|
|
73
73
|
case 4: return [4 /*yield*/, (0, utils_1.getApproved)(signer, token.address, spenderAddress)];
|
|
74
74
|
case 5:
|
|
@@ -86,7 +86,7 @@ var checkAllowance = function (signer, step, chain, token, amount, spenderAddres
|
|
|
86
86
|
case 6:
|
|
87
87
|
approveTx = _a.sent();
|
|
88
88
|
// update currentExecution
|
|
89
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
89
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
90
90
|
txHash: approveTx.hash,
|
|
91
91
|
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + approveTx.hash,
|
|
92
92
|
});
|
|
@@ -95,10 +95,10 @@ var checkAllowance = function (signer, step, chain, token, amount, spenderAddres
|
|
|
95
95
|
case 7:
|
|
96
96
|
// wait for transcation
|
|
97
97
|
_a.sent();
|
|
98
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
98
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
99
99
|
return [3 /*break*/, 9];
|
|
100
100
|
case 8:
|
|
101
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
101
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
102
102
|
_a.label = 9;
|
|
103
103
|
case 9: return [3 /*break*/, 15];
|
|
104
104
|
case 10:
|
|
@@ -111,7 +111,7 @@ var checkAllowance = function (signer, step, chain, token, amount, spenderAddres
|
|
|
111
111
|
case 12: return [4 /*yield*/, (0, parseError_1.parseError)(e_1, step, allowanceProcess)];
|
|
112
112
|
case 13:
|
|
113
113
|
error = _a.sent();
|
|
114
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
|
|
114
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
|
|
115
115
|
error: {
|
|
116
116
|
message: error.message,
|
|
117
117
|
htmlMessage: error.htmlMessage,
|
|
@@ -133,14 +133,14 @@ var transactionReplaced = function (replacementTx, allowanceProcess, step, chain
|
|
|
133
133
|
switch (_a.label) {
|
|
134
134
|
case 0:
|
|
135
135
|
_a.trys.push([0, 2, , 5]);
|
|
136
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
136
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
|
|
137
137
|
txHash: replacementTx.hash,
|
|
138
138
|
txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + replacementTx.hash,
|
|
139
139
|
});
|
|
140
140
|
return [4 /*yield*/, replacementTx.wait()];
|
|
141
141
|
case 1:
|
|
142
142
|
_a.sent();
|
|
143
|
-
statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
143
|
+
allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
|
|
144
144
|
return [3 /*break*/, 5];
|
|
145
145
|
case 2:
|
|
146
146
|
e_2 = _a.sent();
|
|
@@ -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 BridgeExecutionManager = /** @class */ (function () {
|
|
@@ -61,23 +73,23 @@ var BridgeExecutionManager = /** @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, toChain, oldCrossProcess, crossChainProcess, tx, personalizedStep, transactionRequest, updatedSigner, e_1, error, receivingChainProcess, statusResponse, e_2;
|
|
65
|
-
var
|
|
66
|
-
return __generator(this, function (
|
|
67
|
-
switch (
|
|
76
|
+
var action, estimate, chainsService, fromChain, toChain, oldCrossProcess, crossChainProcess, tx, personalizedStep, updatedStep, _b, transactionRequest, updatedSigner, e_1, error, receivingChainProcess, statusResponse, e_2;
|
|
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);
|
|
71
83
|
chainsService = ChainsService_1.default.getInstance();
|
|
72
84
|
return [4 /*yield*/, chainsService.getChainById(action.fromChainId)];
|
|
73
85
|
case 1:
|
|
74
|
-
fromChain =
|
|
86
|
+
fromChain = _g.sent();
|
|
75
87
|
return [4 /*yield*/, chainsService.getChainById(action.toChainId)
|
|
76
88
|
// STEP 1: Check Allowance ////////////////////////////////////////////////
|
|
77
89
|
// approval still needed?
|
|
78
90
|
];
|
|
79
91
|
case 2:
|
|
80
|
-
toChain =
|
|
92
|
+
toChain = _g.sent();
|
|
81
93
|
oldCrossProcess = step.execution.process.find(function (p) { return p.type === 'CROSS_CHAIN'; });
|
|
82
94
|
if (!!(oldCrossProcess === null || oldCrossProcess === void 0 ? void 0 : oldCrossProcess.txHash)) return [3 /*break*/, 4];
|
|
83
95
|
if (!(action.fromToken.address !== ethers_1.constants.AddressZero)) return [3 /*break*/, 4];
|
|
@@ -85,20 +97,20 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
85
97
|
return [4 /*yield*/, (0, allowance_execute_1.checkAllowance)(signer, step, fromChain, action.fromToken, action.fromAmount, estimate.approvalAddress, statusManager, settings.infiniteApproval, this.shouldContinue)];
|
|
86
98
|
case 3:
|
|
87
99
|
// Check Token Approval only if fromToken is not the native token => no approval needed in that case
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
_g.sent();
|
|
101
|
+
_g.label = 4;
|
|
90
102
|
case 4:
|
|
91
103
|
crossChainProcess = statusManager.findOrCreateProcess('CROSS_CHAIN', step);
|
|
92
|
-
|
|
104
|
+
_g.label = 5;
|
|
93
105
|
case 5:
|
|
94
|
-
|
|
106
|
+
_g.trys.push([5, 16, , 20]);
|
|
95
107
|
tx = void 0;
|
|
96
108
|
if (!crossChainProcess.txHash) return [3 /*break*/, 7];
|
|
97
109
|
return [4 /*yield*/, (0, getProvider_1.getProvider)(signer).getTransaction(crossChainProcess.txHash)];
|
|
98
110
|
case 6:
|
|
99
111
|
// load exiting transaction
|
|
100
|
-
tx =
|
|
101
|
-
return [3 /*break*/,
|
|
112
|
+
tx = _g.sent();
|
|
113
|
+
return [3 /*break*/, 14];
|
|
102
114
|
case 7:
|
|
103
115
|
// check balance
|
|
104
116
|
return [4 /*yield*/, (0, balanceCheck_execute_1.balanceCheck)(signer, step)
|
|
@@ -106,57 +118,62 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
106
118
|
];
|
|
107
119
|
case 8:
|
|
108
120
|
// check balance
|
|
109
|
-
|
|
121
|
+
_g.sent();
|
|
110
122
|
return [4 /*yield*/, (0, utils_1.personalizeStep)(signer, step)];
|
|
111
123
|
case 9:
|
|
112
|
-
personalizedStep =
|
|
124
|
+
personalizedStep = _g.sent();
|
|
113
125
|
return [4 /*yield*/, ApiService_1.default.getStepTransaction(personalizedStep)];
|
|
114
126
|
case 10:
|
|
115
|
-
|
|
127
|
+
updatedStep = _g.sent();
|
|
128
|
+
_b = [{}];
|
|
129
|
+
return [4 /*yield*/, (0, stepComparison_1.stepComparison)(statusManager, personalizedStep, updatedStep, settings.acceptSlippageUpdateHook, this.shouldContinue)];
|
|
130
|
+
case 11:
|
|
131
|
+
step = __assign.apply(void 0, [__assign.apply(void 0, _b.concat([(_g.sent())])), { execution: step.execution }]);
|
|
132
|
+
transactionRequest = step.transactionRequest;
|
|
116
133
|
if (!transactionRequest) {
|
|
117
134
|
throw new errors_1.TransactionError(errors_1.LifiErrorCode.TransactionUnprepared, 'Unable to prepare transaction.');
|
|
118
135
|
}
|
|
119
136
|
return [4 /*yield*/, (0, switchChain_1.switchChain)(signer, statusManager, step, settings.switchChainHook, this.shouldContinue)];
|
|
120
|
-
case
|
|
121
|
-
updatedSigner =
|
|
137
|
+
case 12:
|
|
138
|
+
updatedSigner = _g.sent();
|
|
122
139
|
if (!updatedSigner) {
|
|
123
140
|
// chain switch was not successful, stop execution here
|
|
124
141
|
return [2 /*return*/, step.execution];
|
|
125
142
|
}
|
|
126
143
|
signer = updatedSigner;
|
|
127
|
-
statusManager.updateProcess(step, crossChainProcess.type, 'ACTION_REQUIRED');
|
|
144
|
+
crossChainProcess = statusManager.updateProcess(step, crossChainProcess.type, 'ACTION_REQUIRED');
|
|
128
145
|
if (!this.shouldContinue) {
|
|
129
146
|
return [2 /*return*/, step.execution];
|
|
130
147
|
}
|
|
131
148
|
return [4 /*yield*/, signer.sendTransaction(transactionRequest)
|
|
132
149
|
// STEP 4: Wait for Transaction ///////////////////////////////////////////
|
|
133
150
|
];
|
|
134
|
-
case
|
|
135
|
-
tx =
|
|
151
|
+
case 13:
|
|
152
|
+
tx = _g.sent();
|
|
136
153
|
// STEP 4: Wait for Transaction ///////////////////////////////////////////
|
|
137
|
-
statusManager.updateProcess(step, crossChainProcess.type, 'PENDING', {
|
|
154
|
+
crossChainProcess = statusManager.updateProcess(step, crossChainProcess.type, 'PENDING', {
|
|
138
155
|
txHash: tx.hash,
|
|
139
156
|
txLink: fromChain.metamask.blockExplorerUrls[0] + 'tx/' + tx.hash,
|
|
140
157
|
});
|
|
141
|
-
|
|
142
|
-
case
|
|
143
|
-
case 14:
|
|
144
|
-
_f.sent();
|
|
145
|
-
return [3 /*break*/, 19];
|
|
158
|
+
_g.label = 14;
|
|
159
|
+
case 14: return [4 /*yield*/, tx.wait()];
|
|
146
160
|
case 15:
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
_g.sent();
|
|
162
|
+
return [3 /*break*/, 20];
|
|
163
|
+
case 16:
|
|
164
|
+
e_1 = _g.sent();
|
|
165
|
+
if (!(e_1.code === 'TRANSACTION_REPLACED' && e_1.replacement)) return [3 /*break*/, 17];
|
|
166
|
+
crossChainProcess = statusManager.updateProcess(step, crossChainProcess.type, 'PENDING', {
|
|
150
167
|
txHash: e_1.replacement.hash,
|
|
151
168
|
txLink: fromChain.metamask.blockExplorerUrls[0] +
|
|
152
169
|
'tx/' +
|
|
153
170
|
e_1.replacement.hash,
|
|
154
171
|
});
|
|
155
|
-
return [3 /*break*/,
|
|
156
|
-
case
|
|
157
|
-
case
|
|
158
|
-
error =
|
|
159
|
-
statusManager.updateProcess(step, crossChainProcess.type, 'FAILED', {
|
|
172
|
+
return [3 /*break*/, 19];
|
|
173
|
+
case 17: return [4 /*yield*/, (0, parseError_1.parseError)(e_1, step, crossChainProcess)];
|
|
174
|
+
case 18:
|
|
175
|
+
error = _g.sent();
|
|
176
|
+
crossChainProcess = statusManager.updateProcess(step, crossChainProcess.type, 'FAILED', {
|
|
160
177
|
error: {
|
|
161
178
|
message: error.message,
|
|
162
179
|
htmlMessage: error.htmlMessage,
|
|
@@ -165,23 +182,23 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
165
182
|
});
|
|
166
183
|
statusManager.updateExecution(step, 'FAILED');
|
|
167
184
|
throw error;
|
|
168
|
-
case
|
|
169
|
-
case 19:
|
|
170
|
-
statusManager.updateProcess(step, crossChainProcess.type, 'DONE');
|
|
171
|
-
receivingChainProcess = statusManager.findOrCreateProcess('RECEIVING_CHAIN', step, 'PENDING');
|
|
172
|
-
_f.label = 20;
|
|
185
|
+
case 19: return [3 /*break*/, 20];
|
|
173
186
|
case 20:
|
|
174
|
-
|
|
187
|
+
crossChainProcess = statusManager.updateProcess(step, crossChainProcess.type, 'DONE');
|
|
188
|
+
receivingChainProcess = statusManager.findOrCreateProcess('RECEIVING_CHAIN', step, 'PENDING');
|
|
189
|
+
_g.label = 21;
|
|
190
|
+
case 21:
|
|
191
|
+
_g.trys.push([21, 23, , 24]);
|
|
175
192
|
if (!crossChainProcess.txHash) {
|
|
176
193
|
throw new Error('Transaction hash is undefined.');
|
|
177
194
|
}
|
|
178
195
|
return [4 /*yield*/, (0, utils_2.waitForReceivingTransaction)(crossChainProcess.txHash, statusManager, receivingChainProcess.type, step)];
|
|
179
|
-
case 21:
|
|
180
|
-
statusResponse = _f.sent();
|
|
181
|
-
return [3 /*break*/, 23];
|
|
182
196
|
case 22:
|
|
183
|
-
|
|
184
|
-
|
|
197
|
+
statusResponse = _g.sent();
|
|
198
|
+
return [3 /*break*/, 24];
|
|
199
|
+
case 23:
|
|
200
|
+
e_2 = _g.sent();
|
|
201
|
+
receivingChainProcess = statusManager.updateProcess(step, receivingChainProcess.type, 'FAILED', {
|
|
185
202
|
error: {
|
|
186
203
|
code: errors_1.LifiErrorCode.TransactionFailed,
|
|
187
204
|
message: 'Failed while waiting for receiving chain.',
|
|
@@ -190,21 +207,22 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
190
207
|
});
|
|
191
208
|
statusManager.updateExecution(step, 'FAILED');
|
|
192
209
|
throw e_2;
|
|
193
|
-
case
|
|
194
|
-
statusManager.updateProcess(step, receivingChainProcess.type, 'DONE', {
|
|
210
|
+
case 24:
|
|
211
|
+
receivingChainProcess = statusManager.updateProcess(step, receivingChainProcess.type, 'DONE', {
|
|
195
212
|
substatus: statusResponse.substatus,
|
|
196
213
|
substatusMessage: statusResponse.substatusMessage ||
|
|
197
214
|
(0, utils_2.getSubstatusMessage)(statusResponse.status, statusResponse.substatus),
|
|
198
|
-
txHash: (
|
|
215
|
+
txHash: (_c = statusResponse.receiving) === null || _c === void 0 ? void 0 : _c.txHash,
|
|
199
216
|
txLink: toChain.metamask.blockExplorerUrls[0] +
|
|
200
217
|
'tx/' +
|
|
201
|
-
((
|
|
218
|
+
((_d = statusResponse.receiving) === null || _d === void 0 ? void 0 : _d.txHash),
|
|
202
219
|
});
|
|
203
220
|
statusManager.updateExecution(step, 'DONE', {
|
|
204
221
|
fromAmount: statusResponse.sending.amount,
|
|
205
|
-
toAmount: (
|
|
206
|
-
toToken: (
|
|
207
|
-
|
|
222
|
+
toAmount: (_e = statusResponse.receiving) === null || _e === void 0 ? void 0 : _e.amount,
|
|
223
|
+
toToken: (_f = statusResponse.receiving) === null || _f === void 0 ? void 0 : _f.token,
|
|
224
|
+
gasUsed: statusResponse.sending.gasUsed,
|
|
225
|
+
gasPrice: statusResponse.sending.gasPrice,
|
|
208
226
|
});
|
|
209
227
|
// DONE
|
|
210
228
|
return [2 /*return*/, step.execution];
|