Skip to content

Commit

Permalink
Sync with upstream repo (#82)
Browse files Browse the repository at this point in the history
Merge latest changes from upstream repo
  • Loading branch information
sameersubudhi authored Dec 16, 2024
2 parents c3763a0 + 4d9d83d commit bd057d0
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 88 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"node": ">=20"
},
"dependencies": {
"@across-protocol/constants": "^3.1.20",
"@across-protocol/contracts": "^3.0.16",
"@across-protocol/sdk": "^3.3.21",
"@across-protocol/constants": "^3.1.22",
"@across-protocol/contracts": "^3.0.18",
"@across-protocol/sdk": "^3.3.25",
"@arbitrum/sdk": "^4.0.2",
"@aws-sdk/client-kms": "^3.592.0",
"@aws-sdk/client-s3": "^3.592.0",
Expand Down
4 changes: 2 additions & 2 deletions src/common/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ export const SUPPORTED_TOKENS: { [chainId: number]: string[] } = {
[CHAIN_IDs.BASE]: ["BAL", "DAI", "ETH", "WETH", "USDC", "POOL"],
[CHAIN_IDs.BLAST]: ["DAI", "WBTC", "WETH"],
[CHAIN_IDs.LINEA]: ["USDC", "USDT", "WETH", "WBTC", "DAI"],
[CHAIN_IDs.LISK]: ["WETH", "USDT", "LSK"],
[CHAIN_IDs.LISK]: ["WETH", "USDT", "LSK", "WBTC"],
[CHAIN_IDs.MODE]: ["ETH", "WETH", "USDC", "USDT", "WBTC"],
[CHAIN_IDs.OPTIMISM]: ["DAI", "SNX", "BAL", "WETH", "USDC", "POOL", "USDT", "WBTC", "UMA", "ACX"],
[CHAIN_IDs.POLYGON]: ["USDC", "USDT", "WETH", "DAI", "WBTC", "UMA", "BAL", "ACX", "POOL"],
[CHAIN_IDs.REDSTONE]: ["WETH"],
[CHAIN_IDs.SCROLL]: ["WETH", "USDC", "USDT", "WBTC", "POOL"],
[CHAIN_IDs.WORLD_CHAIN]: ["WETH", "WBTC", "USDC"],
[CHAIN_IDs.WORLD_CHAIN]: ["WETH", "WBTC", "USDC", "POOL"],
[CHAIN_IDs.ZK_SYNC]: ["USDC", "USDT", "WETH", "WBTC", "DAI"],
[CHAIN_IDs.ZORA]: ["USDC", "WETH"],

Expand Down
2 changes: 1 addition & 1 deletion src/libexec/RelayerSpokePoolIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async function run(argv: string[]): Promise<void> {
};
const args = minimist(argv, minimistOpts);

const { chainId: chainId, lookback, relayer = null, blockrange: maxBlockRange = 10_000 } = args;
const { chainid: chainId, lookback, relayer = null, blockrange: maxBlockRange = 10_000 } = args;
assert(Number.isInteger(chainId), "chainId must be numeric ");
assert(Number.isInteger(maxBlockRange), "maxBlockRange must be numeric");
assert(!isDefined(relayer) || ethersUtils.isAddress(relayer), `relayer address is invalid (${relayer})`);
Expand Down
63 changes: 40 additions & 23 deletions src/monitor/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
L1Token,
RelayerBalanceReport,
RelayerBalanceTable,
RelayerBalanceColumns,
RelayerBalanceCell,
TokenTransfer,
} from "../interfaces";
import {
Expand Down Expand Up @@ -44,13 +42,12 @@ import {
resolveTokenDecimals,
sortEventsDescending,
getWidestPossibleExpectedBlockRange,
utils,
} from "../utils";

import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper";
import { MonitorConfig } from "./MonitorConfig";
import { CombinedRefunds } from "../dataworker/DataworkerUtils";

import lodash from "lodash";
import { PUBLIC_NETWORKS } from "@across-protocol/constants";

// 60 minutes, which is the length of the challenge window, so if a rebalance takes longer than this to finalize,
// then its finalizing after the subsequent challenge period has started, which is sub-optimal.
Expand Down Expand Up @@ -299,26 +296,37 @@ export class Monitor {
message: `Balance report for ${relayer} 📖`,
mrkdwn,
});

// Note: types are here for clarity, not necessity.
const machineReadableReport = lodash.mapValues(reports, (table: RelayerBalanceTable) =>
lodash.mapValues(table, (columns: RelayerBalanceColumns, tokenSymbol: string) => {
const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals;
if (!decimals) {
throw new Error(`No decimals found for ${tokenSymbol}`);
}
Object.entries(reports).forEach(([relayer, balanceTable]) => {
Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => {
const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals;
if (!decimals) {
throw new Error(`No decimals found for ${tokenSymbol}`);
}
Object.entries(columns).forEach(([chainName, cell]) => {
if (this._tokenEnabledForNetwork(tokenSymbol, chainName)) {
Object.entries(cell).forEach(([balanceType, balance]) => {
// Don't log zero balances.
if (balance.isZero()) {
return;
}
this.logger.debug({
at: "Monitor#reportRelayerBalances",
message: "Machine-readable single balance report",
relayer,
tokenSymbol,
decimals,
chainName,
balanceType,
balanceInWei: balance.toString(),
balance: Number(utils.formatUnits(balance, decimals)),
datadog: true,
});
});
}
return lodash.mapValues(columns, (cell: RelayerBalanceCell) =>
lodash.mapValues(cell, (balance: BigNumber) => Number(convertFromWei(balance.toString(), decimals)))
);
})
);

this.logger.debug({
at: "Monitor#reportRelayerBalances",
message: "Machine-readable balance report",
report: machineReadableReport,
});
});
}
});
}

