Skip to content

Commit 21ba2c1

Browse files
committed
Reformat
1 parent 4426aec commit 21ba2c1

File tree

1 file changed

+63
-75
lines changed

1 file changed

+63
-75
lines changed

src/dataworker/PoolRebalanceUtils.ts

Lines changed: 63 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { HubPoolClient } from "../clients";
33
import { PendingRootBundle, PoolRebalanceLeaf, RelayerRefundLeaf, SlowFillLeaf } from "../interfaces";
44
import {
55
BigNumber,
6+
bnZero,
67
MerkleTree,
78
convertFromWei,
89
formatFeePct,
910
shortenHexString,
10-
shortenHexStrings,
1111
toBN,
1212
winston,
1313
assert,
@@ -74,93 +74,83 @@ export function generateMarkdownForRootBundle(
7474

7575
const convertTokenListFromWei = (chainId: number, tokenAddresses: Address[], weiVals: string[]) => {
7676
return tokenAddresses.map((token, index) => {
77-
try {
78-
const { decimals } = hubPoolClient.getTokenInfoForAddress(token, chainId);
79-
return convertFromWei(weiVals[index], decimals);
80-
} catch (error) {
81-
hubPoolClient.logger.debug({
82-
at: "PoolRebalanceUtils#generateMarkdownForRootBundle#convertTokenListFromWei",
83-
message: `Error getting token info for address ${token} on chain ${chainId}`,
84-
error,
85-
});
86-
return weiVals[index].toString();
87-
}
77+
const { decimals } = hubPoolClient.getTokenInfoForAddress(token, chainId);
78+
return convertFromWei(weiVals[index], decimals);
8879
});
8980
};
90-
const convertTokenAddressToSymbol = (chainId: number, tokenAddress: Address) => {
91-
try {
92-
return hubPoolClient.getTokenInfoForAddress(tokenAddress, chainId).symbol;
93-
} catch (error) {
94-
hubPoolClient.logger.debug({
95-
at: "PoolRebalanceUtils#generateMarkdownForRootBundle#convertTokenAddressToSymbol",
96-
message: `Error getting token info for address ${tokenAddress} on chain ${chainId}`,
97-
error,
98-
});
99-
return "UNKNOWN TOKEN";
100-
}
101-
};
81+
82+
const convertTokenAddressToSymbol = (chainId: number, tokenAddress: Address) =>
83+
hubPoolClient.getTokenInfoForAddress(tokenAddress, chainId).symbol;
84+
10285
const convertL1TokenAddressesToSymbols = (l1Tokens: EvmAddress[]) => {
10386
return l1Tokens.map((l1Token) => {
10487
return convertTokenAddressToSymbol(hubPoolChainId, l1Token);
10588
});
10689
};
90+
91+
const tokenPad = 5;
92+
const amountPad = 18;
93+
const balancePad = 18;
94+
const feePad = 18;
10795
let poolRebalanceLeavesPretty = "";
108-
poolRebalanceLeaves.forEach((leaf, index) => {
109-
const { chainId, refundAmounts, refundAddresses, groupIndex: groupId } = leaf;
96+
poolRebalanceLeaves.forEach((leaf, leafId) => {
97+
const { chainId, groupIndex: groupId } = leaf;
11098
const l1Tokens = convertL1TokenAddressesToSymbols(leaf.l1Tokens);
111-
const bundleLpFees = convertTokenListFromWei(hubPoolChainId, leaf.l1Tokens, leaf.bundleLpFees);
99+
const fees = convertTokenListFromWei(hubPoolChainId, leaf.l1Tokens, leaf.bundleLpFees);
112100
const runningBalances = convertTokenListFromWei(hubPoolChainId, leaf.l1Tokens, leaf.runningBalances);
113101
const netSendAmounts = convertTokenListFromWei(hubPoolChainId, leaf.l1Tokens, leaf.netSendAmounts);
114102

115-
// Explicitly set leaf ordering for ease of reability in logs.
116-
const orderedLeaf = {
117-
chainId,
118-
l1Tokens,
119-
netSendAmounts,
120-
runningBalances,
121-
refundAddresses,
122-
refundAmounts,
123-
bundleLpFees,
124-
groupId,
125-
};
126-
poolRebalanceLeavesPretty += `\n\t\t\t${index}: ${JSON.stringify(orderedLeaf)}`;
103+
poolRebalanceLeavesPretty += "```";
104+
poolRebalanceLeavesPretty += `${getNetworkName(chainId)} (${leafId}-${groupId}):\n`;
105+
poolRebalanceLeavesPretty += `${"".padStart(tokenPad, " ")}`;
106+
poolRebalanceLeavesPretty += `\t${"balance".padStart(balancePad)}`;
107+
poolRebalanceLeavesPretty += `\t${"netSendAmount".padStart(amountPad, " ")}`;
108+
poolRebalanceLeavesPretty += `\t${"fees".padStart(feePad, " ")}`;
109+
110+
l1Tokens.forEach((l1Token, idx) => {
111+
const netSendAmount = netSendAmounts[idx];
112+
const runningBalance = runningBalances[idx];
113+
const fee = fees[idx];
114+
poolRebalanceLeavesPretty += `\n${(l1Token + ":").padStart(tokenPad, " ")}`;
115+
poolRebalanceLeavesPretty += `\t${runningBalance.padStart(balancePad, " ")}`;
116+
poolRebalanceLeavesPretty += `\t${netSendAmount.padStart(amountPad, " ")}`;
117+
poolRebalanceLeavesPretty += `\t${fee.padStart(feePad, " ")}`;
118+
poolRebalanceLeavesPretty += "\n";
119+
});
120+
poolRebalanceLeavesPretty += "```\n";
127121
});
128122

129123
let relayerRefundLeavesPretty = "";
130-
relayerRefundLeaves.forEach((leaf, index) => {
131-
const { chainId } = leaf;
132-
let amountToReturn = "";
133-
try {
134-
amountToReturn = convertFromWei(
135-
leaf.amountToReturn,
136-
hubPoolClient.getTokenInfoForAddress(leaf.l2TokenAddress, leaf.chainId).decimals
137-
);
138-
} catch (error) {
139-
hubPoolClient.logger.debug({
140-
at: "PoolRebalanceUtils#generateMarkdownForRootBundle",
141-
message: `Error getting token info for address ${leaf.l2TokenAddress} on chain ${leaf.chainId}`,
142-
error,
143-
});
144-
amountToReturn = leaf.amountToReturn.toString();
145-
}
146-
147-
const l2Token = convertTokenAddressToSymbol(leaf.chainId, leaf.l2TokenAddress);
148-
const refundAddresses = shortenHexStrings(leaf.refundAddresses.map((addr) => addr.toNative()));
124+
relayerRefundLeaves.forEach((leaf) => {
125+
const { chainId, l2TokenAddress } = leaf;
126+
const l2Token = convertTokenAddressToSymbol(chainId, l2TokenAddress);
127+
const refundAddresses = leaf.refundAddresses.map((addr) => shortenHexString(addr.toNative(), 14));
149128
const refundAmounts = convertTokenListFromWei(
150129
chainId,
151-
Array(leaf.refundAmounts.length).fill(leaf.l2TokenAddress),
130+
Array(leaf.refundAmounts.length).fill(l2TokenAddress),
152131
leaf.refundAmounts
153132
);
154133

155-
// Explicitly set leaf ordering for ease of reability in logs.
156-
const orderedLeaf = {
157-
chainId,
158-
l2Token,
159-
amountToReturn,
160-
refundAddresses,
161-
refundAmounts,
162-
};
163-
relayerRefundLeavesPretty += `\n\t\t\t${index}: ${JSON.stringify(orderedLeaf)}`;
134+
relayerRefundLeavesPretty += "```\n";
135+
relayerRefundLeavesPretty += `${getNetworkName(chainId)} ${l2Token}:`;
136+
if (leaf.amountToReturn.gt(bnZero)) {
137+
const { decimals } = hubPoolClient.getTokenInfoForAddress(l2TokenAddress, chainId);
138+
const amountToReturn = convertFromWei(leaf.amountToReturn, decimals);
139+
relayerRefundLeavesPretty += ` (return ${amountToReturn})`;
140+
}
141+
const nCols = 2;
142+
const nRows = Math.ceil(refundAddresses.length / nCols);
143+
for (let row = 0; row < nRows; ++row) {
144+
relayerRefundLeavesPretty += "\n\t";
145+
for (let col = 0; col < nCols; ++col) {
146+
const idx = row + nRows * col;
147+
if (idx >= refundAddresses.length) {
148+
break;
149+
}
150+
relayerRefundLeavesPretty += `\t${refundAddresses[idx]}: ${refundAmounts[idx].padStart(14, " ")}`;
151+
}
152+
}
153+
relayerRefundLeavesPretty += "```\n";
164154
});
165155

166156
let slowRelayLeavesPretty = "";
@@ -205,13 +195,11 @@ export function generateMarkdownForRootBundle(
205195
: "No slow relay leaves";
206196
return (
207197
"\n" +
208-
`\t*Bundle blocks*:${bundleBlockRangePretty}\n` +
209-
"\t*PoolRebalance*:\n" +
210-
`\t\troot:${shortenHexString(poolRebalanceRoot)}...\n` +
211-
`\t\tleaves:${poolRebalanceLeavesPretty}\n` +
212-
"\t*RelayerRefund*\n" +
213-
`\t\troot:${shortenHexString(relayerRefundRoot)}...\n` +
214-
`\t\tleaves:${relayerRefundLeavesPretty}\n` +
198+
`\t*Bundle blocks*: ${bundleBlockRangePretty}\n` +
199+
`\t*PoolRebalance*: ${shortenHexString(poolRebalanceRoot, 20)}...\n` +
200+
`${poolRebalanceLeavesPretty}\n` +
201+
`\t*RelayerRefund*: ${shortenHexString(relayerRefundRoot, 20)}\n` +
202+
`\t\t${relayerRefundLeavesPretty}\n` +
215203
"\t*SlowRelay*\n" +
216204
`\t${slowRelayMsg}`
217205
);

0 commit comments

Comments
 (0)