@lifi/sdk 1.1.2 → 1.1.3
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 +7 -0
- package/dist/Lifi.js +179 -285
- package/dist/allowance/index.js +56 -148
- package/dist/allowance/utils.js +51 -116
- package/dist/balances/index.js +29 -92
- package/dist/balances/utils.js +108 -218
- package/dist/connectors.js +50 -133
- package/dist/execution/StatusManager.js +34 -41
- package/dist/execution/StepExecutor.js +54 -123
- package/dist/execution/allowance.execute.js +76 -142
- package/dist/execution/balanceCheck.execute.js +29 -74
- package/dist/execution/bridges/bridge.execute.js +132 -221
- package/dist/execution/exchanges/swap.execute.js +142 -225
- package/dist/execution/index.js +1 -17
- package/dist/execution/stepComparison.js +22 -61
- package/dist/execution/switchChain.js +33 -81
- package/dist/execution/utils.js +60 -119
- package/dist/helpers.js +15 -53
- package/dist/index.js +6 -25
- package/dist/services/ApiService.js +248 -385
- package/dist/services/ChainsService.js +29 -89
- package/dist/services/ConfigService.js +47 -86
- package/dist/typeguards.js +13 -21
- package/dist/types/ERC20.js +1 -4
- package/dist/types/index.js +4 -22
- package/dist/types/internal.types.js +1 -2
- package/dist/utils/errors.js +47 -93
- package/dist/utils/getProvider.js +3 -7
- package/dist/utils/multicall.js +61 -117
- package/dist/utils/parseError.js +73 -141
- package/dist/utils/preRestart.js +14 -21
- package/dist/utils/utils.js +47 -130
- package/package.json +1 -1
package/dist/utils/utils.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,90 +7,45 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
8
|
});
|
|
21
9
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.isNativeTokenAddress = exports.isZeroAddress = exports.loadTransactionReceipt = exports.repeatUntilDone = exports.formatTokenAmountOnly = exports.splitListIntoChunks = exports.personalizeStep = exports.sleep = exports.deepClone = void 0;
|
|
54
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
55
|
-
var ethers_1 = require("ethers");
|
|
56
|
-
var connectors_1 = require("../connectors");
|
|
57
|
-
var deepClone = function (src) {
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
import { constants } from 'ethers';
|
|
12
|
+
import { getRpcProvider } from '../connectors';
|
|
13
|
+
export const deepClone = (src) => {
|
|
58
14
|
return JSON.parse(JSON.stringify(src));
|
|
59
15
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return new Promise(function (resolve) {
|
|
16
|
+
export const sleep = (mills) => {
|
|
17
|
+
return new Promise((resolve) => {
|
|
63
18
|
setTimeout(resolve, mills);
|
|
64
19
|
});
|
|
65
20
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
var splitListIntoChunks = function (list, chunkSize) {
|
|
86
|
-
return list.reduce(function (resultList, item, index) {
|
|
87
|
-
var chunkIndex = Math.floor(index / chunkSize);
|
|
88
|
-
if (!resultList[chunkIndex]) {
|
|
89
|
-
resultList[chunkIndex] = []; // start a new chunk
|
|
90
|
-
}
|
|
91
|
-
resultList[chunkIndex].push(item);
|
|
92
|
-
return resultList;
|
|
93
|
-
}, []);
|
|
94
|
-
};
|
|
95
|
-
exports.splitListIntoChunks = splitListIntoChunks;
|
|
96
|
-
var formatTokenAmountOnly = function (token, amount) {
|
|
21
|
+
export const personalizeStep = (signer, step) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
if (step.action.toAddress && step.action.fromAddress) {
|
|
23
|
+
return step;
|
|
24
|
+
}
|
|
25
|
+
const address = yield signer.getAddress();
|
|
26
|
+
const fromAddress = step.action.fromAddress || address;
|
|
27
|
+
const toAddress = step.action.toAddress || address;
|
|
28
|
+
return Object.assign(Object.assign({}, step), { action: Object.assign(Object.assign({}, step.action), { fromAddress,
|
|
29
|
+
toAddress }) });
|
|
30
|
+
});
|
|
31
|
+
export const splitListIntoChunks = (list, chunkSize) => list.reduce((resultList, item, index) => {
|
|
32
|
+
const chunkIndex = Math.floor(index / chunkSize);
|
|
33
|
+
if (!resultList[chunkIndex]) {
|
|
34
|
+
resultList[chunkIndex] = []; // start a new chunk
|
|
35
|
+
}
|
|
36
|
+
resultList[chunkIndex].push(item);
|
|
37
|
+
return resultList;
|
|
38
|
+
}, []);
|
|
39
|
+
export const formatTokenAmountOnly = (token, amount) => {
|
|
97
40
|
if (!amount) {
|
|
98
41
|
return '0.0';
|
|
99
42
|
}
|
|
100
|
-
|
|
43
|
+
let floated;
|
|
101
44
|
if (typeof amount === 'string') {
|
|
102
45
|
if (amount === '0') {
|
|
103
46
|
return '0.0';
|
|
104
47
|
}
|
|
105
|
-
floated = new
|
|
48
|
+
floated = new BigNumber(amount).shiftedBy(-token.decimals);
|
|
106
49
|
}
|
|
107
50
|
else {
|
|
108
51
|
floated = amount;
|
|
@@ -111,73 +54,48 @@ var formatTokenAmountOnly = function (token, amount) {
|
|
|
111
54
|
}
|
|
112
55
|
}
|
|
113
56
|
// show at least 4 decimal places and at least two non-zero digests
|
|
114
|
-
|
|
57
|
+
let decimalPlaces = 3;
|
|
115
58
|
while (floated.lt(1 / Math.pow(10, decimalPlaces))) {
|
|
116
59
|
decimalPlaces++;
|
|
117
60
|
}
|
|
118
61
|
return floated.toFixed(decimalPlaces + 1, 1);
|
|
119
62
|
};
|
|
120
|
-
exports.formatTokenAmountOnly = formatTokenAmountOnly;
|
|
121
63
|
/**
|
|
122
64
|
* Repeatedly calls a given asynchronous function until it resolves with a value
|
|
123
65
|
* @param toRepeat The function that should be repeated
|
|
124
66
|
* @param timeout The timeout in milliseconds between retries, defaults to 5000
|
|
125
67
|
* @returns The result of the toRepeat function
|
|
126
68
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
result = _a.sent();
|
|
138
|
-
if (!!result) return [3 /*break*/, 3];
|
|
139
|
-
return [4 /*yield*/, (0, exports.sleep)(timeout)];
|
|
140
|
-
case 2:
|
|
141
|
-
_a.sent();
|
|
142
|
-
_a.label = 3;
|
|
143
|
-
case 3: return [3 /*break*/, 0];
|
|
144
|
-
case 4: return [2 /*return*/, result];
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
exports.repeatUntilDone = repeatUntilDone;
|
|
69
|
+
export const repeatUntilDone = (toRepeat, timeout = 5000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
let result;
|
|
71
|
+
while (!result) {
|
|
72
|
+
result = yield toRepeat();
|
|
73
|
+
if (!result) {
|
|
74
|
+
yield sleep(timeout);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
});
|
|
150
79
|
/**
|
|
151
80
|
* Loads a transaction receipt using the rpc for the given chain id
|
|
152
81
|
* @param chainId The chain id where the transaction should be loaded from
|
|
153
82
|
* @param txHash The hash of the transaction
|
|
154
83
|
* @returns TransactionReceipt
|
|
155
84
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return [4 /*yield*/, rpc.getTransaction(txHash)];
|
|
164
|
-
case 2:
|
|
165
|
-
tx = _a.sent();
|
|
166
|
-
return [2 /*return*/, tx.wait()];
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}); };
|
|
170
|
-
exports.loadTransactionReceipt = loadTransactionReceipt;
|
|
171
|
-
var isZeroAddress = function (address) {
|
|
172
|
-
if (address === ethers_1.constants.AddressZero ||
|
|
85
|
+
export const loadTransactionReceipt = (chainId, txHash) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
const rpc = yield getRpcProvider(chainId);
|
|
87
|
+
const tx = yield rpc.getTransaction(txHash);
|
|
88
|
+
return tx.wait();
|
|
89
|
+
});
|
|
90
|
+
export const isZeroAddress = (address) => {
|
|
91
|
+
if (address === constants.AddressZero ||
|
|
173
92
|
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
|
|
174
93
|
return true;
|
|
175
94
|
}
|
|
176
95
|
return false;
|
|
177
96
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (address === ethers_1.constants.AddressZero ||
|
|
97
|
+
export const isNativeTokenAddress = (address) => {
|
|
98
|
+
if (address === constants.AddressZero ||
|
|
181
99
|
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
|
|
182
100
|
// CELO native token
|
|
183
101
|
address === '0x471ece3750da237f93b8e339c536989b8978a438') {
|
|
@@ -185,4 +103,3 @@ var isNativeTokenAddress = function (address) {
|
|
|
185
103
|
}
|
|
186
104
|
return false;
|
|
187
105
|
};
|
|
188
|
-
exports.isNativeTokenAddress = isNativeTokenAddress;
|