// Update current balances of all tokens on each supported chain for each relayer.
Expand Down Expand Up @@ -1284,4 +1292,13 @@ export class Monitor {
})
);
}

private _tokenEnabledForNetwork(tokenSymbol: string, networkName: string): boolean {
for (const [chainId, network] of Object.entries(PUBLIC_NETWORKS)) {
if (network.name === networkName) {
return isDefined(TOKEN_SYMBOLS_MAP[tokenSymbol]?.addresses[chainId]);
}
}
return false;
}
}
28 changes: 18 additions & 10 deletions src/relayer/Relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,21 +1251,29 @@ export class Relayer {
if (this.clients.inventoryClient.isInventoryManagementEnabled() && chainId !== hubChainId) {
// Shortfalls are mapped to deposit output tokens so look up output token in token symbol map.
const l1Token = this.clients.hubPoolClient.getL1TokenInfoForAddress(token, chainId);
crossChainLog =
"There is " +
formatter(
this.clients.inventoryClient.crossChainTransferClient
.getOutstandingCrossChainTransferAmount(this.relayerAddress, chainId, l1Token.address, token)
// TODO: Add in additional l2Token param here once we can specify it
.toString()
) +
` inbound L1->L2 ${symbol} transfers. `;
const outstandingCrossChainTransferAmount =
this.clients.inventoryClient.crossChainTransferClient.getOutstandingCrossChainTransferAmount(
this.relayerAddress,
chainId,
l1Token.address,
token
);
crossChainLog = outstandingCrossChainTransferAmount.gt(0)
? " There is " +
formatter(
this.clients.inventoryClient.crossChainTransferClient
.getOutstandingCrossChainTransferAmount(this.relayerAddress, chainId, l1Token.address, token)
// TODO: Add in additional l2Token param here once we can specify it
.toString()
) +
` inbound L1->L2 ${symbol} transfers. `
: undefined;
}
mrkdwn +=
` - ${symbol} cumulative shortfall of ` +
`${formatter(shortfall.toString())} ` +
`(have ${formatter(balance.toString())} but need ` +
`${formatter(needed.toString())}). ${crossChainLog}` +
`${formatter(needed.toString())}).${crossChainLog}` +
`This is blocking deposits: ${deposits}.\n`;
});
});
Expand Down
2 changes: 0 additions & 2 deletions test/Dataworker.loadData.slowFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ describe("BundleDataClient: Slow fill handling & validation", async function ()
const destinationChainDeposit = spokePoolClient_2.getDeposits()[0];

// Generate slow fill requests for the slow fill-eligible deposits
await spokePool_1.setCurrentTime(depositsWithSlowFillRequests[1].exclusivityDeadline + 1); // Temporary workaround
await spokePool_2.setCurrentTime(depositsWithSlowFillRequests[0].exclusivityDeadline + 1); // Temporary workaround
await requestSlowFill(spokePool_2, relayer, depositsWithSlowFillRequests[0]);
await requestSlowFill(spokePool_1, relayer, depositsWithSlowFillRequests[1]);
const lastDestinationChainSlowFillRequestBlock = await spokePool_2.provider.getBlockNumber();
Expand Down
2 changes: 0 additions & 2 deletions test/Relayer.BasicFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () {
spy.getCalls().find(({ lastArg }) => lastArg.message.includes("Skipping fill for deposit with message"))
).to.not.be.undefined;
} else {
await spokePool_2.setCurrentTime(deposit.exclusivityDeadline + 1); // Temporary workaround.
// Now speed up deposit again with a higher fee and a message of 0x. This should be filled.
expect((await txnReceipts[destinationChainId]).length).to.equal(1);
expect(lastSpyLogIncludes(spy, "Filled v3 deposit")).to.be.true;
Expand Down Expand Up @@ -1011,7 +1010,6 @@ describe("Relayer: Check for Unfilled Deposits and Fill", async function () {
depositor
);

await spokePool_2.setCurrentTime(deposit.exclusivityDeadline + 1); // Temporary workaround.
await updateAllClients();
txnReceipts = await relayerInstance.checkForUnfilledDepositsAndFill();
expect((await txnReceipts[destinationChainId]).length).to.equal(1);
Expand Down
1 change: 0 additions & 1 deletion test/Relayer.SlowFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ describe("Relayer: Initiates slow fill requests", async function () {
);
expect(deposit).to.exist;

await spokePool_2.setCurrentTime(deposit.exclusivityDeadline + 1); // Temporary workaround
await updateAllClients();
const _txnReceipts = await relayerInstance.checkForUnfilledDepositsAndFill();
const txnHashes = await _txnReceipts[destinationChainId];
Expand Down
Loading

0 comments on commit bd057d0

Please sign in to comment.