Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: swap all Ovm adapters (excl. Optimism/Base) w/ generic adapter #1824

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adapter/bridges/BlastBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BlastBridge extends BaseBridgeAdapter {
const l2Bridge = this.getL2Bridge();
const events = await paginatedEventQuery(
l2Bridge,
l2Bridge.filters.ERC20BridgeFinalized(l1Token, undefined, fromAddress),
l2Bridge.filters.ERC20BridgeFinalized(undefined, l1Token, fromAddress),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually an issue where I assumed the blast bridge followed the same interface as the OpStackDefaultERC20Bridge finalization events, but actually the token address positions are swapped. I.e. the first position is the address of USDB and the second position is DAI on mainnet, not the other way around.

eventConfig
);
return {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/bridges/OpStackWethBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class OpStackWethBridge extends BaseBridgeAdapter {
)
// If EOA sent the ETH via the AtomicDepositor, then remove any events where the
// toAddress is not the EOA so we don't get confused with other users using the AtomicDepositor
.filter((event) => event.args._to === fromAddress);
.filter((event) => event.args._to === toAddress);

// We only care about WETH finalization events initiated by the relayer running this rebalancer logic, so only
// filter on Deposit events sent from the provided signer. We can't simply filter on `fromAddress` because
Expand Down
73 changes: 56 additions & 17 deletions src/clients/bridges/AdapterManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { utils } from "@across-protocol/sdk";
import { spokesThatHoldEthAndWeth, SUPPORTED_TOKENS } from "../../common/Constants";
import {
spokesThatHoldEthAndWeth,
SUPPORTED_TOKENS,
CUSTOM_BRIDGE,
CANONICAL_BRIDGE,
DEFAULT_GAS_MULTIPLIER,
} from "../../common/Constants";
import { InventoryConfig, OutstandingTransfers } from "../../interfaces";
import { BigNumber, isDefined, winston, Signer, getL2TokenAddresses, TransactionResponse, assert } from "../../utils";
import { SpokePoolClient, HubPoolClient } from "../";
import { ArbitrumAdapter, PolygonAdapter, ZKSyncAdapter, LineaAdapter, OpStackAdapter, ScrollAdapter } from "./";
import { CHAIN_IDs } from "@across-protocol/constants";
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";

import { BaseChainAdapter } from "../../adapter";

Expand Down Expand Up @@ -40,6 +46,19 @@ export class AdapterManager {
};

const { OPTIMISM, ARBITRUM, POLYGON, ZK_SYNC, BASE, MODE, LINEA, LISK, BLAST, REDSTONE, SCROLL, ZORA } = CHAIN_IDs;
const hubChainId = hubPoolClient.chainId;
const l1Signer = spokePoolClients[hubChainId].spokePool.signer;
const constructBridges = (chainId: number) => {
return Object.fromEntries(
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 OpStackAdapter(
OPTIMISM,
Expand Down Expand Up @@ -71,51 +90,71 @@ export class AdapterManager {
this.adapters[LINEA] = new LineaAdapter(logger, spokePoolClients, filterMonitoredAddresses(LINEA));
}
if (this.spokePoolClients[MODE] !== undefined) {
this.adapters[MODE] = new OpStackAdapter(
const bridges = constructBridges(MODE);
this.adapters[MODE] = new BaseChainAdapter(
spokePoolClients,
MODE,
hubChainId,
filterMonitoredAddresses(MODE),
logger,
SUPPORTED_TOKENS[MODE],
spokePoolClients,
filterMonitoredAddresses(MODE)
bridges,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bridges used anywhere else? Could maybe squash it?

Suggested change
bridges,
constructBridges(MODE),

DEFAULT_GAS_MULTIPLIER[MODE] ?? 1
);
}
if (this.spokePoolClients[REDSTONE] !== undefined) {
this.adapters[REDSTONE] = new OpStackAdapter(
const bridges = constructBridges(REDSTONE);
this.adapters[REDSTONE] = new BaseChainAdapter(
spokePoolClients,
REDSTONE,
hubChainId,
filterMonitoredAddresses(REDSTONE),
logger,
SUPPORTED_TOKENS[REDSTONE],
spokePoolClients,
filterMonitoredAddresses(REDSTONE)
bridges,
DEFAULT_GAS_MULTIPLIER[REDSTONE] ?? 1
);
}
if (this.spokePoolClients[LISK] !== undefined) {
this.adapters[LISK] = new OpStackAdapter(
const bridges = constructBridges(LISK);
this.adapters[LISK] = new BaseChainAdapter(
spokePoolClients,
LISK,
hubChainId,
filterMonitoredAddresses(LISK),
logger,
SUPPORTED_TOKENS[LISK],
spokePoolClients,
filterMonitoredAddresses(LISK)
bridges,
DEFAULT_GAS_MULTIPLIER[LISK] ?? 1
);
}
if (this.spokePoolClients[BLAST] !== undefined) {
this.adapters[BLAST] = new OpStackAdapter(
const bridges = constructBridges(BLAST);
this.adapters[BLAST] = new BaseChainAdapter(
spokePoolClients,
BLAST,
hubChainId,
filterMonitoredAddresses(BLAST),
logger,
SUPPORTED_TOKENS[BLAST],
spokePoolClients,
filterMonitoredAddresses(BLAST)
bridges,
DEFAULT_GAS_MULTIPLIER[BLAST] ?? 1
);
}
if (this.spokePoolClients[SCROLL] !== undefined) {
this.adapters[SCROLL] = new ScrollAdapter(logger, spokePoolClients, filterMonitoredAddresses(SCROLL));
}
if (this.spokePoolClients[ZORA] !== undefined) {
this.adapters[ZORA] = new OpStackAdapter(
const bridges = constructBridges(ZORA);
this.adapters[ZORA] = new BaseChainAdapter(
spokePoolClients,
ZORA,
hubChainId,
filterMonitoredAddresses(ZORA),
logger,
SUPPORTED_TOKENS[ZORA],
spokePoolClients,
filterMonitoredAddresses(ZORA)
bridges,
DEFAULT_GAS_MULTIPLIER[ZORA] ?? 1
);
}

Expand Down