@lifi/sdk 1.1.2 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -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/cjs/Lifi.d.ts +200 -0
- package/dist/cjs/Lifi.js +376 -0
- package/dist/cjs/allowance/index.d.ts +22 -0
- package/dist/cjs/allowance/index.js +78 -0
- package/dist/cjs/allowance/utils.d.ts +14 -0
- package/dist/cjs/allowance/utils.js +82 -0
- package/dist/cjs/balances/index.d.ts +11 -0
- package/dist/cjs/balances/index.js +46 -0
- package/dist/cjs/balances/utils.d.ts +5 -0
- package/dist/cjs/balances/utils.js +150 -0
- package/dist/cjs/connectors.d.ts +6 -0
- package/dist/cjs/connectors.js +77 -0
- package/dist/cjs/execution/StatusManager.d.ts +65 -0
- package/dist/cjs/execution/StatusManager.js +167 -0
- package/dist/cjs/execution/StepExecutor.d.ts +15 -0
- package/dist/cjs/execution/StepExecutor.js +74 -0
- package/dist/cjs/execution/allowance.execute.d.ts +4 -0
- package/dist/cjs/execution/allowance.execute.js +97 -0
- package/dist/cjs/execution/balanceCheck.execute.d.ts +3 -0
- package/dist/cjs/execution/balanceCheck.execute.js +48 -0
- package/dist/cjs/execution/bridges/bridge.execute.d.ts +7 -0
- package/dist/cjs/execution/bridges/bridge.execute.js +154 -0
- package/dist/cjs/execution/exchanges/swap.execute.d.ts +7 -0
- package/dist/cjs/execution/exchanges/swap.execute.js +164 -0
- package/dist/cjs/execution/index.d.ts +1 -0
- package/dist/cjs/execution/index.js +17 -0
- package/dist/cjs/execution/stepComparison.d.ts +14 -0
- package/dist/cjs/execution/stepComparison.js +46 -0
- package/dist/cjs/execution/switchChain.d.ts +16 -0
- package/dist/cjs/execution/switchChain.js +58 -0
- package/dist/cjs/execution/utils.d.ts +6 -0
- package/dist/cjs/execution/utils.js +137 -0
- package/dist/cjs/helpers.d.ts +18 -0
- package/dist/cjs/helpers.js +54 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/services/ApiService.d.ts +15 -0
- package/dist/cjs/services/ApiService.js +272 -0
- package/dist/cjs/services/ChainsService.d.ts +11 -0
- package/dist/cjs/services/ChainsService.js +54 -0
- package/dist/cjs/services/ConfigService.d.ts +23 -0
- package/dist/cjs/services/ConfigService.js +98 -0
- package/dist/cjs/typeguards.d.ts +4 -0
- package/dist/cjs/typeguards.js +53 -0
- package/dist/cjs/types/ERC20.d.ts +22 -0
- package/dist/cjs/types/ERC20.js +53 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/internal.types.d.ts +85 -0
- package/dist/cjs/types/internal.types.js +2 -0
- package/dist/cjs/utils/errors.d.ts +75 -0
- package/dist/cjs/utils/errors.js +115 -0
- package/dist/cjs/utils/getProvider.d.ts +3 -0
- package/dist/cjs/utils/getProvider.js +11 -0
- package/dist/cjs/utils/multicall.d.ts +10 -0
- package/dist/cjs/utils/multicall.js +77 -0
- package/dist/cjs/utils/multicallAbi.json +313 -0
- package/dist/cjs/utils/parseError.d.ts +38 -0
- package/dist/cjs/utils/parseError.js +141 -0
- package/dist/cjs/utils/preRestart.d.ts +2 -0
- package/dist/cjs/utils/preRestart.js +31 -0
- package/dist/cjs/utils/utils.d.ts +26 -0
- package/dist/cjs/utils/utils.js +120 -0
- 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 +34 -11
package/dist/balances/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,43 +7,12 @@ 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
|
-
|
|
27
|
-
|
|
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
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
54
|
-
var ethers_1 = require("ethers");
|
|
55
|
-
var connectors_1 = require("../connectors");
|
|
56
|
-
var multicall_1 = require("../utils/multicall");
|
|
57
|
-
var utils_1 = require("../utils/utils");
|
|
58
|
-
var balanceAbi = [
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
import { ethers } from 'ethers';
|
|
12
|
+
import { getMulticallAddress, getRpcProvider } from '../connectors';
|
|
13
|
+
import { fetchDataUsingMulticall } from '../utils/multicall';
|
|
14
|
+
import { isZeroAddress } from '../utils/utils';
|
|
15
|
+
const balanceAbi = [
|
|
59
16
|
{
|
|
60
17
|
constant: true,
|
|
61
18
|
inputs: [{ name: 'who', type: 'address' }],
|
|
@@ -75,181 +32,114 @@ var balanceAbi = [
|
|
|
75
32
|
type: 'function',
|
|
76
33
|
},
|
|
77
34
|
];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (token.chainId !== chainId) {
|
|
89
|
-
// eslint-disable-next-line no-console
|
|
90
|
-
console.warn("Requested tokens have to be on same chain.");
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return [4 /*yield*/, (0, connectors_1.getMulticallAddress)(chainId)];
|
|
95
|
-
case 1:
|
|
96
|
-
if ((_a.sent()) && tokens.length > 1) {
|
|
97
|
-
return [2 /*return*/, getBalancesFromProviderUsingMulticall(walletAddress, tokens)];
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return [2 /*return*/, getBalancesFromProvider(walletAddress, tokens)];
|
|
101
|
-
}
|
|
102
|
-
return [2 /*return*/];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}); };
|
|
106
|
-
var getBalancesFromProviderUsingMulticall = function (walletAddress, tokens) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var chainId, multicallAddress;
|
|
108
|
-
return __generator(this, function (_a) {
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0:
|
|
111
|
-
chainId = tokens[0].chainId;
|
|
112
|
-
return [4 /*yield*/, (0, connectors_1.getMulticallAddress)(chainId)];
|
|
113
|
-
case 1:
|
|
114
|
-
multicallAddress = _a.sent();
|
|
115
|
-
if (!multicallAddress) {
|
|
116
|
-
throw new Error('No multicallAddress found for the given chain.');
|
|
117
|
-
}
|
|
118
|
-
return [2 /*return*/, executeMulticall(walletAddress, tokens, multicallAddress, chainId)];
|
|
35
|
+
const getBalances = (walletAddress, tokens) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
if (tokens.length === 0) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const { chainId } = tokens[0];
|
|
40
|
+
tokens.forEach((token) => {
|
|
41
|
+
if (token.chainId !== chainId) {
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.warn(`Requested tokens have to be on same chain.`);
|
|
44
|
+
return [];
|
|
119
45
|
}
|
|
120
46
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!res.length) {
|
|
148
|
-
return [2 /*return*/, []];
|
|
149
|
-
}
|
|
150
|
-
return [2 /*return*/, tokens.map(function (token, i) {
|
|
151
|
-
var amount = new bignumber_js_1.default(res[i].amount.toString() || '0')
|
|
152
|
-
.shiftedBy(-token.decimals)
|
|
153
|
-
.toFixed();
|
|
154
|
-
return __assign(__assign({}, token), { amount: amount || '0', blockNumber: res[i].blockNumber });
|
|
155
|
-
})];
|
|
47
|
+
if ((yield getMulticallAddress(chainId)) && tokens.length > 1) {
|
|
48
|
+
return getBalancesFromProviderUsingMulticall(walletAddress, tokens);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return getBalancesFromProvider(walletAddress, tokens);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const getBalancesFromProviderUsingMulticall = (walletAddress, tokens) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
// Configuration
|
|
56
|
+
const { chainId } = tokens[0];
|
|
57
|
+
const multicallAddress = yield getMulticallAddress(chainId);
|
|
58
|
+
if (!multicallAddress) {
|
|
59
|
+
throw new Error('No multicallAddress found for the given chain.');
|
|
60
|
+
}
|
|
61
|
+
return executeMulticall(walletAddress, tokens, multicallAddress, chainId);
|
|
62
|
+
});
|
|
63
|
+
const executeMulticall = (walletAddress, tokens, multicallAddress, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
// Collect calls we want to make
|
|
65
|
+
const calls = [];
|
|
66
|
+
tokens.map((token) => {
|
|
67
|
+
if (isZeroAddress(token.address)) {
|
|
68
|
+
calls.push({
|
|
69
|
+
address: multicallAddress,
|
|
70
|
+
name: 'getEthBalance',
|
|
71
|
+
params: [walletAddress],
|
|
72
|
+
});
|
|
156
73
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
case 0: return [4 /*yield*/, (0, multicall_1.fetchDataUsingMulticall)(calls, abi, chainId, multicallAddress)];
|
|
164
|
-
case 1:
|
|
165
|
-
result = _a.sent();
|
|
166
|
-
return [2 /*return*/, result.map(function (_a) {
|
|
167
|
-
var data = _a.data, blockNumber = _a.blockNumber;
|
|
168
|
-
return ({
|
|
169
|
-
amount: data ? data : new bignumber_js_1.default(0),
|
|
170
|
-
blockNumber: blockNumber,
|
|
171
|
-
});
|
|
172
|
-
})];
|
|
74
|
+
else {
|
|
75
|
+
calls.push({
|
|
76
|
+
address: token.address,
|
|
77
|
+
name: 'balanceOf',
|
|
78
|
+
params: [walletAddress],
|
|
79
|
+
});
|
|
173
80
|
}
|
|
174
81
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
rpc = _a.sent();
|
|
185
|
-
tokenAmountPromises = tokens.map(function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
186
|
-
var amount, blockNumber, balance, e_1;
|
|
187
|
-
return __generator(this, function (_a) {
|
|
188
|
-
switch (_a.label) {
|
|
189
|
-
case 0:
|
|
190
|
-
amount = '0';
|
|
191
|
-
_a.label = 1;
|
|
192
|
-
case 1:
|
|
193
|
-
_a.trys.push([1, 3, , 4]);
|
|
194
|
-
return [4 /*yield*/, getBalanceFromProvider(walletAddress, token.address, chainId, rpc)];
|
|
195
|
-
case 2:
|
|
196
|
-
balance = _a.sent();
|
|
197
|
-
amount = new bignumber_js_1.default(balance.amount.toString())
|
|
198
|
-
.shiftedBy(-token.decimals)
|
|
199
|
-
.toString();
|
|
200
|
-
blockNumber = balance.blockNumber;
|
|
201
|
-
return [3 /*break*/, 4];
|
|
202
|
-
case 3:
|
|
203
|
-
e_1 = _a.sent();
|
|
204
|
-
// eslint-disable-next-line no-console
|
|
205
|
-
console.warn(e_1);
|
|
206
|
-
return [3 /*break*/, 4];
|
|
207
|
-
case 4: return [2 /*return*/, __assign(__assign({}, token), { amount: amount, blockNumber: blockNumber })];
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}); });
|
|
211
|
-
return [2 /*return*/, Promise.all(tokenAmountPromises)];
|
|
212
|
-
}
|
|
82
|
+
const res = yield fetchViaMulticall(calls, balanceAbi, chainId, multicallAddress);
|
|
83
|
+
if (!res.length) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
return tokens.map((token, i) => {
|
|
87
|
+
const amount = new BigNumber(res[i].amount.toString() || '0')
|
|
88
|
+
.shiftedBy(-token.decimals)
|
|
89
|
+
.toFixed();
|
|
90
|
+
return Object.assign(Object.assign({}, token), { amount: amount || '0', blockNumber: res[i].blockNumber });
|
|
213
91
|
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_a.label = 5;
|
|
235
|
-
case 5: return [2 /*return*/, {
|
|
236
|
-
amount: balance,
|
|
237
|
-
blockNumber: blockNumber,
|
|
238
|
-
}];
|
|
92
|
+
});
|
|
93
|
+
const fetchViaMulticall = (calls, abi, chainId, multicallAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const result = yield fetchDataUsingMulticall(calls, abi, chainId, multicallAddress);
|
|
95
|
+
return result.map(({ data, blockNumber }) => ({
|
|
96
|
+
amount: data ? data : new BigNumber(0),
|
|
97
|
+
blockNumber,
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
const getBalancesFromProvider = (walletAddress, tokens) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const chainId = tokens[0].chainId;
|
|
102
|
+
const rpc = yield getRpcProvider(chainId);
|
|
103
|
+
const tokenAmountPromises = tokens.map((token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
let amount = '0';
|
|
105
|
+
let blockNumber;
|
|
106
|
+
try {
|
|
107
|
+
const balance = yield getBalanceFromProvider(walletAddress, token.address, chainId, rpc);
|
|
108
|
+
amount = new BigNumber(balance.amount.toString())
|
|
109
|
+
.shiftedBy(-token.decimals)
|
|
110
|
+
.toString();
|
|
111
|
+
blockNumber = balance.blockNumber;
|
|
239
112
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var rpc;
|
|
244
|
-
return __generator(this, function (_a) {
|
|
245
|
-
switch (_a.label) {
|
|
246
|
-
case 0: return [4 /*yield*/, (0, connectors_1.getRpcProvider)(chainId)];
|
|
247
|
-
case 1:
|
|
248
|
-
rpc = _a.sent();
|
|
249
|
-
return [2 /*return*/, rpc.getBlockNumber()];
|
|
113
|
+
catch (e) {
|
|
114
|
+
// eslint-disable-next-line no-console
|
|
115
|
+
console.warn(e);
|
|
250
116
|
}
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
|
|
117
|
+
return Object.assign(Object.assign({}, token), { amount,
|
|
118
|
+
blockNumber });
|
|
119
|
+
}));
|
|
120
|
+
return Promise.all(tokenAmountPromises);
|
|
121
|
+
});
|
|
122
|
+
const getBalanceFromProvider = (walletAddress, assetId, chainId, provider) => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
const blockNumber = yield getCurrentBlockNumber(chainId);
|
|
124
|
+
let balance;
|
|
125
|
+
if (isZeroAddress(assetId)) {
|
|
126
|
+
balance = yield provider.getBalance(walletAddress, blockNumber);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const contract = new ethers.Contract(assetId, ['function balanceOf(address owner) view returns (uint256)'], provider);
|
|
130
|
+
balance = yield contract.balanceOf(walletAddress, {
|
|
131
|
+
blockTag: blockNumber,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
amount: balance,
|
|
136
|
+
blockNumber,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
const getCurrentBlockNumber = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const rpc = yield getRpcProvider(chainId);
|
|
141
|
+
return rpc.getBlockNumber();
|
|
142
|
+
});
|
|
143
|
+
export default {
|
|
144
|
+
getBalances,
|
|
255
145
|
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { FallbackProvider } from '@ethersproject/providers';
|
|
2
|
+
import { Chain, ChainId, ChainKey, ContractCallQuoteRequest, GetStatusRequest, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, Route, RoutesRequest, RoutesResponse, StatusResponse, Step, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
|
|
3
|
+
import { Signer } from 'ethers';
|
|
4
|
+
import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
|
|
5
|
+
import { Config, ConfigUpdate, ExecutionSettings, RevokeTokenData } from './types';
|
|
6
|
+
export default class LIFI {
|
|
7
|
+
private activeRouteDictionary;
|
|
8
|
+
private configService;
|
|
9
|
+
private chainsService;
|
|
10
|
+
constructor(configUpdate?: ConfigUpdate);
|
|
11
|
+
/**
|
|
12
|
+
* Get the current configuration of the SDK
|
|
13
|
+
* @return {Config} - The config object
|
|
14
|
+
*/
|
|
15
|
+
getConfig: () => Config;
|
|
16
|
+
/**
|
|
17
|
+
* Get the SDK configuration after all setup calls are finished
|
|
18
|
+
* @return {Promise<Config>} - The config object
|
|
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>;
|
|
28
|
+
/**
|
|
29
|
+
* Set a new confuration for the SDK
|
|
30
|
+
* @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
|
|
31
|
+
* @return {Config} The renewed config object
|
|
32
|
+
*/
|
|
33
|
+
setConfig: (configUpdate: ConfigUpdate) => Config;
|
|
34
|
+
/**
|
|
35
|
+
* Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
|
|
36
|
+
* @param {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
|
|
37
|
+
* @return {Promise<PossibilitiesResponse>} Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
|
|
38
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
39
|
+
*/
|
|
40
|
+
getPossibilities: (request?: PossibilitiesRequest, options?: RequestOptions) => Promise<PossibilitiesResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Fetch information about a Token
|
|
43
|
+
* @param {ChainKey | ChainId} chain - Id or key of the chain that contains the token
|
|
44
|
+
* @param {string} token - Address or symbol of the token on the requested chain
|
|
45
|
+
* @throws {LifiError} - Throws a LifiError if request fails
|
|
46
|
+
*/
|
|
47
|
+
getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions) => Promise<Token>;
|
|
48
|
+
/**
|
|
49
|
+
* Get a quote for a token transfer
|
|
50
|
+
* @param {QuoteRequest} request - The configuration of the requested quote
|
|
51
|
+
* @throws {LifiError} - Throws a LifiError if request fails
|
|
52
|
+
*/
|
|
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>;
|
|
60
|
+
/**
|
|
61
|
+
* Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
|
|
62
|
+
* @param {GetStatusRequest} request - Configuration of the requested status
|
|
63
|
+
* @throws {LifiError} - Throws a LifiError if request fails
|
|
64
|
+
*/
|
|
65
|
+
getStatus: (request: GetStatusRequest, options?: RequestOptions) => Promise<StatusResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Get the available tools to bridge and swap tokens.
|
|
68
|
+
* @param {ToolsRequest?} request - The configuration of the requested tools
|
|
69
|
+
* @returns The tools that are available on the requested chains
|
|
70
|
+
*/
|
|
71
|
+
getTools: (request?: ToolsRequest, options?: RequestOptions) => Promise<ToolsResponse>;
|
|
72
|
+
/**
|
|
73
|
+
* Get all known tokens.
|
|
74
|
+
* @param {TokensRequest?} request - The configuration of the requested tokens
|
|
75
|
+
* @returns The tokens that are available on the requested chains
|
|
76
|
+
*/
|
|
77
|
+
getTokens: (request?: TokensRequest, options?: RequestOptions) => Promise<TokensResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Get all available chains
|
|
80
|
+
* @return {Promise<Chain[]>} A list of all available chains
|
|
81
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
82
|
+
*/
|
|
83
|
+
getChains: () => Promise<Chain[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Get a set of routes for a request that describes a transfer of tokens.
|
|
86
|
+
* @param {RoutesRequest} routesRequest - A description of the transfer.
|
|
87
|
+
* @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
|
|
88
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
89
|
+
*/
|
|
90
|
+
getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the transaction data for a single step of a route
|
|
93
|
+
* @param {Step} step - The step object.
|
|
94
|
+
* @return {Promise<Step>} The step populated with the transaction data.
|
|
95
|
+
* @throws {LifiError} Throws a LifiError if request fails.
|
|
96
|
+
*/
|
|
97
|
+
getStepTransaction: (step: Step, options?: RequestOptions) => Promise<Step>;
|
|
98
|
+
/**
|
|
99
|
+
* Stops the execution of an active route.
|
|
100
|
+
* @param {Route} route - A route that is currently in execution.
|
|
101
|
+
* @return {Route} The stopped route.
|
|
102
|
+
*/
|
|
103
|
+
stopExecution: (route: Route) => Route;
|
|
104
|
+
/**
|
|
105
|
+
* Executes a route until a user interaction is necessary (signing transactions, etc.) and then halts until the route is resumed.
|
|
106
|
+
* @param {Route} route - A route that is currently in execution.
|
|
107
|
+
*/
|
|
108
|
+
moveExecutionToBackground: (route: Route) => void;
|
|
109
|
+
/**
|
|
110
|
+
* Execute a route.
|
|
111
|
+
* @param {Signer} signer - The signer required to send the transactions.
|
|
112
|
+
* @param {Route} route - The route that should be executed. Cannot be an active route.
|
|
113
|
+
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
114
|
+
* @return {Promise<Route>} The executed route.
|
|
115
|
+
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
116
|
+
*/
|
|
117
|
+
executeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
118
|
+
/**
|
|
119
|
+
* Resume the execution of a route that has been stopped or had an error while executing.
|
|
120
|
+
* @param {Signer} signer - The signer required to send the transactions.
|
|
121
|
+
* @param {Route} route - The route that is to be executed. Cannot be an active route.
|
|
122
|
+
* @param {ExecutionSettings} settings - An object containing settings and callbacks.
|
|
123
|
+
* @return {Promise<Route>} The executed route.
|
|
124
|
+
* @throws {LifiError} Throws a LifiError if the execution fails.
|
|
125
|
+
*/
|
|
126
|
+
resumeRoute: (signer: Signer, route: Route, settings?: ExecutionSettings) => Promise<Route>;
|
|
127
|
+
private executeSteps;
|
|
128
|
+
/**
|
|
129
|
+
* Update the ExecutionSettings for an active route.
|
|
130
|
+
* @param {ExecutionSettings} settings - An object with execution settings.
|
|
131
|
+
* @param {Route} route - The active route that gets the new execution settings.
|
|
132
|
+
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
133
|
+
*/
|
|
134
|
+
updateExecutionSettings: (settings: ExecutionSettings, route: Route) => void;
|
|
135
|
+
/**
|
|
136
|
+
* Get the list of active routes.
|
|
137
|
+
* @return {Route[]} A list of routes.
|
|
138
|
+
*/
|
|
139
|
+
getActiveRoutes: () => Route[];
|
|
140
|
+
/**
|
|
141
|
+
* Return the current route information for given route. The route has to be active.
|
|
142
|
+
* @param {Route} route - A route object.
|
|
143
|
+
* @return {Route} The updated route.
|
|
144
|
+
*/
|
|
145
|
+
getActiveRoute: (route: Route) => Route | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
148
|
+
* @param {string} walletAddress - A wallet address.
|
|
149
|
+
* @param {Token} token - A Token object.
|
|
150
|
+
* @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
|
|
151
|
+
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
152
|
+
*/
|
|
153
|
+
getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
|
|
154
|
+
/**
|
|
155
|
+
* Returns the balances for a list tokens a wallet holds across all aggregated chains.
|
|
156
|
+
* @param {string} walletAddress - A wallet address.
|
|
157
|
+
* @param {Token[]} tokens - A list of Token objects.
|
|
158
|
+
* @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
|
|
159
|
+
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
160
|
+
*/
|
|
161
|
+
getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
162
|
+
/**
|
|
163
|
+
* This method queries the balances of tokens for a specific list of chains for a given wallet.
|
|
164
|
+
* @param {string} walletAddress - A walletaddress.
|
|
165
|
+
* @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids.
|
|
166
|
+
* @return {Promise<{ [chainId: number]: TokenAmount[] }} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
|
|
167
|
+
* @throws {ValidationError} Throws a ValidationError if parameters are invalid.
|
|
168
|
+
*/
|
|
169
|
+
getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
|
|
170
|
+
[chainId: number]: Token[];
|
|
171
|
+
}) => Promise<{
|
|
172
|
+
[chainId: number]: TokenAmount[];
|
|
173
|
+
}>;
|
|
174
|
+
/**
|
|
175
|
+
* Get the current approval for a certain token.
|
|
176
|
+
* @param signer - The signer owning the token
|
|
177
|
+
* @param token - The token that should be checked
|
|
178
|
+
* @param approvalAddress - The address that has be approved
|
|
179
|
+
*/
|
|
180
|
+
getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>;
|
|
181
|
+
/**
|
|
182
|
+
* Get the current approval for a list of token / approval address pairs.
|
|
183
|
+
* @param signer - The signer owning the tokens
|
|
184
|
+
* @param tokenData - A list of token and approval address pairs
|
|
185
|
+
*/
|
|
186
|
+
bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{
|
|
187
|
+
token: Token;
|
|
188
|
+
approval: string | undefined;
|
|
189
|
+
}[]>;
|
|
190
|
+
/**
|
|
191
|
+
* Set approval for a certain token and amount.
|
|
192
|
+
* @param { ApproveTokenRequest } request - The approval request
|
|
193
|
+
*/
|
|
194
|
+
approveToken: (request: ApproveTokenRequest) => Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Revoke approval for a certain token.
|
|
197
|
+
* @param { RevokeApprovalRequest } request - The revoke request
|
|
198
|
+
*/
|
|
199
|
+
revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
|
|
200
|
+
}
|