@across-protocol/sdk 4.3.58 → 4.3.59
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/dist/cjs/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +45 -332
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +6 -4
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js +5 -0
- package/dist/cjs/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +4 -3
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/HubPoolClient.d.ts +3 -9
- package/dist/cjs/clients/HubPoolClient.js +44 -68
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +4 -3
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.d.ts +2 -2
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/providers/retryProvider.js +6 -4
- package/dist/cjs/providers/retryProvider.js.map +1 -1
- package/dist/cjs/providers/utils.js +1 -1
- package/dist/cjs/providers/utils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +47 -373
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +6 -4
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js +6 -1
- package/dist/esm/clients/BundleDataClient/utils/FillUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +3 -2
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/HubPoolClient.d.ts +3 -9
- package/dist/esm/clients/HubPoolClient.js +48 -74
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +4 -3
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.d.ts +2 -2
- package/dist/esm/clients/mocks/MockHubPoolClient.js +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/providers/retryProvider.js +6 -4
- package/dist/esm/providers/retryProvider.js.map +1 -1
- package/dist/esm/providers/utils.js +2 -2
- package/dist/esm/providers/utils.js.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts +2 -15
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/FillUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts +1 -1
- package/dist/types/clients/BundleDataClient/utils/PoolRebalanceUtils.d.ts.map +1 -1
- package/dist/types/clients/HubPoolClient.d.ts +3 -9
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts +2 -2
- package/dist/types/clients/mocks/MockHubPoolClient.d.ts.map +1 -1
- package/dist/types/providers/retryProvider.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/clients/BundleDataClient/BundleDataClient.ts +12 -358
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +13 -20
- package/src/clients/BundleDataClient/utils/FillUtils.ts +7 -1
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +8 -2
- package/src/clients/HubPoolClient.ts +49 -80
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +15 -11
- package/src/clients/mocks/MockHubPoolClient.ts +3 -3
- package/src/providers/retryProvider.ts +6 -4
- package/src/providers/utils.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SpokePoolClientsByChain, LoadDataReturnValue, Clients, FillWithBlock, DepositWithBlock } from "../../interfaces";
|
|
2
2
|
import { SpokePoolClient } from "..";
|
|
3
|
-
import { BigNumber
|
|
3
|
+
import { BigNumber } from "../../utils";
|
|
4
4
|
import winston from "winston";
|
|
5
5
|
import { SpokePoolManager } from "../SpokePoolClient/SpokePoolClientManager";
|
|
6
6
|
export declare const INFINITE_FILL_DEADLINE: BigNumber;
|
|
@@ -31,19 +31,6 @@ export declare class BundleDataClient {
|
|
|
31
31
|
static getArweaveClientKey(blockRangesForChains: number[][]): string;
|
|
32
32
|
private getArweaveBundleDataClientKey;
|
|
33
33
|
private loadPersistedDataFromArweave;
|
|
34
|
-
getPendingRefundsFromValidBundles(): Promise<CombinedRefunds[]>;
|
|
35
|
-
getPendingRefundsFromBundle(bundle: ProposedRootBundle): Promise<CombinedRefunds>;
|
|
36
|
-
getApproximateRefundsForBlockRange(chainIds: number[], blockRanges: number[][]): Promise<CombinedRefunds>;
|
|
37
|
-
getUpcomingDepositAmount(chainId: number, l2Token: Address, latestBlockToSearch: number): BigNumber;
|
|
38
|
-
getNextBundleRefunds(): Promise<CombinedRefunds[]>;
|
|
39
|
-
getExecutedRefunds(spokePoolClient: SpokePoolClient, relayerRefundRoot: string): {
|
|
40
|
-
[tokenAddress: string]: {
|
|
41
|
-
[relayer: string]: BigNumber;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
private deductExecutedRefunds;
|
|
45
|
-
getRefundsFor(bundleRefunds: CombinedRefunds, relayer: Address, chainId: number, token: Address): BigNumber;
|
|
46
|
-
getTotalRefund(refunds: CombinedRefunds[], relayer: Address, chainId: number, refundToken: Address): BigNumber;
|
|
47
34
|
private loadArweaveData;
|
|
48
35
|
loadData(blockRangesForChains: number[][], spokePoolClients: SpokePoolClientsByChain, attemptArweaveLoad?: boolean): Promise<LoadDataReturnValue>;
|
|
49
36
|
private loadDataFromScratch;
|
|
@@ -217,293 +217,6 @@ var BundleDataClient = (function () {
|
|
|
217
217
|
});
|
|
218
218
|
});
|
|
219
219
|
};
|
|
220
|
-
BundleDataClient.prototype.getPendingRefundsFromValidBundles = function () {
|
|
221
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
222
|
-
var refunds, bundle, _a, _b;
|
|
223
|
-
return tslib_1.__generator(this, function (_c) {
|
|
224
|
-
switch (_c.label) {
|
|
225
|
-
case 0:
|
|
226
|
-
refunds = [];
|
|
227
|
-
if (!this.clients.hubPoolClient.isUpdated) {
|
|
228
|
-
throw new Error("BundleDataClient::getPendingRefundsFromValidBundles HubPoolClient not updated.");
|
|
229
|
-
}
|
|
230
|
-
bundle = this.clients.hubPoolClient.getLatestFullyExecutedRootBundle(this.clients.hubPoolClient.latestHeightSearched);
|
|
231
|
-
if (!(bundle !== undefined)) return [3, 2];
|
|
232
|
-
_b = (_a = refunds).push;
|
|
233
|
-
return [4, this.getPendingRefundsFromBundle(bundle)];
|
|
234
|
-
case 1:
|
|
235
|
-
_b.apply(_a, [_c.sent()]);
|
|
236
|
-
_c.label = 2;
|
|
237
|
-
case 2: return [2, refunds];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
BundleDataClient.prototype.getPendingRefundsFromBundle = function (bundle) {
|
|
243
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
244
|
-
var nextBundleMainnetStartBlock, chainIds, bundleEvaluationBlockRanges, combinedRefunds, arweaveData, bundleFillsV3, expiredDepositsToRefundV3;
|
|
245
|
-
var _this = this;
|
|
246
|
-
return tslib_1.__generator(this, function (_a) {
|
|
247
|
-
switch (_a.label) {
|
|
248
|
-
case 0:
|
|
249
|
-
nextBundleMainnetStartBlock = this.clients.hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, this.clients.hubPoolClient.latestHeightSearched, this.clients.hubPoolClient.chainId);
|
|
250
|
-
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
251
|
-
bundleEvaluationBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(this.clients.hubPoolClient, this.clients.configStoreClient, bundle);
|
|
252
|
-
return [4, this.loadArweaveData(bundleEvaluationBlockRanges)];
|
|
253
|
-
case 1:
|
|
254
|
-
arweaveData = _a.sent();
|
|
255
|
-
if (!!(0, utils_1.isDefined)(arweaveData)) return [3, 3];
|
|
256
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, bundleEvaluationBlockRanges)];
|
|
257
|
-
case 2:
|
|
258
|
-
combinedRefunds = _a.sent();
|
|
259
|
-
return [3, 4];
|
|
260
|
-
case 3:
|
|
261
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
262
|
-
combinedRefunds = (0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3);
|
|
263
|
-
Object.keys(combinedRefunds).forEach(function (chainId) {
|
|
264
|
-
if (!_this.spokePoolClientManager.getClient(Number(chainId))) {
|
|
265
|
-
delete combinedRefunds[Number(chainId)];
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
_a.label = 4;
|
|
269
|
-
case 4: return [2, this.deductExecutedRefunds(combinedRefunds, bundle)];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
BundleDataClient.prototype.getApproximateRefundsForBlockRange = function (chainIds, blockRanges) {
|
|
275
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var refundsForChain, bundleEndBlockForMainnet, _loop_1, this_1, _i, chainIds_1, chainId;
|
|
277
|
-
var _this = this;
|
|
278
|
-
return tslib_1.__generator(this, function (_a) {
|
|
279
|
-
switch (_a.label) {
|
|
280
|
-
case 0:
|
|
281
|
-
refundsForChain = {};
|
|
282
|
-
bundleEndBlockForMainnet = blockRanges[0][1];
|
|
283
|
-
_loop_1 = function (chainId) {
|
|
284
|
-
var spokePoolClient, chainIndex, fillsToCount;
|
|
285
|
-
return tslib_1.__generator(this, function (_b) {
|
|
286
|
-
switch (_b.label) {
|
|
287
|
-
case 0:
|
|
288
|
-
spokePoolClient = this_1.spokePoolClientManager.getClient(chainId);
|
|
289
|
-
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
290
|
-
return [2, "continue"];
|
|
291
|
-
}
|
|
292
|
-
chainIndex = chainIds.indexOf(chainId);
|
|
293
|
-
fillsToCount = spokePoolClient.getFills().filter(function (fill) {
|
|
294
|
-
if (fill.blockNumber < blockRanges[chainIndex][0] ||
|
|
295
|
-
fill.blockNumber > blockRanges[chainIndex][1] ||
|
|
296
|
-
(0, utils_1.isZeroValueFillOrSlowFillRequest)(fill) ||
|
|
297
|
-
(0, utils_1.invalidOutputToken)(fill)) {
|
|
298
|
-
return false;
|
|
299
|
-
}
|
|
300
|
-
var originSpokePoolClient = _this.spokePoolClientManager.getClient(fill.originChainId);
|
|
301
|
-
if (!(0, utils_1.isDefined)(originSpokePoolClient)) {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
var matchingDeposit = originSpokePoolClient.getDeposit(fill.depositId);
|
|
305
|
-
var hasMatchingDeposit = matchingDeposit !== undefined && (0, utils_1.getRelayEventKey)(fill) === (0, utils_1.getRelayEventKey)(matchingDeposit);
|
|
306
|
-
return hasMatchingDeposit;
|
|
307
|
-
});
|
|
308
|
-
return [4, (0, utils_1.forEachAsync)(fillsToCount, function (_fill) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
309
|
-
var originChain, originSpokePoolClient, matchingDeposit, spokeClient, provider, fill, _a, chainToSendRefundTo, repaymentToken, relayer, refundAmount, existingRefundAmount;
|
|
310
|
-
var _b, _c, _d;
|
|
311
|
-
var _e, _f;
|
|
312
|
-
return tslib_1.__generator(this, function (_g) {
|
|
313
|
-
switch (_g.label) {
|
|
314
|
-
case 0:
|
|
315
|
-
originChain = (0, utils_1.getNetworkName)(_fill.originChainId);
|
|
316
|
-
originSpokePoolClient = this.spokePoolClientManager.getClient(_fill.originChainId);
|
|
317
|
-
(0, assert_1.default)((0, utils_1.isDefined)(originSpokePoolClient), "No SpokePoolClient for chain ".concat(originChain));
|
|
318
|
-
matchingDeposit = originSpokePoolClient.getDeposit(_fill.depositId);
|
|
319
|
-
(0, assert_1.default)((0, utils_1.isDefined)(matchingDeposit), "No ".concat(originChain, " deposit found for ").concat((0, utils_1.getNetworkName)(_fill.destinationChainId), " fill ").concat(_fill.depositId));
|
|
320
|
-
spokeClient = this.spokePoolClientManager.getClient(_fill.destinationChainId);
|
|
321
|
-
(0, assert_1.default)((0, utils_1.isDefined)(spokeClient), "SpokePoolClient for ".concat((0, utils_1.getNetworkName)(_fill.destinationChainId), " not found for fill."));
|
|
322
|
-
if ((0, SpokePoolClient_1.isEVMSpokePoolClient)(spokeClient)) {
|
|
323
|
-
provider = spokeClient.spokePool.provider;
|
|
324
|
-
}
|
|
325
|
-
else if ((0, SpokePoolClient_1.isSVMSpokePoolClient)(spokeClient)) {
|
|
326
|
-
provider = spokeClient.svmEventsClient.getRpc();
|
|
327
|
-
}
|
|
328
|
-
return [4, (0, utils_2.verifyFillRepayment)(_fill, provider, matchingDeposit, this.clients.hubPoolClient, bundleEndBlockForMainnet)];
|
|
329
|
-
case 1:
|
|
330
|
-
fill = _g.sent();
|
|
331
|
-
if (!(0, utils_1.isDefined)(fill)) {
|
|
332
|
-
return [2];
|
|
333
|
-
}
|
|
334
|
-
_a = (0, utils_2.getRefundInformationFromFill)(tslib_1.__assign(tslib_1.__assign({}, fill), { fromLiteChain: matchingDeposit.fromLiteChain }), this.clients.hubPoolClient, bundleEndBlockForMainnet), chainToSendRefundTo = _a.chainToSendRefundTo, repaymentToken = _a.repaymentToken;
|
|
335
|
-
relayer = fill.relayer, refundAmount = fill.inputAmount;
|
|
336
|
-
(_b = refundsForChain[chainToSendRefundTo]) !== null && _b !== void 0 ? _b : (refundsForChain[chainToSendRefundTo] = {});
|
|
337
|
-
(_c = (_e = refundsForChain[chainToSendRefundTo])[_f = repaymentToken.toBytes32()]) !== null && _c !== void 0 ? _c : (_e[_f] = {});
|
|
338
|
-
existingRefundAmount = (_d = refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()]) !== null && _d !== void 0 ? _d : utils_1.bnZero;
|
|
339
|
-
refundsForChain[chainToSendRefundTo][repaymentToken.toBytes32()][relayer.toBytes32()] =
|
|
340
|
-
existingRefundAmount.add(refundAmount);
|
|
341
|
-
return [2];
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
}); })];
|
|
345
|
-
case 1:
|
|
346
|
-
_b.sent();
|
|
347
|
-
return [2];
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
this_1 = this;
|
|
352
|
-
_i = 0, chainIds_1 = chainIds;
|
|
353
|
-
_a.label = 1;
|
|
354
|
-
case 1:
|
|
355
|
-
if (!(_i < chainIds_1.length)) return [3, 4];
|
|
356
|
-
chainId = chainIds_1[_i];
|
|
357
|
-
return [5, _loop_1(chainId)];
|
|
358
|
-
case 2:
|
|
359
|
-
_a.sent();
|
|
360
|
-
_a.label = 3;
|
|
361
|
-
case 3:
|
|
362
|
-
_i++;
|
|
363
|
-
return [3, 1];
|
|
364
|
-
case 4: return [2, refundsForChain];
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
};
|
|
369
|
-
BundleDataClient.prototype.getUpcomingDepositAmount = function (chainId, l2Token, latestBlockToSearch) {
|
|
370
|
-
var spokePoolClient = this.spokePoolClientManager.getClient(chainId);
|
|
371
|
-
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
372
|
-
return (0, utils_1.toBN)(0);
|
|
373
|
-
}
|
|
374
|
-
return spokePoolClient
|
|
375
|
-
.getDeposits()
|
|
376
|
-
.filter(function (deposit) { return deposit.blockNumber > latestBlockToSearch && deposit.inputToken.eq(l2Token); })
|
|
377
|
-
.reduce(function (acc, deposit) {
|
|
378
|
-
return acc.add(deposit.inputAmount);
|
|
379
|
-
}, (0, utils_1.toBN)(0));
|
|
380
|
-
};
|
|
381
|
-
BundleDataClient.prototype.getNextBundleRefunds = function () {
|
|
382
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
383
|
-
function getBlockRangeDelta(_pendingBlockRanges) {
|
|
384
|
-
return widestBundleBlockRanges.map(function (blockRange, index) {
|
|
385
|
-
var _a;
|
|
386
|
-
var initialBlockRange = (_a = _pendingBlockRanges[index]) !== null && _a !== void 0 ? _a : blockRange;
|
|
387
|
-
if (initialBlockRange[0] === initialBlockRange[1]) {
|
|
388
|
-
return initialBlockRange;
|
|
389
|
-
}
|
|
390
|
-
if (!(0, utils_1.isDefined)(blockRange[1]) || initialBlockRange[1] >= blockRange[1]) {
|
|
391
|
-
return [initialBlockRange[1], initialBlockRange[1]];
|
|
392
|
-
}
|
|
393
|
-
return [initialBlockRange[1] + 1, blockRange[1]];
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
var hubPoolClient, nextBundleMainnetStartBlock, chainIds, combinedRefunds, widestBundleBlockRanges, pendingBundleBlockRanges, arweaveData, _a, _b, bundleFillsV3, expiredDepositsToRefundV3, start, _c, _d;
|
|
397
|
-
return tslib_1.__generator(this, function (_e) {
|
|
398
|
-
switch (_e.label) {
|
|
399
|
-
case 0:
|
|
400
|
-
hubPoolClient = this.clients.hubPoolClient;
|
|
401
|
-
nextBundleMainnetStartBlock = hubPoolClient.getNextBundleStartBlockNumber(this.chainIdListForBundleEvaluationBlockNumbers, hubPoolClient.latestHeightSearched, hubPoolClient.chainId);
|
|
402
|
-
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(nextBundleMainnetStartBlock);
|
|
403
|
-
combinedRefunds = [];
|
|
404
|
-
return [4, (0, utils_2.getWidestPossibleExpectedBlockRange)(chainIds, this.spokePoolClientManager.getSpokePoolClients(), (0, utils_2.getEndBlockBuffers)(chainIds, this.blockRangeEndBlockBuffer), this.clients, this.clients.hubPoolClient.latestHeightSearched, this.clients.configStoreClient.getEnabledChains(this.clients.hubPoolClient.latestHeightSearched))];
|
|
405
|
-
case 1:
|
|
406
|
-
widestBundleBlockRanges = _e.sent();
|
|
407
|
-
if (!hubPoolClient.hasPendingProposal()) return [3, 6];
|
|
408
|
-
pendingBundleBlockRanges = (0, utils_1.getImpliedBundleBlockRanges)(hubPoolClient, this.clients.configStoreClient, hubPoolClient.getLatestProposedRootBundle());
|
|
409
|
-
return [4, this.loadArweaveData(pendingBundleBlockRanges)];
|
|
410
|
-
case 2:
|
|
411
|
-
arweaveData = _e.sent();
|
|
412
|
-
if (!!(0, utils_1.isDefined)(arweaveData)) return [3, 4];
|
|
413
|
-
_b = (_a = combinedRefunds).push;
|
|
414
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, pendingBundleBlockRanges)];
|
|
415
|
-
case 3:
|
|
416
|
-
_b.apply(_a, [_e.sent()]);
|
|
417
|
-
return [3, 5];
|
|
418
|
-
case 4:
|
|
419
|
-
bundleFillsV3 = arweaveData.bundleFillsV3, expiredDepositsToRefundV3 = arweaveData.expiredDepositsToRefundV3;
|
|
420
|
-
combinedRefunds.push((0, utils_2.getRefundsFromBundle)(bundleFillsV3, expiredDepositsToRefundV3));
|
|
421
|
-
_e.label = 5;
|
|
422
|
-
case 5:
|
|
423
|
-
widestBundleBlockRanges = getBlockRangeDelta(pendingBundleBlockRanges);
|
|
424
|
-
_e.label = 6;
|
|
425
|
-
case 6:
|
|
426
|
-
start = performance.now();
|
|
427
|
-
_d = (_c = combinedRefunds).push;
|
|
428
|
-
return [4, this.getApproximateRefundsForBlockRange(chainIds, widestBundleBlockRanges)];
|
|
429
|
-
case 7:
|
|
430
|
-
_d.apply(_c, [_e.sent()]);
|
|
431
|
-
this.logger.debug({
|
|
432
|
-
at: "BundleDataClient#getNextBundleRefunds",
|
|
433
|
-
message: "Loading approximate refunds for next bundle in ".concat(Math.round(performance.now() - start) / 1000, "s."),
|
|
434
|
-
blockRanges: JSON.stringify(widestBundleBlockRanges),
|
|
435
|
-
});
|
|
436
|
-
return [2, combinedRefunds];
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
BundleDataClient.prototype.getExecutedRefunds = function (spokePoolClient, relayerRefundRoot) {
|
|
442
|
-
var _a, _b;
|
|
443
|
-
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
444
|
-
return {};
|
|
445
|
-
}
|
|
446
|
-
var bundle = lodash_1.default.findLast(spokePoolClient.getRootBundleRelays(), function (bundle) { return bundle.relayerRefundRoot === relayerRefundRoot; });
|
|
447
|
-
if (bundle === undefined) {
|
|
448
|
-
return {};
|
|
449
|
-
}
|
|
450
|
-
var executedRefundLeaves = spokePoolClient
|
|
451
|
-
.getRelayerRefundExecutions()
|
|
452
|
-
.filter(function (leaf) { return leaf.rootBundleId === bundle.rootBundleId; });
|
|
453
|
-
var executedRefunds = {};
|
|
454
|
-
for (var _i = 0, executedRefundLeaves_1 = executedRefundLeaves; _i < executedRefundLeaves_1.length; _i++) {
|
|
455
|
-
var refundLeaf = executedRefundLeaves_1[_i];
|
|
456
|
-
var tokenAddress = refundLeaf.l2TokenAddress.toBytes32();
|
|
457
|
-
var executedTokenRefunds = ((_a = executedRefunds[tokenAddress]) !== null && _a !== void 0 ? _a : (executedRefunds[tokenAddress] = {}));
|
|
458
|
-
for (var i = 0; i < refundLeaf.refundAddresses.length; i++) {
|
|
459
|
-
var relayer = refundLeaf.refundAddresses[i].toBytes32();
|
|
460
|
-
var refundAmount = refundLeaf.refundAmounts[i];
|
|
461
|
-
(_b = executedTokenRefunds[relayer]) !== null && _b !== void 0 ? _b : (executedTokenRefunds[relayer] = utils_1.bnZero);
|
|
462
|
-
executedTokenRefunds[relayer] = executedTokenRefunds[relayer].add(refundAmount);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return executedRefunds;
|
|
466
|
-
};
|
|
467
|
-
BundleDataClient.prototype.deductExecutedRefunds = function (allRefunds, bundleContainingRefunds) {
|
|
468
|
-
for (var _i = 0, _a = Object.keys(allRefunds); _i < _a.length; _i++) {
|
|
469
|
-
var chainIdStr = _a[_i];
|
|
470
|
-
var chainId = Number(chainIdStr);
|
|
471
|
-
var spokePoolClient = this.spokePoolClientManager.getClient(chainId);
|
|
472
|
-
if (!(0, utils_1.isDefined)(spokePoolClient)) {
|
|
473
|
-
continue;
|
|
474
|
-
}
|
|
475
|
-
var executedRefunds = this.getExecutedRefunds(spokePoolClient, bundleContainingRefunds.relayerRefundRoot);
|
|
476
|
-
for (var _b = 0, _c = Object.keys(allRefunds[chainId]); _b < _c.length; _b++) {
|
|
477
|
-
var tokenAddress = _c[_b];
|
|
478
|
-
var refunds = allRefunds[chainId][tokenAddress];
|
|
479
|
-
if (executedRefunds[tokenAddress] === undefined || refunds === undefined) {
|
|
480
|
-
continue;
|
|
481
|
-
}
|
|
482
|
-
for (var _d = 0, _e = Object.keys(refunds); _d < _e.length; _d++) {
|
|
483
|
-
var relayer = _e[_d];
|
|
484
|
-
var executedAmount = executedRefunds[tokenAddress][relayer];
|
|
485
|
-
if (executedAmount === undefined) {
|
|
486
|
-
continue;
|
|
487
|
-
}
|
|
488
|
-
refunds[relayer] = utils_1.bnZero;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
return allRefunds;
|
|
493
|
-
};
|
|
494
|
-
BundleDataClient.prototype.getRefundsFor = function (bundleRefunds, relayer, chainId, token) {
|
|
495
|
-
if (!bundleRefunds[chainId] || !bundleRefunds[chainId][token.toBytes32()]) {
|
|
496
|
-
return utils_1.BigNumber.from(0);
|
|
497
|
-
}
|
|
498
|
-
var allRefunds = bundleRefunds[chainId][token.toBytes32()];
|
|
499
|
-
return allRefunds && allRefunds[relayer.toBytes32()] ? allRefunds[relayer.toBytes32()] : utils_1.BigNumber.from(0);
|
|
500
|
-
};
|
|
501
|
-
BundleDataClient.prototype.getTotalRefund = function (refunds, relayer, chainId, refundToken) {
|
|
502
|
-
var _this = this;
|
|
503
|
-
return refunds.reduce(function (totalRefund, refunds) {
|
|
504
|
-
return totalRefund.add(_this.getRefundsFor(refunds, relayer, chainId, refundToken));
|
|
505
|
-
}, utils_1.bnZero);
|
|
506
|
-
};
|
|
507
220
|
BundleDataClient.prototype.loadArweaveData = function (blockRangesForChains) {
|
|
508
221
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
509
222
|
var arweaveKey, arweaveData, _a, _b;
|
|
@@ -555,10 +268,10 @@ var BundleDataClient = (function () {
|
|
|
555
268
|
};
|
|
556
269
|
BundleDataClient.prototype.loadDataFromScratch = function (blockRangesForChains, spokePoolClients) {
|
|
557
270
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
558
|
-
var start, key,
|
|
271
|
+
var start, key, _a, bundleStartBlockForMainnet, bundleEndBlockForMainnet, chainIds, bundleDepositsV3, bundleFillsV3, bundleInvalidFillsV3, bundleUnrepayableFillsV3, bundleInvalidSlowFillRequests, bundleSlowFillsV3, expiredDepositsToRefundV3, unexecutableSlowFills, _canCreateSlowFillLeaf, _depositIsExpired, _getFillStatusForDeposit, allChainIds, _cachedBundleTimestamps, bundleBlockTimestamps, v3RelayHashes, bundleDepositHashes, olderDepositHashes, decodeBundleDepositHash, _loop_1, _i, allChainIds_1, originChainId, validatedBundleV3Fills, validatedBundleSlowFills, validatedBundleUnexecutableSlowFills, fillCounter, _loop_2, _b, allChainIds_2, originChainId, promises, _c, v3FillLpFees, v3SlowFillLpFees, v3UnexecutableSlowFillLpFees, v3SpokeEventsReadable, invalidFillsWithPartialMatchedDeposits_1, preFillsForNextBundle_1, unknownReasonInvalidFills_1;
|
|
559
272
|
var _this = this;
|
|
560
|
-
return tslib_1.__generator(this, function (
|
|
561
|
-
switch (
|
|
273
|
+
return tslib_1.__generator(this, function (_d) {
|
|
274
|
+
switch (_d.label) {
|
|
562
275
|
case 0:
|
|
563
276
|
start = performance.now();
|
|
564
277
|
key = JSON.stringify(blockRangesForChains);
|
|
@@ -568,8 +281,8 @@ var BundleDataClient = (function () {
|
|
|
568
281
|
else if (!this.clients.hubPoolClient.isUpdated) {
|
|
569
282
|
throw new Error("HubPoolClient not updated");
|
|
570
283
|
}
|
|
571
|
-
|
|
572
|
-
|
|
284
|
+
_a = blockRangesForChains[0], bundleStartBlockForMainnet = _a[0], bundleEndBlockForMainnet = _a[1];
|
|
285
|
+
chainIds = this.clients.configStoreClient.getChainIdIndicesForBlock(bundleStartBlockForMainnet);
|
|
573
286
|
if (blockRangesForChains.length > chainIds.length) {
|
|
574
287
|
throw new Error("Unexpected block range list length of ".concat(blockRangesForChains.length, ", should be <= ").concat(chainIds.length));
|
|
575
288
|
}
|
|
@@ -581,10 +294,6 @@ var BundleDataClient = (function () {
|
|
|
581
294
|
bundleSlowFillsV3 = {};
|
|
582
295
|
expiredDepositsToRefundV3 = {};
|
|
583
296
|
unexecutableSlowFills = {};
|
|
584
|
-
_isChainDisabled = function (chainId) {
|
|
585
|
-
var blockRangeForChain = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, chainId, chainIds);
|
|
586
|
-
return (0, utils_2.isChainDisabled)(blockRangeForChain);
|
|
587
|
-
};
|
|
588
297
|
_canCreateSlowFillLeaf = function (deposit) {
|
|
589
298
|
return (_this.clients.hubPoolClient.areTokensEquivalent(deposit.inputToken, deposit.originChainId, deposit.outputToken, deposit.destinationChainId, bundleEndBlockForMainnet) &&
|
|
590
299
|
!deposit.fromLiteChain &&
|
|
@@ -598,7 +307,10 @@ var BundleDataClient = (function () {
|
|
|
598
307
|
};
|
|
599
308
|
allChainIds = blockRangesForChains
|
|
600
309
|
.map(function (_blockRange, index) { return chainIds[index]; })
|
|
601
|
-
.filter(function (chainId) {
|
|
310
|
+
.filter(function (chainId) {
|
|
311
|
+
return !(0, utils_2.isChainDisabledAtBlock)(chainId, bundleStartBlockForMainnet, _this.clients.configStoreClient) &&
|
|
312
|
+
spokePoolClients[chainId] !== undefined;
|
|
313
|
+
});
|
|
602
314
|
allChainIds.forEach(function (chainId) {
|
|
603
315
|
var spokePoolClient = spokePoolClients[chainId];
|
|
604
316
|
if (!spokePoolClient.isUpdated) {
|
|
@@ -610,7 +322,7 @@ var BundleDataClient = (function () {
|
|
|
610
322
|
if (!!_cachedBundleTimestamps) return [3, 2];
|
|
611
323
|
return [4, this.getBundleBlockTimestamps(chainIds, blockRangesForChains, spokePoolClients)];
|
|
612
324
|
case 1:
|
|
613
|
-
bundleBlockTimestamps =
|
|
325
|
+
bundleBlockTimestamps = _d.sent();
|
|
614
326
|
this.setBundleTimestampsInCache(key, bundleBlockTimestamps);
|
|
615
327
|
this.logger.debug({
|
|
616
328
|
at: "BundleDataClient#loadData",
|
|
@@ -621,7 +333,7 @@ var BundleDataClient = (function () {
|
|
|
621
333
|
return [3, 3];
|
|
622
334
|
case 2:
|
|
623
335
|
bundleBlockTimestamps = _cachedBundleTimestamps;
|
|
624
|
-
|
|
336
|
+
_d.label = 3;
|
|
625
337
|
case 3:
|
|
626
338
|
v3RelayHashes = {};
|
|
627
339
|
bundleDepositHashes = [];
|
|
@@ -630,11 +342,11 @@ var BundleDataClient = (function () {
|
|
|
630
342
|
var _a = depositHash.split("@"), relayDataHash = _a[0], i = _a[1];
|
|
631
343
|
return { relayDataHash: relayDataHash, index: Number(i) };
|
|
632
344
|
};
|
|
633
|
-
|
|
345
|
+
_loop_1 = function (originChainId) {
|
|
634
346
|
var originClient = spokePoolClients[originChainId];
|
|
635
347
|
var originChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, originChainId, chainIds);
|
|
636
|
-
for (var
|
|
637
|
-
var destinationChainId = allChainIds_3[
|
|
348
|
+
for (var _e = 0, allChainIds_3 = allChainIds; _e < allChainIds_3.length; _e++) {
|
|
349
|
+
var destinationChainId = allChainIds_3[_e];
|
|
638
350
|
originClient.getDepositsForDestinationChainWithDuplicates(destinationChainId).forEach(function (deposit) {
|
|
639
351
|
var _a, _b;
|
|
640
352
|
if (deposit.blockNumber > originChainBlockRange[1] || (0, utils_1.isZeroValueDeposit)(deposit)) {
|
|
@@ -681,7 +393,7 @@ var BundleDataClient = (function () {
|
|
|
681
393
|
};
|
|
682
394
|
for (_i = 0, allChainIds_1 = allChainIds; _i < allChainIds_1.length; _i++) {
|
|
683
395
|
originChainId = allChainIds_1[_i];
|
|
684
|
-
|
|
396
|
+
_loop_1(originChainId);
|
|
685
397
|
}
|
|
686
398
|
this.logger.debug({
|
|
687
399
|
at: "BundleDataClient#loadData",
|
|
@@ -692,16 +404,16 @@ var BundleDataClient = (function () {
|
|
|
692
404
|
validatedBundleSlowFills = [];
|
|
693
405
|
validatedBundleUnexecutableSlowFills = [];
|
|
694
406
|
fillCounter = 0;
|
|
695
|
-
|
|
696
|
-
var originClient,
|
|
697
|
-
return tslib_1.__generator(this, function (
|
|
698
|
-
switch (
|
|
407
|
+
_loop_2 = function (originChainId) {
|
|
408
|
+
var originClient, _loop_3, _f, allChainIds_4, destinationChainId;
|
|
409
|
+
return tslib_1.__generator(this, function (_g) {
|
|
410
|
+
switch (_g.label) {
|
|
699
411
|
case 0:
|
|
700
412
|
originClient = spokePoolClients[originChainId];
|
|
701
|
-
|
|
413
|
+
_loop_3 = function (destinationChainId) {
|
|
702
414
|
var destinationClient, destinationChainBlockRange, originChainBlockRange, fastFillsReplacingSlowFills;
|
|
703
|
-
return tslib_1.__generator(this, function (
|
|
704
|
-
switch (
|
|
415
|
+
return tslib_1.__generator(this, function (_h) {
|
|
416
|
+
switch (_h.label) {
|
|
705
417
|
case 0:
|
|
706
418
|
destinationClient = spokePoolClients[destinationChainId];
|
|
707
419
|
destinationChainBlockRange = (0, utils_1.getBlockRangeForChain)(blockRangesForChains, destinationChainId, chainIds);
|
|
@@ -818,7 +530,7 @@ var BundleDataClient = (function () {
|
|
|
818
530
|
});
|
|
819
531
|
}); })];
|
|
820
532
|
case 1:
|
|
821
|
-
|
|
533
|
+
_h.sent();
|
|
822
534
|
return [4, (0, utils_1.forEachAsync)(destinationClient
|
|
823
535
|
.getSlowFillRequestsForOriginChain(originChainId)
|
|
824
536
|
.filter(function (request) {
|
|
@@ -890,7 +602,7 @@ var BundleDataClient = (function () {
|
|
|
890
602
|
});
|
|
891
603
|
}); })];
|
|
892
604
|
case 2:
|
|
893
|
-
|
|
605
|
+
_h.sent();
|
|
894
606
|
return [4, (0, utils_1.mapAsync)(bundleDepositHashes, function (depositHash) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
895
607
|
var _a, relayDataHash, index, _b, deposits, fill, slowFillRequest, deposit, provider, fillToRefund, fillStatus, prefill, provider, verifiedFill;
|
|
896
608
|
return tslib_1.__generator(this, function (_c) {
|
|
@@ -988,7 +700,7 @@ var BundleDataClient = (function () {
|
|
|
988
700
|
});
|
|
989
701
|
}); })];
|
|
990
702
|
case 3:
|
|
991
|
-
|
|
703
|
+
_h.sent();
|
|
992
704
|
fastFillsReplacingSlowFills.forEach(function (relayDataHash) {
|
|
993
705
|
var _a = v3RelayHashes[relayDataHash], deposits = _a.deposits, slowFillRequest = _a.slowFillRequest, fill = _a.fill;
|
|
994
706
|
(0, assert_1.default)((fill === null || fill === void 0 ? void 0 : fill.relayExecutionInfo.fillType) === interfaces_1.FillType.ReplacedSlowFill, "Fill type should be ReplacedSlowFill.");
|
|
@@ -1008,33 +720,33 @@ var BundleDataClient = (function () {
|
|
|
1008
720
|
}
|
|
1009
721
|
});
|
|
1010
722
|
};
|
|
1011
|
-
|
|
1012
|
-
|
|
723
|
+
_f = 0, allChainIds_4 = allChainIds;
|
|
724
|
+
_g.label = 1;
|
|
1013
725
|
case 1:
|
|
1014
|
-
if (!(
|
|
1015
|
-
destinationChainId = allChainIds_4[
|
|
1016
|
-
return [5,
|
|
726
|
+
if (!(_f < allChainIds_4.length)) return [3, 4];
|
|
727
|
+
destinationChainId = allChainIds_4[_f];
|
|
728
|
+
return [5, _loop_3(destinationChainId)];
|
|
1017
729
|
case 2:
|
|
1018
|
-
|
|
1019
|
-
|
|
730
|
+
_g.sent();
|
|
731
|
+
_g.label = 3;
|
|
1020
732
|
case 3:
|
|
1021
|
-
|
|
733
|
+
_f++;
|
|
1022
734
|
return [3, 1];
|
|
1023
735
|
case 4: return [2];
|
|
1024
736
|
}
|
|
1025
737
|
});
|
|
1026
738
|
};
|
|
1027
|
-
|
|
1028
|
-
|
|
739
|
+
_b = 0, allChainIds_2 = allChainIds;
|
|
740
|
+
_d.label = 4;
|
|
1029
741
|
case 4:
|
|
1030
|
-
if (!(
|
|
1031
|
-
originChainId = allChainIds_2[
|
|
1032
|
-
return [5,
|
|
742
|
+
if (!(_b < allChainIds_2.length)) return [3, 7];
|
|
743
|
+
originChainId = allChainIds_2[_b];
|
|
744
|
+
return [5, _loop_2(originChainId)];
|
|
1033
745
|
case 5:
|
|
1034
|
-
|
|
1035
|
-
|
|
746
|
+
_d.sent();
|
|
747
|
+
_d.label = 6;
|
|
1036
748
|
case 6:
|
|
1037
|
-
|
|
749
|
+
_b++;
|
|
1038
750
|
return [3, 4];
|
|
1039
751
|
case 7:
|
|
1040
752
|
this.logger.debug({
|
|
@@ -1078,7 +790,7 @@ var BundleDataClient = (function () {
|
|
|
1078
790
|
});
|
|
1079
791
|
}); })];
|
|
1080
792
|
case 8:
|
|
1081
|
-
|
|
793
|
+
_d.sent();
|
|
1082
794
|
start = performance.now();
|
|
1083
795
|
promises = [
|
|
1084
796
|
validatedBundleV3Fills.length > 0
|
|
@@ -1104,7 +816,7 @@ var BundleDataClient = (function () {
|
|
|
1104
816
|
];
|
|
1105
817
|
return [4, Promise.all(promises)];
|
|
1106
818
|
case 9:
|
|
1107
|
-
|
|
819
|
+
_c = _d.sent(), v3FillLpFees = _c[0], v3SlowFillLpFees = _c[1], v3UnexecutableSlowFillLpFees = _c[2];
|
|
1108
820
|
this.logger.debug({
|
|
1109
821
|
at: "BundleDataClient#loadData",
|
|
1110
822
|
message: "Computed batch async LP fees in ".concat(performance.now() - start, "ms."),
|
|
@@ -1236,7 +948,8 @@ var BundleDataClient = (function () {
|
|
|
1236
948
|
switch (_c.label) {
|
|
1237
949
|
case 0:
|
|
1238
950
|
blockRangeForChain = blockRangesForChains[index];
|
|
1239
|
-
if (!(0, utils_1.isDefined)(blockRangeForChain) ||
|
|
951
|
+
if (!(0, utils_1.isDefined)(blockRangeForChain) ||
|
|
952
|
+
(0, utils_2.isChainDisabledAtBlock)(chainId, blockRangesForChains[0][0], this.clients.configStoreClient)) {
|
|
1240
953
|
return [2];
|
|
1241
954
|
}
|
|
1242
955
|
_startBlockForChain = blockRangeForChain[0], _endBlockForChain = blockRangeForChain[1];
|