@across-protocol/sdk 4.3.48 → 4.3.49-alpha.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/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.d.ts +5 -2
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js +106 -75
- package/dist/cjs/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.d.ts +5 -2
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js +146 -125
- package/dist/esm/clients/BundleDataClient/utils/DataworkerUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts +5 -2
- package/dist/types/clients/BundleDataClient/utils/DataworkerUtils.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +2 -2
- package/package.json +1 -1
- package/src/clients/BundleDataClient/utils/DataworkerUtils.ts +65 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3 } from "../../../interfaces";
|
|
1
|
+
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3, SpokePoolClientsByChain } from "../../../interfaces";
|
|
2
2
|
import { AnyObject } from "../../../utils";
|
|
3
3
|
import { PoolRebalanceRoot } from "./PoolRebalanceUtils";
|
|
4
4
|
import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
|
|
5
5
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
6
|
+
import { BundleDataClient } from "../../BundleDataClient";
|
|
6
7
|
export declare function getRefundsFromBundle(bundleFillsV3: BundleFillsV3, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3): CombinedRefunds;
|
|
7
8
|
export declare function prettyPrintV3SpokePoolEvents(bundleDepositsV3: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, unexecutableSlowFills: BundleExcessSlowFills): AnyObject;
|
|
8
9
|
export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNumbers: number[], blockRangeEndBlockBuffer: {
|
|
@@ -11,4 +12,6 @@ export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNu
|
|
|
11
12
|
export declare function _buildPoolRebalanceRoot(latestMainnetBlock: number, mainnetBundleEndBlock: number, bundleV3Deposits: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, unexecutableSlowFills: BundleExcessSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, clients: {
|
|
12
13
|
hubPoolClient: HubPoolClient;
|
|
13
14
|
configStoreClient: AcrossConfigStoreClient;
|
|
14
|
-
|
|
15
|
+
bundleDataClient: BundleDataClient;
|
|
16
|
+
spokePoolClients: SpokePoolClientsByChain;
|
|
17
|
+
}, maxL1TokenCountOverride?: number): Promise<PoolRebalanceRoot>;
|
|
@@ -62,84 +62,115 @@ function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNumbers, blockRan
|
|
|
62
62
|
}
|
|
63
63
|
exports.getEndBlockBuffers = getEndBlockBuffers;
|
|
64
64
|
function _buildPoolRebalanceRoot(latestMainnetBlock, mainnetBundleEndBlock, bundleV3Deposits, bundleFillsV3, bundleSlowFillsV3, unexecutableSlowFills, expiredDepositsToRefundV3, clients, maxL1TokenCountOverride) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var runningBalances, realizedLpFees, chainWithRefundsOnly, mostRecentProposedRootBundle, blockRangesForChains, prevRootBundleData, prevPoolRebalanceRoot, prevRunningBalances_1, leaves;
|
|
67
|
+
return tslib_1.__generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
runningBalances = {};
|
|
71
|
+
realizedLpFees = {};
|
|
72
|
+
chainWithRefundsOnly = new Set();
|
|
73
|
+
Object.entries(bundleFillsV3).forEach(function (_a) {
|
|
74
|
+
var _repaymentChainId = _a[0], fillsForChain = _a[1];
|
|
75
|
+
var repaymentChainId = Number(_repaymentChainId);
|
|
76
|
+
Object.entries(fillsForChain).forEach(function (_a) {
|
|
77
|
+
var l2TokenAddress = _a[0], _b = _a[1], totalRealizedLpFee = _b.realizedLpFees, totalRefundAmount = _b.totalRefundAmount;
|
|
78
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute((0, utils_1.toAddressType)(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock)) {
|
|
79
|
+
chainWithRefundsOnly.add(repaymentChainId);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var l1Token = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock);
|
|
83
|
+
var l1TokenAddr = l1Token.toNative();
|
|
84
|
+
(0, assert_1.default)(l1Token.isEVM(), "Expected an EVM address: ".concat(l1TokenAddr));
|
|
85
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, repaymentChainId, l1TokenAddr, totalRefundAmount);
|
|
86
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(realizedLpFees, repaymentChainId, l1TokenAddr, totalRealizedLpFee);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
Object.entries(bundleSlowFillsV3).forEach(function (_a) {
|
|
90
|
+
var _destinationChainId = _a[0], depositsForChain = _a[1];
|
|
91
|
+
var destinationChainId = Number(_destinationChainId);
|
|
92
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
93
|
+
var outputToken = _a[0], deposits = _a[1];
|
|
94
|
+
deposits.forEach(function (deposit) {
|
|
95
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
96
|
+
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(utils_1.fixedPointAdjustment);
|
|
97
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount.sub(lpFee));
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
Object.entries(unexecutableSlowFills).forEach(function (_a) {
|
|
102
|
+
var _destinationChainId = _a[0], slowFilledDepositsForChain = _a[1];
|
|
103
|
+
var destinationChainId = Number(_destinationChainId);
|
|
104
|
+
Object.entries(slowFilledDepositsForChain).forEach(function (_a) {
|
|
105
|
+
var outputToken = _a[0], slowFilledDeposits = _a[1];
|
|
106
|
+
slowFilledDeposits.forEach(function (deposit) {
|
|
107
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
108
|
+
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(utils_1.fixedPointAdjustment);
|
|
109
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), lpFee.sub(deposit.inputAmount));
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
Object.entries(bundleV3Deposits).forEach(function (_a) {
|
|
114
|
+
var depositsForChain = _a[1];
|
|
115
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
116
|
+
var deposits = _a[1];
|
|
117
|
+
deposits.forEach(function (deposit) {
|
|
118
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
(0, PoolRebalanceUtils_1.updateRunningBalanceForDeposit)(runningBalances, clients.hubPoolClient, deposit, deposit.inputAmount.mul(-1), mainnetBundleEndBlock);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
Object.entries(expiredDepositsToRefundV3).forEach(function (_a) {
|
|
126
|
+
var _originChainId = _a[0], depositsForChain = _a[1];
|
|
127
|
+
var originChainId = Number(_originChainId);
|
|
128
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
129
|
+
var inputToken = _a[0], deposits = _a[1];
|
|
130
|
+
deposits.forEach(function (deposit) {
|
|
131
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
132
|
+
chainWithRefundsOnly.add(deposit.originChainId);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(inputToken, originChainId), originChainId, mainnetBundleEndBlock);
|
|
136
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
if (!(!clients.hubPoolClient.hasPendingProposal() ||
|
|
141
|
+
clients.hubPoolClient.getPendingRootBundle().bundleEvaluationBlockNumbers[1] <= mainnetBundleEndBlock)) return [3, 1];
|
|
142
|
+
(0, PoolRebalanceUtils_1.addLastRunningBalance)(latestMainnetBlock, runningBalances, clients.hubPoolClient);
|
|
143
|
+
return [3, 4];
|
|
144
|
+
case 1:
|
|
145
|
+
mostRecentProposedRootBundle = clients.hubPoolClient.getLatestProposedRootBundle();
|
|
146
|
+
blockRangesForChains = (0, utils_1.getImpliedBundleBlockRanges)(clients.hubPoolClient, clients.configStoreClient, mostRecentProposedRootBundle);
|
|
147
|
+
return [4, clients.bundleDataClient.loadData(blockRangesForChains, clients.spokePoolClients, true)];
|
|
148
|
+
case 2:
|
|
149
|
+
prevRootBundleData = _a.sent();
|
|
150
|
+
return [4, _buildPoolRebalanceRoot(latestMainnetBlock, blockRangesForChains[0][1], prevRootBundleData.bundleDepositsV3, prevRootBundleData.bundleFillsV3, prevRootBundleData.bundleSlowFillsV3, prevRootBundleData.unexecutableSlowFills, prevRootBundleData.expiredDepositsToRefundV3, clients, maxL1TokenCountOverride)];
|
|
151
|
+
case 3:
|
|
152
|
+
prevPoolRebalanceRoot = _a.sent();
|
|
153
|
+
prevRunningBalances_1 = prevPoolRebalanceRoot.runningBalances;
|
|
154
|
+
Object.keys(runningBalances).forEach(function (repaymentChainId) {
|
|
155
|
+
Object.keys(runningBalances[Number(repaymentChainId)]).forEach(function (l1TokenAddress) {
|
|
156
|
+
var _a;
|
|
157
|
+
var updateRunningBalanceAmount = (_a = prevRunningBalances_1[Number(repaymentChainId)]) === null || _a === void 0 ? void 0 : _a[l1TokenAddress];
|
|
158
|
+
var fallbackRunningBalance = clients.hubPoolClient.getRunningBalanceBeforeBlockForChain(latestMainnetBlock, Number(repaymentChainId), utils_1.EvmAddress.from(l1TokenAddress)).runningBalance;
|
|
159
|
+
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, Number(repaymentChainId), l1TokenAddress, updateRunningBalanceAmount !== null && updateRunningBalanceAmount !== void 0 ? updateRunningBalanceAmount : fallbackRunningBalance);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
_a.label = 4;
|
|
163
|
+
case 4:
|
|
164
|
+
leaves = (0, PoolRebalanceUtils_1.constructPoolRebalanceLeaves)(mainnetBundleEndBlock, runningBalances, realizedLpFees, Array.from(chainWithRefundsOnly).filter(function (chainId) { return !Object.keys(runningBalances).includes(chainId.toString()); }), clients.configStoreClient, maxL1TokenCountOverride);
|
|
165
|
+
return [2, {
|
|
166
|
+
runningBalances: runningBalances,
|
|
167
|
+
realizedLpFees: realizedLpFees,
|
|
168
|
+
leaves: leaves,
|
|
169
|
+
tree: (0, MerkleTreeUtils_1.buildPoolRebalanceLeafTree)(leaves),
|
|
170
|
+
}];
|
|
76
171
|
}
|
|
77
|
-
var l1Token = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock);
|
|
78
|
-
var l1TokenAddr = l1Token.toNative();
|
|
79
|
-
(0, assert_1.default)(l1Token.isEVM(), "Expected an EVM address: ".concat(l1TokenAddr));
|
|
80
|
-
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, repaymentChainId, l1TokenAddr, totalRefundAmount);
|
|
81
|
-
(0, PoolRebalanceUtils_1.updateRunningBalance)(realizedLpFees, repaymentChainId, l1TokenAddr, totalRealizedLpFee);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
Object.entries(bundleSlowFillsV3).forEach(function (_a) {
|
|
85
|
-
var _destinationChainId = _a[0], depositsForChain = _a[1];
|
|
86
|
-
var destinationChainId = Number(_destinationChainId);
|
|
87
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
88
|
-
var outputToken = _a[0], deposits = _a[1];
|
|
89
|
-
deposits.forEach(function (deposit) {
|
|
90
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
91
|
-
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(utils_1.fixedPointAdjustment);
|
|
92
|
-
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount.sub(lpFee));
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
Object.entries(unexecutableSlowFills).forEach(function (_a) {
|
|
97
|
-
var _destinationChainId = _a[0], slowFilledDepositsForChain = _a[1];
|
|
98
|
-
var destinationChainId = Number(_destinationChainId);
|
|
99
|
-
Object.entries(slowFilledDepositsForChain).forEach(function (_a) {
|
|
100
|
-
var outputToken = _a[0], slowFilledDeposits = _a[1];
|
|
101
|
-
slowFilledDeposits.forEach(function (deposit) {
|
|
102
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
103
|
-
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(utils_1.fixedPointAdjustment);
|
|
104
|
-
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), lpFee.sub(deposit.inputAmount));
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
Object.entries(bundleV3Deposits).forEach(function (_a) {
|
|
109
|
-
var depositsForChain = _a[1];
|
|
110
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
111
|
-
var deposits = _a[1];
|
|
112
|
-
deposits.forEach(function (deposit) {
|
|
113
|
-
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
(0, PoolRebalanceUtils_1.updateRunningBalanceForDeposit)(runningBalances, clients.hubPoolClient, deposit, deposit.inputAmount.mul(-1), mainnetBundleEndBlock);
|
|
117
|
-
});
|
|
118
172
|
});
|
|
119
173
|
});
|
|
120
|
-
Object.entries(expiredDepositsToRefundV3).forEach(function (_a) {
|
|
121
|
-
var _originChainId = _a[0], depositsForChain = _a[1];
|
|
122
|
-
var originChainId = Number(_originChainId);
|
|
123
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
124
|
-
var inputToken = _a[0], deposits = _a[1];
|
|
125
|
-
deposits.forEach(function (deposit) {
|
|
126
|
-
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
127
|
-
chainWithRefundsOnly.add(deposit.originChainId);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock((0, utils_1.toAddressType)(inputToken, originChainId), originChainId, mainnetBundleEndBlock);
|
|
131
|
-
(0, PoolRebalanceUtils_1.updateRunningBalance)(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
(0, PoolRebalanceUtils_1.addLastRunningBalance)(latestMainnetBlock, runningBalances, clients.hubPoolClient);
|
|
136
|
-
var leaves = (0, PoolRebalanceUtils_1.constructPoolRebalanceLeaves)(mainnetBundleEndBlock, runningBalances, realizedLpFees, Array.from(chainWithRefundsOnly).filter(function (chainId) { return !Object.keys(runningBalances).includes(chainId.toString()); }), clients.configStoreClient, maxL1TokenCountOverride);
|
|
137
|
-
return {
|
|
138
|
-
runningBalances: runningBalances,
|
|
139
|
-
realizedLpFees: realizedLpFees,
|
|
140
|
-
leaves: leaves,
|
|
141
|
-
tree: (0, MerkleTreeUtils_1.buildPoolRebalanceLeafTree)(leaves),
|
|
142
|
-
};
|
|
143
174
|
}
|
|
144
175
|
exports._buildPoolRebalanceRoot = _buildPoolRebalanceRoot;
|
|
145
176
|
//# sourceMappingURL=DataworkerUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataworkerUtils.js","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":";;;;AACA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"DataworkerUtils.js","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":";;;;AACA,0DAA4B;AAa5B,wCASwB;AACxB,2DAM8B;AAI9B,qDAA+D;AAG/D,SAAgB,oBAAoB,CAClC,aAA4B,EAC5B,yBAAoD;IAEpD,IAAM,eAAe,GAIjB,EAAE,CAAC;IACP,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,UAAC,EAAiC;;YAAhC,gBAAgB,QAAA,EAAE,aAAa,QAAA;QACrE,MAAA,eAAe,CAAC,gBAAgB,qCAAhC,eAAe,CAAC,gBAAgB,IAAM,EAAE,EAAC;QACzC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,UAAC,EAA6B;gBAA5B,cAAc,QAAA,EAAI,OAAO,gBAAA;YAE/D,IAAI,OAAO,KAAK,SAAS,EAAE;gBACzB,OAAO;aACR;YAED,IAAM,kBAAkB,wBAAQ,OAAO,CAAE,CAAC;YAC1C,IAAI,eAAe,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,KAAK,SAAS,EAAE;gBACnE,eAAe,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;aACxE;iBAAM;gBAGL,eAAe,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,yCAC5C,eAAe,CAAC,gBAAgB,CAAC,CAAC,cAAc,CAAC,GACjD,kBAAkB,CACtB,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,OAAO,CAAC,UAAC,EAAiC;;YAAhC,aAAa,QAAA,EAAE,gBAAgB,QAAA;QACjF,MAAA,eAAe,CAAC,aAAa,qCAA7B,eAAe,CAAC,aAAa,IAAM,EAAE,EAAC;QACtC,MAAM,CAAC,OAAO,C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,EACf,MAAM,CAAC,gBAAgB,CAAC,EACxB,cAAc,EACd,0BAA0B,aAA1B,0BAA0B,cAA1B,0BAA0B,GAAI,sBAAsB,CACrD,CAAC;wBACJ,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;;;oBAGC,MAAM,GAAwB,IAAA,iDAA4B,EAC9D,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,UAAC,OAAO,IAAK,OAAA,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAA1D,CAA0D,CAAC,EAChH,OAAO,CAAC,iBAAiB,EACzB,uBAAuB,CACxB,CAAC;oBAEF,WAAO;4BACL,eAAe,iBAAA;4BACf,cAAc,gBAAA;4BACd,MAAM,QAAA;4BACN,IAAI,EAAE,IAAA,4CAA0B,EAAC,MAAM,CAAC;yBACzC,EAAC;;;;CACH;AAjQD,0DAiQC"}
|
|
@@ -74,8 +74,8 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
74
74
|
transactionHash?: string | undefined;
|
|
75
75
|
transactionIndex?: number | undefined;
|
|
76
76
|
}[];
|
|
77
|
-
refunds: Record<string, BigNumber>;
|
|
78
77
|
realizedLpFees: BigNumber;
|
|
78
|
+
refunds: Record<string, BigNumber>;
|
|
79
79
|
totalRefundAmount: BigNumber;
|
|
80
80
|
}>>;
|
|
81
81
|
bundleSlowFillsV3: Record<string, Record<string, {
|
|
@@ -334,8 +334,8 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
334
334
|
transactionHash?: string | undefined;
|
|
335
335
|
transactionIndex?: number | undefined;
|
|
336
336
|
}[];
|
|
337
|
-
refunds: Record<string, BigNumber>;
|
|
338
337
|
realizedLpFees: BigNumber;
|
|
338
|
+
refunds: Record<string, BigNumber>;
|
|
339
339
|
totalRefundAmount: BigNumber;
|
|
340
340
|
}>>, null>;
|
|
341
341
|
}>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3 } from "../../../interfaces";
|
|
1
|
+
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3, SpokePoolClientsByChain } from "../../../interfaces";
|
|
2
2
|
import { AnyObject } from "../../../utils";
|
|
3
3
|
import { PoolRebalanceRoot } from "./PoolRebalanceUtils";
|
|
4
4
|
import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
|
|
5
5
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
6
|
+
import { BundleDataClient } from "../../BundleDataClient";
|
|
6
7
|
export declare function getRefundsFromBundle(bundleFillsV3: BundleFillsV3, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3): CombinedRefunds;
|
|
7
8
|
export declare function prettyPrintV3SpokePoolEvents(bundleDepositsV3: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, unexecutableSlowFills: BundleExcessSlowFills): AnyObject;
|
|
8
9
|
export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNumbers: number[], blockRangeEndBlockBuffer: {
|
|
@@ -11,4 +12,6 @@ export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNu
|
|
|
11
12
|
export declare function _buildPoolRebalanceRoot(latestMainnetBlock: number, mainnetBundleEndBlock: number, bundleV3Deposits: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, unexecutableSlowFills: BundleExcessSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, clients: {
|
|
12
13
|
hubPoolClient: HubPoolClient;
|
|
13
14
|
configStoreClient: AcrossConfigStoreClient;
|
|
14
|
-
|
|
15
|
+
bundleDataClient: BundleDataClient;
|
|
16
|
+
spokePoolClients: SpokePoolClientsByChain;
|
|
17
|
+
}, maxL1TokenCountOverride?: number): Promise<PoolRebalanceRoot>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
// Create a combined `refunds` object containing refunds for V2 + V3 fills
|
|
3
3
|
import assert from "assert";
|
|
4
|
-
import { bnZero, fixedPointAdjustment, count2DDictionaryValues, count3DDictionaryValues, toAddressType, } from "../../../utils";
|
|
4
|
+
import { bnZero, fixedPointAdjustment, count2DDictionaryValues, count3DDictionaryValues, toAddressType, getImpliedBundleBlockRanges, EvmAddress, } from "../../../utils";
|
|
5
5
|
import { addLastRunningBalance, constructPoolRebalanceLeaves, updateRunningBalance, updateRunningBalanceForDeposit, } from "./PoolRebalanceUtils";
|
|
6
6
|
import { buildPoolRebalanceLeafTree } from "./MerkleTreeUtils";
|
|
7
7
|
// and expired deposits.
|
|
@@ -74,131 +74,152 @@ export function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNumbers, b
|
|
|
74
74
|
return chainIdListForBundleEvaluationBlockNumbers.map(function (chainId) { var _a; return (_a = blockRangeEndBlockBuffer[chainId]) !== null && _a !== void 0 ? _a : 0; });
|
|
75
75
|
}
|
|
76
76
|
export function _buildPoolRebalanceRoot(latestMainnetBlock, mainnetBundleEndBlock, bundleV3Deposits, bundleFillsV3, bundleSlowFillsV3, unexecutableSlowFills, expiredDepositsToRefundV3, clients, maxL1TokenCountOverride) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var runningBalances, realizedLpFees, chainWithRefundsOnly, mostRecentProposedRootBundle, blockRangesForChains, prevRootBundleData, prevPoolRebalanceRoot, prevRunningBalances_1, leaves;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
runningBalances = {};
|
|
83
|
+
realizedLpFees = {};
|
|
84
|
+
chainWithRefundsOnly = new Set();
|
|
85
|
+
/**
|
|
86
|
+
* REFUNDS FOR FAST FILLS
|
|
87
|
+
*/
|
|
88
|
+
// Add running balances and lp fees for v3 relayer refunds using BundleDataClient.bundleFillsV3. Refunds
|
|
89
|
+
// should be equal to inputAmount - lpFees so that relayers get to keep the relayer fee. Add the refund amount
|
|
90
|
+
// to the running balance for the repayment chain.
|
|
91
|
+
Object.entries(bundleFillsV3).forEach(function (_a) {
|
|
92
|
+
var _repaymentChainId = _a[0], fillsForChain = _a[1];
|
|
93
|
+
var repaymentChainId = Number(_repaymentChainId);
|
|
94
|
+
Object.entries(fillsForChain).forEach(function (_a) {
|
|
95
|
+
var l2TokenAddress = _a[0], _b = _a[1], totalRealizedLpFee = _b.realizedLpFees, totalRefundAmount = _b.totalRefundAmount;
|
|
96
|
+
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
97
|
+
// there are no relevant L1 running balances.
|
|
98
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(toAddressType(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock)) {
|
|
99
|
+
chainWithRefundsOnly.add(repaymentChainId);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
var l1Token = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock);
|
|
103
|
+
var l1TokenAddr = l1Token.toNative();
|
|
104
|
+
assert(l1Token.isEVM(), "Expected an EVM address: ".concat(l1TokenAddr));
|
|
105
|
+
updateRunningBalance(runningBalances, repaymentChainId, l1TokenAddr, totalRefundAmount);
|
|
106
|
+
updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenAddr, totalRealizedLpFee);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* PAYMENTS SLOW FILLS
|
|
111
|
+
*/
|
|
112
|
+
// Add running balances and lp fees for v3 slow fills using BundleDataClient.bundleSlowFillsV3.
|
|
113
|
+
// Slow fills should still increment bundleLpFees and updatedOutputAmount should be equal to inputAmount - lpFees.
|
|
114
|
+
// Increment the updatedOutputAmount to the destination chain.
|
|
115
|
+
Object.entries(bundleSlowFillsV3).forEach(function (_a) {
|
|
116
|
+
var _destinationChainId = _a[0], depositsForChain = _a[1];
|
|
117
|
+
var destinationChainId = Number(_destinationChainId);
|
|
118
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
119
|
+
var outputToken = _a[0], deposits = _a[1];
|
|
120
|
+
deposits.forEach(function (deposit) {
|
|
121
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
122
|
+
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
123
|
+
updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount.sub(lpFee));
|
|
124
|
+
// Slow fill LP fees are accounted for when the slow fill executes and a V3FilledRelay is emitted. i.e. when
|
|
125
|
+
// the slow fill execution is included in bundleFillsV3.
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* EXCESSES FROM UNEXECUTABLE SLOW FILLS
|
|
131
|
+
*/
|
|
132
|
+
// Subtract destination chain running balances for BundleDataClient.unexecutableSlowFills.
|
|
133
|
+
// These are all slow fills that are impossible to execute and therefore the amount to return would be
|
|
134
|
+
// the updatedOutputAmount = inputAmount - lpFees.
|
|
135
|
+
Object.entries(unexecutableSlowFills).forEach(function (_a) {
|
|
136
|
+
var _destinationChainId = _a[0], slowFilledDepositsForChain = _a[1];
|
|
137
|
+
var destinationChainId = Number(_destinationChainId);
|
|
138
|
+
Object.entries(slowFilledDepositsForChain).forEach(function (_a) {
|
|
139
|
+
var outputToken = _a[0], slowFilledDeposits = _a[1];
|
|
140
|
+
slowFilledDeposits.forEach(function (deposit) {
|
|
141
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
142
|
+
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
143
|
+
updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), lpFee.sub(deposit.inputAmount));
|
|
144
|
+
// Slow fills don't add to lpFees, only when the slow fill is executed and a V3FilledRelay is emitted, so
|
|
145
|
+
// we don't need to subtract it here. Moreover, the HubPoole expects bundleLpFees to be > 0.
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* DEPOSITS
|
|
151
|
+
*/
|
|
152
|
+
// Handle v3Deposits. These decrement running balances from the origin chain equal to the inputAmount.
|
|
153
|
+
// There should not be early deposits in v3.
|
|
154
|
+
Object.entries(bundleV3Deposits).forEach(function (_a) {
|
|
155
|
+
var depositsForChain = _a[1];
|
|
156
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
157
|
+
var deposits = _a[1];
|
|
158
|
+
deposits.forEach(function (deposit) {
|
|
159
|
+
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
160
|
+
// there are no relevant L1 running balances.
|
|
161
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
updateRunningBalanceForDeposit(runningBalances, clients.hubPoolClient, deposit, deposit.inputAmount.mul(-1), mainnetBundleEndBlock);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* REFUNDS FOR EXPIRED DEPOSITS
|
|
170
|
+
*/
|
|
171
|
+
// Add origin chain running balance for expired v3 deposits. These should refund the inputAmount.
|
|
172
|
+
Object.entries(expiredDepositsToRefundV3).forEach(function (_a) {
|
|
173
|
+
var _originChainId = _a[0], depositsForChain = _a[1];
|
|
174
|
+
var originChainId = Number(_originChainId);
|
|
175
|
+
Object.entries(depositsForChain).forEach(function (_a) {
|
|
176
|
+
var inputToken = _a[0], deposits = _a[1];
|
|
177
|
+
deposits.forEach(function (deposit) {
|
|
178
|
+
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
179
|
+
// there are no relevant L1 running balances.
|
|
180
|
+
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
181
|
+
chainWithRefundsOnly.add(deposit.originChainId);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(inputToken, originChainId), originChainId, mainnetBundleEndBlock);
|
|
185
|
+
updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
if (!(!clients.hubPoolClient.hasPendingProposal() ||
|
|
190
|
+
clients.hubPoolClient.getPendingRootBundle().bundleEvaluationBlockNumbers[1] <= mainnetBundleEndBlock)) return [3 /*break*/, 1];
|
|
191
|
+
addLastRunningBalance(latestMainnetBlock, runningBalances, clients.hubPoolClient);
|
|
192
|
+
return [3 /*break*/, 4];
|
|
193
|
+
case 1:
|
|
194
|
+
mostRecentProposedRootBundle = clients.hubPoolClient.getLatestProposedRootBundle();
|
|
195
|
+
blockRangesForChains = getImpliedBundleBlockRanges(clients.hubPoolClient, clients.configStoreClient, mostRecentProposedRootBundle);
|
|
196
|
+
return [4 /*yield*/, clients.bundleDataClient.loadData(blockRangesForChains, clients.spokePoolClients, true)];
|
|
197
|
+
case 2:
|
|
198
|
+
prevRootBundleData = _a.sent();
|
|
199
|
+
return [4 /*yield*/, _buildPoolRebalanceRoot(latestMainnetBlock, blockRangesForChains[0][1], prevRootBundleData.bundleDepositsV3, prevRootBundleData.bundleFillsV3, prevRootBundleData.bundleSlowFillsV3, prevRootBundleData.unexecutableSlowFills, prevRootBundleData.expiredDepositsToRefundV3, clients, maxL1TokenCountOverride)];
|
|
200
|
+
case 3:
|
|
201
|
+
prevPoolRebalanceRoot = _a.sent();
|
|
202
|
+
prevRunningBalances_1 = prevPoolRebalanceRoot.runningBalances;
|
|
203
|
+
Object.keys(runningBalances).forEach(function (repaymentChainId) {
|
|
204
|
+
Object.keys(runningBalances[Number(repaymentChainId)]).forEach(function (l1TokenAddress) {
|
|
205
|
+
var _a;
|
|
206
|
+
var updateRunningBalanceAmount = (_a = prevRunningBalances_1[Number(repaymentChainId)]) === null || _a === void 0 ? void 0 : _a[l1TokenAddress];
|
|
207
|
+
// If the pending root bundle didn't have a running balance, fall back to the last running balance for that token and chain pair.
|
|
208
|
+
var fallbackRunningBalance = clients.hubPoolClient.getRunningBalanceBeforeBlockForChain(latestMainnetBlock, Number(repaymentChainId), EvmAddress.from(l1TokenAddress)).runningBalance;
|
|
209
|
+
updateRunningBalance(runningBalances, Number(repaymentChainId), l1TokenAddress, updateRunningBalanceAmount !== null && updateRunningBalanceAmount !== void 0 ? updateRunningBalanceAmount : fallbackRunningBalance);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
_a.label = 4;
|
|
213
|
+
case 4:
|
|
214
|
+
leaves = constructPoolRebalanceLeaves(mainnetBundleEndBlock, runningBalances, realizedLpFees, Array.from(chainWithRefundsOnly).filter(function (chainId) { return !Object.keys(runningBalances).includes(chainId.toString()); }), clients.configStoreClient, maxL1TokenCountOverride);
|
|
215
|
+
return [2 /*return*/, {
|
|
216
|
+
runningBalances: runningBalances,
|
|
217
|
+
realizedLpFees: realizedLpFees,
|
|
218
|
+
leaves: leaves,
|
|
219
|
+
tree: buildPoolRebalanceLeafTree(leaves),
|
|
220
|
+
}];
|
|
105
221
|
}
|
|
106
|
-
var l1Token = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(l2TokenAddress, repaymentChainId), repaymentChainId, mainnetBundleEndBlock);
|
|
107
|
-
var l1TokenAddr = l1Token.toNative();
|
|
108
|
-
assert(l1Token.isEVM(), "Expected an EVM address: ".concat(l1TokenAddr));
|
|
109
|
-
updateRunningBalance(runningBalances, repaymentChainId, l1TokenAddr, totalRefundAmount);
|
|
110
|
-
updateRunningBalance(realizedLpFees, repaymentChainId, l1TokenAddr, totalRealizedLpFee);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
/**
|
|
114
|
-
* PAYMENTS SLOW FILLS
|
|
115
|
-
*/
|
|
116
|
-
// Add running balances and lp fees for v3 slow fills using BundleDataClient.bundleSlowFillsV3.
|
|
117
|
-
// Slow fills should still increment bundleLpFees and updatedOutputAmount should be equal to inputAmount - lpFees.
|
|
118
|
-
// Increment the updatedOutputAmount to the destination chain.
|
|
119
|
-
Object.entries(bundleSlowFillsV3).forEach(function (_a) {
|
|
120
|
-
var _destinationChainId = _a[0], depositsForChain = _a[1];
|
|
121
|
-
var destinationChainId = Number(_destinationChainId);
|
|
122
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
123
|
-
var outputToken = _a[0], deposits = _a[1];
|
|
124
|
-
deposits.forEach(function (deposit) {
|
|
125
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
126
|
-
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
127
|
-
updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount.sub(lpFee));
|
|
128
|
-
// Slow fill LP fees are accounted for when the slow fill executes and a V3FilledRelay is emitted. i.e. when
|
|
129
|
-
// the slow fill execution is included in bundleFillsV3.
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
/**
|
|
134
|
-
* EXCESSES FROM UNEXECUTABLE SLOW FILLS
|
|
135
|
-
*/
|
|
136
|
-
// Subtract destination chain running balances for BundleDataClient.unexecutableSlowFills.
|
|
137
|
-
// These are all slow fills that are impossible to execute and therefore the amount to return would be
|
|
138
|
-
// the updatedOutputAmount = inputAmount - lpFees.
|
|
139
|
-
Object.entries(unexecutableSlowFills).forEach(function (_a) {
|
|
140
|
-
var _destinationChainId = _a[0], slowFilledDepositsForChain = _a[1];
|
|
141
|
-
var destinationChainId = Number(_destinationChainId);
|
|
142
|
-
Object.entries(slowFilledDepositsForChain).forEach(function (_a) {
|
|
143
|
-
var outputToken = _a[0], slowFilledDeposits = _a[1];
|
|
144
|
-
slowFilledDeposits.forEach(function (deposit) {
|
|
145
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(outputToken, destinationChainId), destinationChainId, mainnetBundleEndBlock);
|
|
146
|
-
var lpFee = deposit.lpFeePct.mul(deposit.inputAmount).div(fixedPointAdjustment);
|
|
147
|
-
updateRunningBalance(runningBalances, destinationChainId, l1TokenCounterpart.toEvmAddress(), lpFee.sub(deposit.inputAmount));
|
|
148
|
-
// Slow fills don't add to lpFees, only when the slow fill is executed and a V3FilledRelay is emitted, so
|
|
149
|
-
// we don't need to subtract it here. Moreover, the HubPoole expects bundleLpFees to be > 0.
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
/**
|
|
154
|
-
* DEPOSITS
|
|
155
|
-
*/
|
|
156
|
-
// Handle v3Deposits. These decrement running balances from the origin chain equal to the inputAmount.
|
|
157
|
-
// There should not be early deposits in v3.
|
|
158
|
-
Object.entries(bundleV3Deposits).forEach(function (_a) {
|
|
159
|
-
var depositsForChain = _a[1];
|
|
160
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
161
|
-
var deposits = _a[1];
|
|
162
|
-
deposits.forEach(function (deposit) {
|
|
163
|
-
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
164
|
-
// there are no relevant L1 running balances.
|
|
165
|
-
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
updateRunningBalanceForDeposit(runningBalances, clients.hubPoolClient, deposit, deposit.inputAmount.mul(-1), mainnetBundleEndBlock);
|
|
169
|
-
});
|
|
170
222
|
});
|
|
171
223
|
});
|
|
172
|
-
/**
|
|
173
|
-
* REFUNDS FOR EXPIRED DEPOSITS
|
|
174
|
-
*/
|
|
175
|
-
// Add origin chain running balance for expired v3 deposits. These should refund the inputAmount.
|
|
176
|
-
Object.entries(expiredDepositsToRefundV3).forEach(function (_a) {
|
|
177
|
-
var _originChainId = _a[0], depositsForChain = _a[1];
|
|
178
|
-
var originChainId = Number(_originChainId);
|
|
179
|
-
Object.entries(depositsForChain).forEach(function (_a) {
|
|
180
|
-
var inputToken = _a[0], deposits = _a[1];
|
|
181
|
-
deposits.forEach(function (deposit) {
|
|
182
|
-
// If the repayment token and repayment chain ID do not map to a PoolRebalanceRoute graph, then
|
|
183
|
-
// there are no relevant L1 running balances.
|
|
184
|
-
if (!clients.hubPoolClient.l2TokenHasPoolRebalanceRoute(deposit.inputToken, deposit.originChainId, mainnetBundleEndBlock)) {
|
|
185
|
-
chainWithRefundsOnly.add(deposit.originChainId);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
var l1TokenCounterpart = clients.hubPoolClient.getL1TokenForL2TokenAtBlock(toAddressType(inputToken, originChainId), originChainId, mainnetBundleEndBlock);
|
|
189
|
-
updateRunningBalance(runningBalances, originChainId, l1TokenCounterpart.toEvmAddress(), deposit.inputAmount);
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
// Add to the running balance value from the last valid root bundle proposal for {chainId, l1Token}
|
|
194
|
-
// combination if found.
|
|
195
|
-
addLastRunningBalance(latestMainnetBlock, runningBalances, clients.hubPoolClient);
|
|
196
|
-
var leaves = constructPoolRebalanceLeaves(mainnetBundleEndBlock, runningBalances, realizedLpFees, Array.from(chainWithRefundsOnly).filter(function (chainId) { return !Object.keys(runningBalances).includes(chainId.toString()); }), clients.configStoreClient, maxL1TokenCountOverride);
|
|
197
|
-
return {
|
|
198
|
-
runningBalances: runningBalances,
|
|
199
|
-
realizedLpFees: realizedLpFees,
|
|
200
|
-
leaves: leaves,
|
|
201
|
-
tree: buildPoolRebalanceLeafTree(leaves),
|
|
202
|
-
};
|
|
203
224
|
}
|
|
204
225
|
//# sourceMappingURL=DataworkerUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataworkerUtils.js","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"DataworkerUtils.js","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,OAAO,MAAM,MAAM,QAAQ,CAAC;AAa5B,OAAO,EACL,MAAM,EAEN,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,EACb,2BAA2B,EAC3B,UAAU,GACX,M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|
74
74
|
transactionHash?: string | undefined;
|
|
75
75
|
transactionIndex?: number | undefined;
|
|
76
76
|
}[];
|
|
77
|
-
refunds: Record<string, BigNumber>;
|
|
78
77
|
realizedLpFees: BigNumber;
|
|
78
|
+
refunds: Record<string, BigNumber>;
|
|
79
79
|
totalRefundAmount: BigNumber;
|
|
80
80
|
}>>;
|
|
81
81
|
bundleSlowFillsV3: Record<string, Record<string, {
|
|
@@ -334,8 +334,8 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
334
334
|
transactionHash?: string | undefined;
|
|
335
335
|
transactionIndex?: number | undefined;
|
|
336
336
|
}[];
|
|
337
|
-
refunds: Record<string, BigNumber>;
|
|
338
337
|
realizedLpFees: BigNumber;
|
|
338
|
+
refunds: Record<string, BigNumber>;
|
|
339
339
|
totalRefundAmount: BigNumber;
|
|
340
340
|
}>>, null>;
|
|
341
341
|
}>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3 } from "../../../interfaces";
|
|
1
|
+
import { BundleDepositsV3, BundleExcessSlowFills, BundleFillsV3, BundleSlowFills, CombinedRefunds, ExpiredDepositsToRefundV3, SpokePoolClientsByChain } from "../../../interfaces";
|
|
2
2
|
import { AnyObject } from "../../../utils";
|
|
3
3
|
import { PoolRebalanceRoot } from "./PoolRebalanceUtils";
|
|
4
4
|
import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
|
|
5
5
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
6
|
+
import { BundleDataClient } from "../../BundleDataClient";
|
|
6
7
|
export declare function getRefundsFromBundle(bundleFillsV3: BundleFillsV3, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3): CombinedRefunds;
|
|
7
8
|
export declare function prettyPrintV3SpokePoolEvents(bundleDepositsV3: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, unexecutableSlowFills: BundleExcessSlowFills): AnyObject;
|
|
8
9
|
export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNumbers: number[], blockRangeEndBlockBuffer: {
|
|
@@ -11,5 +12,7 @@ export declare function getEndBlockBuffers(chainIdListForBundleEvaluationBlockNu
|
|
|
11
12
|
export declare function _buildPoolRebalanceRoot(latestMainnetBlock: number, mainnetBundleEndBlock: number, bundleV3Deposits: BundleDepositsV3, bundleFillsV3: BundleFillsV3, bundleSlowFillsV3: BundleSlowFills, unexecutableSlowFills: BundleExcessSlowFills, expiredDepositsToRefundV3: ExpiredDepositsToRefundV3, clients: {
|
|
12
13
|
hubPoolClient: HubPoolClient;
|
|
13
14
|
configStoreClient: AcrossConfigStoreClient;
|
|
14
|
-
|
|
15
|
+
bundleDataClient: BundleDataClient;
|
|
16
|
+
spokePoolClients: SpokePoolClientsByChain;
|
|
17
|
+
}, maxL1TokenCountOverride?: number): Promise<PoolRebalanceRoot>;
|
|
15
18
|
//# sourceMappingURL=DataworkerUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataworkerUtils.d.ts","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,eAAe,EACf,yBAAyB,
|
|
1
|
+
{"version":3,"file":"DataworkerUtils.d.ts","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/utils/DataworkerUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,eAAe,EACf,yBAAyB,EAIzB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,SAAS,EAOV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,iBAAiB,EAGlB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,EAC5B,yBAAyB,EAAE,yBAAyB,GACnD,eAAe,CA2CjB;AAED,wBAAgB,4BAA4B,CAC1C,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,eAAe,EAClC,yBAAyB,EAAE,yBAAyB,EACpD,qBAAqB,EAAE,qBAAqB,GAC3C,SAAS,CAQX;AAED,wBAAgB,kBAAkB,CAChC,0CAA0C,EAAE,MAAM,EAAE,EACpD,wBAAwB,EAAE;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACtD,MAAM,EAAE,CAcV;AAED,wBAAsB,uBAAuB,CAC3C,kBAAkB,EAAE,MAAM,EAC1B,qBAAqB,EAAE,MAAM,EAC7B,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,eAAe,EAClC,qBAAqB,EAAE,qBAAqB,EAC5C,yBAAyB,EAAE,yBAAyB,EACpD,OAAO,EAAE;IACP,aAAa,EAAE,aAAa,CAAC;IAC7B,iBAAiB,EAAE,uBAAuB,CAAC;IAC3C,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,gBAAgB,EAAE,uBAAuB,CAAC;CAC3C,EACD,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAkP5B"}
|
|
@@ -74,8 +74,8 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
74
74
|
transactionHash?: string | undefined;
|
|
75
75
|
transactionIndex?: number | undefined;
|
|
76
76
|
}[];
|
|
77
|
-
refunds: Record<string, BigNumber>;
|
|
78
77
|
realizedLpFees: BigNumber;
|
|
78
|
+
refunds: Record<string, BigNumber>;
|
|
79
79
|
totalRefundAmount: BigNumber;
|
|
80
80
|
}>>;
|
|
81
81
|
bundleSlowFillsV3: Record<string, Record<string, {
|
|
@@ -334,8 +334,8 @@ export declare const BundleDataSS: import("superstruct").Struct<{
|
|
|
334
334
|
transactionHash?: string | undefined;
|
|
335
335
|
transactionIndex?: number | undefined;
|
|
336
336
|
}[];
|
|
337
|
-
refunds: Record<string, BigNumber>;
|
|
338
337
|
realizedLpFees: BigNumber;
|
|
338
|
+
refunds: Record<string, BigNumber>;
|
|
339
339
|
totalRefundAmount: BigNumber;
|
|
340
340
|
}>>, null>;
|
|
341
341
|
}>;
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PoolRebalanceLeaf,
|
|
11
11
|
Refund,
|
|
12
12
|
RunningBalances,
|
|
13
|
+
SpokePoolClientsByChain,
|
|
13
14
|
} from "../../../interfaces";
|
|
14
15
|
import {
|
|
15
16
|
bnZero,
|
|
@@ -18,6 +19,8 @@ import {
|
|
|
18
19
|
count2DDictionaryValues,
|
|
19
20
|
count3DDictionaryValues,
|
|
20
21
|
toAddressType,
|
|
22
|
+
getImpliedBundleBlockRanges,
|
|
23
|
+
EvmAddress,
|
|
21
24
|
} from "../../../utils";
|
|
22
25
|
import {
|
|
23
26
|
addLastRunningBalance,
|
|
@@ -28,6 +31,7 @@ import {
|
|
|
28
31
|
} from "./PoolRebalanceUtils";
|
|
29
32
|
import { AcrossConfigStoreClient } from "../../AcrossConfigStoreClient";
|
|
30
33
|
import { HubPoolClient } from "../../HubPoolClient";
|
|
34
|
+
import { BundleDataClient } from "../../BundleDataClient";
|
|
31
35
|
import { buildPoolRebalanceLeafTree } from "./MerkleTreeUtils";
|
|
32
36
|
|
|
33
37
|
// and expired deposits.
|
|
@@ -114,7 +118,7 @@ export function getEndBlockBuffers(
|
|
|
114
118
|
return chainIdListForBundleEvaluationBlockNumbers.map((chainId: number) => blockRangeEndBlockBuffer[chainId] ?? 0);
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
export function _buildPoolRebalanceRoot(
|
|
121
|
+
export async function _buildPoolRebalanceRoot(
|
|
118
122
|
latestMainnetBlock: number,
|
|
119
123
|
mainnetBundleEndBlock: number,
|
|
120
124
|
bundleV3Deposits: BundleDepositsV3,
|
|
@@ -122,9 +126,14 @@ export function _buildPoolRebalanceRoot(
|
|
|
122
126
|
bundleSlowFillsV3: BundleSlowFills,
|
|
123
127
|
unexecutableSlowFills: BundleExcessSlowFills,
|
|
124
128
|
expiredDepositsToRefundV3: ExpiredDepositsToRefundV3,
|
|
125
|
-
clients: {
|
|
129
|
+
clients: {
|
|
130
|
+
hubPoolClient: HubPoolClient;
|
|
131
|
+
configStoreClient: AcrossConfigStoreClient;
|
|
132
|
+
bundleDataClient: BundleDataClient;
|
|
133
|
+
spokePoolClients: SpokePoolClientsByChain;
|
|
134
|
+
},
|
|
126
135
|
maxL1TokenCountOverride?: number
|
|
127
|
-
): PoolRebalanceRoot {
|
|
136
|
+
): Promise<PoolRebalanceRoot> {
|
|
128
137
|
// Running balances are the amount of tokens that we need to send to each SpokePool to pay for all instant and
|
|
129
138
|
// slow relay refunds. They are decreased by the amount of funds already held by the SpokePool. Balances are keyed
|
|
130
139
|
// by the SpokePool's network and L1 token equivalent of the L2 token to refund.
|
|
@@ -297,9 +306,59 @@ export function _buildPoolRebalanceRoot(
|
|
|
297
306
|
});
|
|
298
307
|
});
|
|
299
308
|
|
|
300
|
-
// Add to the running balance value from the last valid root bundle proposal
|
|
301
|
-
//
|
|
302
|
-
|
|
309
|
+
// Add to the running balance value from the last valid root bundle proposal. A root bundle proposal which is still in liveness and has not yet been executed counts as a valid proposal.
|
|
310
|
+
// If the mainnetBundleEndBlock for this pool rebalance root corresponds to the pending root bundle or some root bundle before the pending root bundle, then we can fetch running balances directly from `ExecutedRootBundle` events.
|
|
311
|
+
if (
|
|
312
|
+
!clients.hubPoolClient.hasPendingProposal() ||
|
|
313
|
+
clients.hubPoolClient.getPendingRootBundle()!.bundleEvaluationBlockNumbers[1] <= mainnetBundleEndBlock
|
|
314
|
+
) {
|
|
315
|
+
addLastRunningBalance(latestMainnetBlock, runningBalances, clients.hubPoolClient);
|
|
316
|
+
} else {
|
|
317
|
+
// Otherwise, the pool rebalance root for this root bundle must be for an optimistic proposal, so we need to reconstruct the pool rebalance root for the pending root bundle to obtain the running balances.
|
|
318
|
+
// @dev It is safe to index the hub pool client's proposed root bundles here since there is guaranteed to be a pending proposal in this code block.
|
|
319
|
+
const mostRecentProposedRootBundle = clients.hubPoolClient.getLatestProposedRootBundle();
|
|
320
|
+
const blockRangesForChains = getImpliedBundleBlockRanges(
|
|
321
|
+
clients.hubPoolClient,
|
|
322
|
+
clients.configStoreClient,
|
|
323
|
+
mostRecentProposedRootBundle
|
|
324
|
+
);
|
|
325
|
+
// We are loading data from a pending root bundle, so we want to use arweave if possible.
|
|
326
|
+
const prevRootBundleData = await clients.bundleDataClient.loadData(
|
|
327
|
+
blockRangesForChains,
|
|
328
|
+
clients.spokePoolClients,
|
|
329
|
+
true
|
|
330
|
+
);
|
|
331
|
+
const prevPoolRebalanceRoot = await _buildPoolRebalanceRoot(
|
|
332
|
+
latestMainnetBlock,
|
|
333
|
+
blockRangesForChains[0][1],
|
|
334
|
+
prevRootBundleData.bundleDepositsV3,
|
|
335
|
+
prevRootBundleData.bundleFillsV3,
|
|
336
|
+
prevRootBundleData.bundleSlowFillsV3,
|
|
337
|
+
prevRootBundleData.unexecutableSlowFills,
|
|
338
|
+
prevRootBundleData.expiredDepositsToRefundV3,
|
|
339
|
+
clients,
|
|
340
|
+
maxL1TokenCountOverride
|
|
341
|
+
);
|
|
342
|
+
// Update the running balances by adding the pending root bundle's running balance amounts to this bundle's running balances.
|
|
343
|
+
const { runningBalances: prevRunningBalances } = prevPoolRebalanceRoot;
|
|
344
|
+
Object.keys(runningBalances).forEach((repaymentChainId) => {
|
|
345
|
+
Object.keys(runningBalances[Number(repaymentChainId)]).forEach((l1TokenAddress) => {
|
|
346
|
+
const updateRunningBalanceAmount = prevRunningBalances[Number(repaymentChainId)]?.[l1TokenAddress];
|
|
347
|
+
// If the pending root bundle didn't have a running balance, fall back to the last running balance for that token and chain pair.
|
|
348
|
+
const { runningBalance: fallbackRunningBalance } = clients.hubPoolClient.getRunningBalanceBeforeBlockForChain(
|
|
349
|
+
latestMainnetBlock,
|
|
350
|
+
Number(repaymentChainId),
|
|
351
|
+
EvmAddress.from(l1TokenAddress)
|
|
352
|
+
);
|
|
353
|
+
updateRunningBalance(
|
|
354
|
+
runningBalances,
|
|
355
|
+
Number(repaymentChainId),
|
|
356
|
+
l1TokenAddress,
|
|
357
|
+
updateRunningBalanceAmount ?? fallbackRunningBalance
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
|
303
362
|
|
|
304
363
|
const leaves: PoolRebalanceLeaf[] = constructPoolRebalanceLeaves(
|
|
305
364
|
mainnetBundleEndBlock,
|