@lifi/sdk 1.0.0 → 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 +28 -0
- package/LICENSE.md +201 -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 +14 -3
- 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/multicall.js +18 -3
- 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 +3 -3
- package/LICENSE +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
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.0](https://github.com/lifinance/sdk/compare/v1.0.2...v1.1.0) (2022-08-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add fee parameter and getContractCallQuote endpoint ([#92](https://github.com/lifinance/sdk/issues/92)) ([56695d6](https://github.com/lifinance/sdk/commit/56695d6026e99951a4518e45d1a4965f7546d204))
|
|
11
|
+
* add gasinformation to execution object ([#91](https://github.com/lifinance/sdk/issues/91)) ([f3a13b4](https://github.com/lifinance/sdk/commit/f3a13b4458db4c5dea245ae56f205a58b6cd00ed))
|
|
12
|
+
* expose get getRpcProvider ([#89](https://github.com/lifinance/sdk/issues/89)) ([750b675](https://github.com/lifinance/sdk/commit/750b675a6dbca0ae18361ee150f292a9ec820dfd))
|
|
13
|
+
* increase gasLimit or gasPrice on restart if necessary ([#90](https://github.com/lifinance/sdk/issues/90)) ([6f947d3](https://github.com/lifinance/sdk/commit/6f947d3b0b326f821fcee448636b65a10ee4f38a))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* build error ([#94](https://github.com/lifinance/sdk/issues/94)) ([810028e](https://github.com/lifinance/sdk/commit/810028e0d2fb7d09dd5b9d5829faab983df5ae5a))
|
|
19
|
+
* failing tests ([#93](https://github.com/lifinance/sdk/issues/93)) ([318ec7b](https://github.com/lifinance/sdk/commit/318ec7ba3bbe21dbcad38baba09ef9fcc38469bd))
|
|
20
|
+
* update execution state ([#88](https://github.com/lifinance/sdk/issues/88)) ([d974263](https://github.com/lifinance/sdk/commit/d9742636f5aeb77a3b4c1db5eecc6c6625812430))
|
|
21
|
+
|
|
22
|
+
### [1.0.2](https://github.com/lifinance/sdk/compare/v1.0.1...v1.0.2) (2022-07-15)
|
|
23
|
+
|
|
24
|
+
### [1.0.1](https://github.com/lifinance/sdk/compare/v1.0.0...v1.0.1) (2022-07-14)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* adjust approval messages ([f445021](https://github.com/lifinance/sdk/commit/f445021761bda2e4fd1d7eab90f0a04be4827280))
|
|
30
|
+
* handle more multicall failure cases ([#86](https://github.com/lifinance/sdk/issues/86)) ([f7acaca](https://github.com/lifinance/sdk/commit/f7acaca2ab48f58844ec331cb207fa6592488fb1))
|
|
31
|
+
* publishing script ([8c2f12a](https://github.com/lifinance/sdk/commit/8c2f12a7ee091547980f7622ba34fde8d548f606))
|
|
32
|
+
|
|
5
33
|
## [1.0.0](https://github.com/lifinance/sdk/compare/v1.0.0-beta.14...v1.0.0) (2022-07-12)
|
|
6
34
|
|
|
7
35
|
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
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;
|
|
@@ -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,19 +118,24 @@ 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];
|
|
@@ -131,31 +148,31 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
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
154
|
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
|
-
|
|
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];
|
|
149
166
|
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 =
|
|
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();
|
|
159
176
|
statusManager.updateProcess(step, crossChainProcess.type, 'FAILED', {
|
|
160
177
|
error: {
|
|
161
178
|
message: error.message,
|
|
@@ -165,22 +182,22 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
165
182
|
});
|
|
166
183
|
statusManager.updateExecution(step, 'FAILED');
|
|
167
184
|
throw error;
|
|
168
|
-
case
|
|
169
|
-
case
|
|
185
|
+
case 19: return [3 /*break*/, 20];
|
|
186
|
+
case 20:
|
|
170
187
|
statusManager.updateProcess(step, crossChainProcess.type, 'DONE');
|
|
171
188
|
receivingChainProcess = statusManager.findOrCreateProcess('RECEIVING_CHAIN', step, 'PENDING');
|
|
172
|
-
|
|
173
|
-
case
|
|
174
|
-
|
|
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
|
-
|
|
197
|
+
statusResponse = _g.sent();
|
|
198
|
+
return [3 /*break*/, 24];
|
|
199
|
+
case 23:
|
|
200
|
+
e_2 = _g.sent();
|
|
184
201
|
statusManager.updateProcess(step, receivingChainProcess.type, 'FAILED', {
|
|
185
202
|
error: {
|
|
186
203
|
code: errors_1.LifiErrorCode.TransactionFailed,
|
|
@@ -190,21 +207,22 @@ var BridgeExecutionManager = /** @class */ (function () {
|
|
|
190
207
|
});
|
|
191
208
|
statusManager.updateExecution(step, 'FAILED');
|
|
192
209
|
throw e_2;
|
|
193
|
-
case
|
|
210
|
+
case 24:
|
|
194
211
|
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];
|