diff --git a/src/adapter/AdapterManager.ts b/src/adapter/AdapterManager.ts deleted file mode 100644 index d345c62af..000000000 --- a/src/adapter/AdapterManager.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { winston, TOKEN_SYMBOLS_MAP } from "../utils"; -import { SpokePoolClient, HubPoolClient } from "../clients"; -import { BaseChainAdapter } from "./"; -import { SUPPORTED_TOKENS, CUSTOM_BRIDGE, CANONICAL_BRIDGE, DEFAULT_GAS_MULTIPLIER } from "../common"; - -import { AdapterManager } from "../clients/bridges"; - -export class GenericAdapterManager extends AdapterManager { - constructor( - readonly logger: winston.Logger, - readonly spokePoolClients: { [chainId: number]: SpokePoolClient }, - readonly hubPoolClient: HubPoolClient, - readonly monitoredAddresses: string[] - ) { - super(logger, spokePoolClients, hubPoolClient, monitoredAddresses); - if (!spokePoolClients) { - return; - } - const spokePoolAddresses = Object.values(spokePoolClients).map((client) => client.spokePool.address); - const hubChainId = this.hubPoolClient.chainId; - - // The adapters are only set up to monitor EOA's and the HubPool and SpokePool address, so remove - // spoke pool addresses from other chains. - const filterMonitoredAddresses = (chainId: number) => { - return monitoredAddresses.filter( - (address) => - this.hubPoolClient.hubPool.address === address || - this.spokePoolClients[chainId].spokePool.address === address || - !spokePoolAddresses.includes(address) - ); - }; - - const l1Signer = spokePoolClients[hubChainId].spokePool.signer; - - Object.values(this.spokePoolClients) - .filter(({ chainId }) => chainId !== hubChainId) - .map(({ chainId }) => { - // First, fetch all the bridges associated with the chain. - const bridges = {}; - const l2Signer = spokePoolClients[chainId].spokePool.signer; - - SUPPORTED_TOKENS[chainId]?.map((symbol) => { - const l1Token = TOKEN_SYMBOLS_MAP[symbol].addresses[hubChainId]; - const bridgeConstructor = CUSTOM_BRIDGE[chainId]?.[l1Token] ?? CANONICAL_BRIDGE[chainId]; - - bridges[l1Token] = new bridgeConstructor(chainId, hubChainId, l1Signer, l2Signer, l1Token); - }); - - // Then instantiate a generic adapter. - this.adapters[chainId] = new BaseChainAdapter( - spokePoolClients, - chainId, - hubChainId, - filterMonitoredAddresses(chainId), - logger, - SUPPORTED_TOKENS[chainId], - bridges, - DEFAULT_GAS_MULTIPLIER[chainId] ?? 1 - ); - }); - - logger.debug({ - at: "AdapterManager#constructor", - message: "Initialized experimental AdapterManager for generic adapters. Ensure this was intended!", - adapterChains: Object.keys(this.adapters).map((chainId) => chainId), - }); - } -} diff --git a/src/clients/bridges/AdapterManager.ts b/src/clients/bridges/AdapterManager.ts index 8d83fc6c4..8bc6854ce 100644 --- a/src/clients/bridges/AdapterManager.ts +++ b/src/clients/bridges/AdapterManager.ts @@ -9,11 +9,8 @@ import { import { InventoryConfig, OutstandingTransfers } from "../../interfaces"; import { BigNumber, isDefined, winston, Signer, getL2TokenAddresses, TransactionResponse, assert } from "../../utils"; import { SpokePoolClient, HubPoolClient } from "../"; -import { ArbitrumAdapter, PolygonAdapter, ZKSyncAdapter, LineaAdapter, ScrollAdapter } from "./"; import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants"; - import { BaseChainAdapter } from "../../adapter"; -import { EthereumAdapter } from "./EthereumAdapter"; export class AdapterManager { public adapters: { [chainId: number]: BaseChainAdapter } = {}; @@ -46,145 +43,37 @@ export class AdapterManager { ); }; - const { OPTIMISM, ARBITRUM, POLYGON, ZK_SYNC, BASE, MODE, LINEA, LISK, BLAST, REDSTONE, SCROLL, ZORA, ALEPH_ZERO } = - CHAIN_IDs; const hubChainId = hubPoolClient.chainId; const l1Signer = spokePoolClients[hubChainId].spokePool.signer; const constructBridges = (chainId: number) => { + if (chainId === hubChainId) { + return {}; + } // Special case for the EthereumAdapter return Object.fromEntries( - SUPPORTED_TOKENS[chainId].map((symbol) => { + SUPPORTED_TOKENS[chainId]?.map((symbol) => { const l2Signer = spokePoolClients[chainId].spokePool.signer; const l1Token = TOKEN_SYMBOLS_MAP[symbol].addresses[hubChainId]; const bridgeConstructor = CUSTOM_BRIDGE[chainId]?.[l1Token] ?? CANONICAL_BRIDGE[chainId]; const bridge = new bridgeConstructor(chainId, hubChainId, l1Signer, l2Signer, l1Token); return [l1Token, bridge]; - }) + }) ?? [] ); }; - if (this.spokePoolClients[OPTIMISM] !== undefined) { - this.adapters[OPTIMISM] = new BaseChainAdapter( - spokePoolClients, - OPTIMISM, - hubChainId, - filterMonitoredAddresses(OPTIMISM), - logger, - SUPPORTED_TOKENS[OPTIMISM], - constructBridges(OPTIMISM), - DEFAULT_GAS_MULTIPLIER[OPTIMISM] ?? 1 - ); - } - if (this.spokePoolClients[POLYGON] !== undefined) { - this.adapters[POLYGON] = new PolygonAdapter(logger, spokePoolClients, filterMonitoredAddresses(POLYGON)); - } - if (this.spokePoolClients[ARBITRUM] !== undefined) { - this.adapters[ARBITRUM] = new ArbitrumAdapter(logger, spokePoolClients, filterMonitoredAddresses(ARBITRUM)); - } - if (this.spokePoolClients[ZK_SYNC] !== undefined) { - this.adapters[ZK_SYNC] = new ZKSyncAdapter(logger, spokePoolClients, filterMonitoredAddresses(ZK_SYNC)); - } - if (this.spokePoolClients[BASE] !== undefined) { - this.adapters[BASE] = new BaseChainAdapter( - spokePoolClients, - BASE, - hubChainId, - filterMonitoredAddresses(BASE), - logger, - SUPPORTED_TOKENS[BASE], - constructBridges(BASE), - DEFAULT_GAS_MULTIPLIER[BASE] ?? 1 - ); - } - if (this.spokePoolClients[LINEA] !== undefined) { - this.adapters[LINEA] = new LineaAdapter(logger, spokePoolClients, filterMonitoredAddresses(LINEA)); - } - if (this.spokePoolClients[MODE] !== undefined) { - this.adapters[MODE] = new BaseChainAdapter( - spokePoolClients, - MODE, - hubChainId, - filterMonitoredAddresses(MODE), - logger, - SUPPORTED_TOKENS[MODE], - constructBridges(MODE), - DEFAULT_GAS_MULTIPLIER[MODE] ?? 1 - ); - } - if (this.spokePoolClients[REDSTONE] !== undefined) { - this.adapters[REDSTONE] = new BaseChainAdapter( - spokePoolClients, - REDSTONE, - hubChainId, - filterMonitoredAddresses(REDSTONE), - logger, - SUPPORTED_TOKENS[REDSTONE], - constructBridges(REDSTONE), - DEFAULT_GAS_MULTIPLIER[REDSTONE] ?? 1 - ); - } - if (this.spokePoolClients[LISK] !== undefined) { - this.adapters[LISK] = new BaseChainAdapter( + Object.keys(this.spokePoolClients).map((_chainId) => { + const chainId = Number(_chainId); + assert(chainId.toString() === _chainId); + // Instantiate a generic adapter and supply all network-specific configurations. + this.adapters[chainId] = new BaseChainAdapter( spokePoolClients, - LISK, - hubChainId, - filterMonitoredAddresses(LISK), - logger, - SUPPORTED_TOKENS[LISK], - constructBridges(LISK), - DEFAULT_GAS_MULTIPLIER[LISK] ?? 1 - ); - } - if (this.spokePoolClients[BLAST] !== undefined) { - this.adapters[BLAST] = new BaseChainAdapter( - spokePoolClients, - BLAST, - hubChainId, - filterMonitoredAddresses(BLAST), - logger, - SUPPORTED_TOKENS[BLAST], - constructBridges(BLAST), - DEFAULT_GAS_MULTIPLIER[BLAST] ?? 1 - ); - } - if (this.spokePoolClients[SCROLL] !== undefined) { - this.adapters[SCROLL] = new ScrollAdapter(logger, spokePoolClients, filterMonitoredAddresses(SCROLL)); - } - if (this.spokePoolClients[CHAIN_IDs.WORLD_CHAIN] !== undefined) { - this.adapters[CHAIN_IDs.WORLD_CHAIN] = new BaseChainAdapter( - spokePoolClients, - CHAIN_IDs.WORLD_CHAIN, - hubChainId, - filterMonitoredAddresses(CHAIN_IDs.WORLD_CHAIN), - logger, - SUPPORTED_TOKENS[CHAIN_IDs.WORLD_CHAIN], - constructBridges(CHAIN_IDs.WORLD_CHAIN), - DEFAULT_GAS_MULTIPLIER[CHAIN_IDs.WORLD_CHAIN] ?? 1 - ); - } - if (this.spokePoolClients[ZORA] !== undefined) { - this.adapters[ZORA] = new BaseChainAdapter( - spokePoolClients, - ZORA, - hubChainId, - filterMonitoredAddresses(ZORA), - logger, - SUPPORTED_TOKENS[ZORA], - constructBridges(ZORA), - DEFAULT_GAS_MULTIPLIER[ZORA] ?? 1 - ); - } - if (this.spokePoolClients[ALEPH_ZERO] !== undefined) { - this.adapters[ALEPH_ZERO] = new BaseChainAdapter( - spokePoolClients, - ALEPH_ZERO, + chainId, hubChainId, - filterMonitoredAddresses(ALEPH_ZERO), + filterMonitoredAddresses(chainId), logger, - SUPPORTED_TOKENS[ALEPH_ZERO], - constructBridges(ALEPH_ZERO), - DEFAULT_GAS_MULTIPLIER[ALEPH_ZERO] ?? 1 + SUPPORTED_TOKENS[chainId] ?? [], + constructBridges(chainId), + DEFAULT_GAS_MULTIPLIER[chainId] ?? 1 ); - } - + }); logger.debug({ at: "AdapterManager#constructor", message: "Initialized AdapterManager", @@ -246,14 +135,7 @@ export class AdapterManager { wrapThreshold.gte(wrapTarget), `wrapEtherThreshold ${wrapThreshold.toString()} must be >= wrapEtherTarget ${wrapTarget.toString()}` ); - if (chainId === CHAIN_IDs.MAINNET) { - // For mainnet, construct one-off adapter to wrap ETH, because Ethereum is typically not a chain - // that we have an adapter for. - const ethAdapter = new EthereumAdapter(this.logger, this.spokePoolClients); - await ethAdapter.wrapEthIfAboveThreshold(wrapThreshold, wrapTarget, simMode); - } else { - await this.adapters[chainId].wrapEthIfAboveThreshold(wrapThreshold, wrapTarget, simMode); - } + await this.adapters[chainId].wrapEthIfAboveThreshold(wrapThreshold, wrapTarget, simMode); } ); } diff --git a/src/monitor/MonitorClientHelper.ts b/src/monitor/MonitorClientHelper.ts index 908e5f2aa..66d21c3f2 100644 --- a/src/monitor/MonitorClientHelper.ts +++ b/src/monitor/MonitorClientHelper.ts @@ -9,6 +9,7 @@ import { constructSpokePoolClientsWithLookback, } from "../common"; import { SpokePoolClientsByChain } from "../interfaces"; +import { AdapterManager, CrossChainTransferClient } from "../clients/bridges"; export interface MonitorClients extends Clients { bundleDataClient: BundleDataClient; @@ -18,9 +19,6 @@ export interface MonitorClients extends Clients { tokenTransferClient: TokenTransferClient; } -import { GenericAdapterManager } from "../adapter/AdapterManager"; -import { AdapterManager, CrossChainTransferClient } from "../clients/bridges"; - export async function constructMonitorClients( config: MonitorConfig, logger: winston.Logger, @@ -56,8 +54,7 @@ export async function constructMonitorClients( // Cross-chain transfers will originate from the HubPool's address and target SpokePool addresses, so // track both. - const adapterManagerConstructor = config.useGenericAdapter ? GenericAdapterManager : AdapterManager; - const adapterManager = new adapterManagerConstructor(logger, spokePoolClients, hubPoolClient, [ + const adapterManager = new AdapterManager(logger, spokePoolClients, hubPoolClient, [ signerAddr, hubPoolClient.hubPool.address, ...spokePoolAddresses, diff --git a/src/monitor/MonitorConfig.ts b/src/monitor/MonitorConfig.ts index a161a4852..5c766512c 100644 --- a/src/monitor/MonitorConfig.ts +++ b/src/monitor/MonitorConfig.ts @@ -66,7 +66,6 @@ export class MonitorConfig extends CommonConfig { REFILL_BALANCES, REFILL_BALANCES_ENABLED, STUCK_REBALANCES_ENABLED, - MONITOR_USE_GENERIC_ADAPTER, REPORT_SPOKE_POOL_BALANCES, MONITORED_SPOKE_POOL_CHAINS, MONITORED_TOKEN_SYMBOLS, @@ -83,8 +82,6 @@ export class MonitorConfig extends CommonConfig { spokePoolBalanceReportEnabled: REPORT_SPOKE_POOL_BALANCES === "true", }; - this.useGenericAdapter = MONITOR_USE_GENERIC_ADAPTER === "true"; - // Used to monitor activities not from whitelisted data workers or relayers. this.whitelistedDataworkers = parseAddressesOptional(WHITELISTED_DATA_WORKERS); this.whitelistedRelayers = parseAddressesOptional(WHITELISTED_RELAYERS); diff --git a/src/relayer/RelayerClientHelper.ts b/src/relayer/RelayerClientHelper.ts index c598b38d4..8a04fdaab 100644 --- a/src/relayer/RelayerClientHelper.ts +++ b/src/relayer/RelayerClientHelper.ts @@ -21,8 +21,6 @@ import { import { SpokePoolClientsByChain } from "../interfaces"; import { getBlockForTimestamp, getCurrentTime, getProvider, getRedisCache, Signer, SpokePool } from "../utils"; import { RelayerConfig } from "./RelayerConfig"; - -import { GenericAdapterManager } from "../adapter/AdapterManager"; import { AdapterManager, CrossChainTransferClient } from "../clients/bridges"; export interface RelayerClients extends Clients { @@ -143,8 +141,7 @@ export async function constructRelayerClients( await profitClient.update(); const monitoredAddresses = [signerAddr]; - const adapterManagerConstructor = config.useGenericAdapter ? GenericAdapterManager : AdapterManager; - const adapterManager = new adapterManagerConstructor( + const adapterManager = new AdapterManager( logger, spokePoolClients, hubPoolClient, diff --git a/src/relayer/RelayerConfig.ts b/src/relayer/RelayerConfig.ts index 3af672aa4..58f85509f 100644 --- a/src/relayer/RelayerConfig.ts +++ b/src/relayer/RelayerConfig.ts @@ -89,14 +89,11 @@ export class RelayerConfig extends CommonConfig { RELAYER_IGNORE_LIMITS, RELAYER_EXTERNAL_INDEXER, RELAYER_TRY_MULTICALL_CHAINS, - RELAYER_USE_GENERIC_ADAPTER, RELAYER_LOGGING_INTERVAL = "30", RELAYER_MAINTENANCE_INTERVAL = "60", } = env; super(env); - this.useGenericAdapter = RELAYER_USE_GENERIC_ADAPTER === "true"; - // External indexing is dependent on looping mode being configured. this.externalIndexer = this.pollingDelay > 0 && RELAYER_EXTERNAL_INDEXER === "true"; diff --git a/test/generic-adapters/AdapterManager.SendTokensCrossChain.ts b/test/generic-adapters/AdapterManager.SendTokensCrossChain.ts index 9bf7e797c..9f3e880a5 100644 --- a/test/generic-adapters/AdapterManager.SendTokensCrossChain.ts +++ b/test/generic-adapters/AdapterManager.SendTokensCrossChain.ts @@ -1,6 +1,6 @@ import * as zksync from "zksync-ethers"; import { SpokePoolClient } from "../../src/clients"; -import { GenericAdapterManager } from "../../src/adapter/AdapterManager"; // Tested +import { AdapterManager } from "../../src/clients/bridges"; import { CONTRACT_ADDRESSES, chainIdsToCctpDomains } from "../../src/common"; import { bnToHex, @@ -30,7 +30,7 @@ const mockSpokePoolClients: { [chainId: number]: SpokePoolClient; } = {}; let relayer: SignerWithAddress, owner: SignerWithAddress, spyLogger: winston.Logger, amountToSend: BigNumber; -let adapterManager: AdapterManager; // tested +let adapterManager: AdapterManager; // Atomic depositor let l1AtomicDepositor: FakeContract; @@ -78,7 +78,7 @@ describe("AdapterManager: Send tokens cross-chain", async function () { const { hubPool } = await hubPoolFixture(); hubPoolClient = new MockHubPoolClient(spyLogger, hubPool, configStoreClient); await seedMocks(); - adapterManager = new GenericAdapterManager(spyLogger, mockSpokePoolClients, hubPoolClient, [relayer.address]); + adapterManager = new AdapterManager(spyLogger, mockSpokePoolClients, hubPoolClient, [relayer.address]); await constructChainSpecificFakes();