Skip to content

Commit

Permalink
Sync with upstream repo (#81)
Browse files Browse the repository at this point in the history
Merge latest changes from upstream repo
  • Loading branch information
sameersubudhi authored Nov 30, 2024
2 parents 514900b + b7beea9 commit c3763a0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/clients/SpokePoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ export class IndexedSpokePoolClient extends clients.SpokePoolClient {
*/
protected startWorker(): void {
const {
eventSearchConfig: { fromBlock, maxBlockLookBack: blockRange },
eventSearchConfig: { fromBlock, maxBlockLookBack: blockrange },
spokePool: { address: spokepool },
} = this;
const opts = { blockRange, lookback: `@${fromBlock}` };
const opts = { spokepool, blockrange, lookback: `@${fromBlock}` };

const args = Object.entries(opts)
.map(([k, v]) => [`--${k}`, `${v}`])
.flat();
this.worker = spawn("node", [this.indexerPath, "--chainId", this.chainId.toString(), ...args], {
this.worker = spawn("node", [this.indexerPath, "--chainid", this.chainId.toString(), ...args], {
stdio: ["ignore", "inherit", "inherit", "ipc"],
});

Expand Down
2 changes: 1 addition & 1 deletion src/common/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const CHAIN_MAX_BLOCK_LOOKBACK = {
[CHAIN_IDs.BOBA]: 4990,
[CHAIN_IDs.LINEA]: 5000,
[CHAIN_IDs.LISK]: 10000,
[CHAIN_IDs.MAINNET]: 10000,
[CHAIN_IDs.MAINNET]: 5000,
[CHAIN_IDs.MODE]: 10000,
[CHAIN_IDs.OPTIMISM]: 10000, // Quick
[CHAIN_IDs.POLYGON]: 10000,
Expand Down
20 changes: 16 additions & 4 deletions src/libexec/RelayerSpokePoolIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getOriginFromURL,
getProvider,
getRedisCache,
getSpokePool,
getWSProviders,
Logger,
winston,
Expand Down Expand Up @@ -117,18 +118,24 @@ async function listen(
*/
async function run(argv: string[]): Promise<void> {
const minimistOpts = {
string: ["lookback", "relayer"],
string: ["lookback", "relayer", "spokepool"],
};
const args = minimist(argv, minimistOpts);

const { chainId, lookback, relayer = null, 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})`);

const { quorum = getChainQuorum(chainId) } = args;
assert(Number.isInteger(quorum), "quorum must be numeric ");

let { spokepool: spokePoolAddr } = args;
assert(
!isDefined(spokePoolAddr) || ethersUtils.isAddress(spokePoolAddr),
`Invalid SpokePool address (${spokePoolAddr})`
);

chain = getNetworkName(chainId);

const quorumProvider = await getProvider(chainId);
Expand All @@ -152,16 +159,21 @@ async function run(argv: string[]): Promise<void> {
logger.debug({ at: "RelayerSpokePoolIndexer::run", message: `Skipping lookback on ${chain}.` });
}

const spokePool = getSpokePool(chainId, spokePoolAddr);
if (!isDefined(spokePoolAddr)) {
({ address: spokePoolAddr } = spokePool);
}

const opts = {
quorum,
spokePool: spokePoolAddr,
deploymentBlock,
lookback: latestBlock.number - startBlock,
maxBlockRange,
filterArgs: getEventFilterArgs(relayer),
quorum,
};

logger.debug({ at: "RelayerSpokePoolIndexer::run", message: `Starting ${chain} SpokePool Indexer.`, opts });
const spokePool = await utils.getSpokePoolContract(chainId);

process.on("SIGHUP", () => {
logger.debug({ at: "Relayer#run", message: `Received SIGHUP in ${chain} listener, stopping...` });
Expand Down
22 changes: 17 additions & 5 deletions src/libexec/SpokePoolListenerExperimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getNodeUrlList,
getOriginFromURL,
getProvider,
getSpokePool,
getRedisCache,
Logger,
winston,
Expand Down Expand Up @@ -161,19 +162,25 @@ async function listen(eventMgr: EventManager, spokePool: Contract, eventNames: s
*/
async function run(argv: string[]): Promise<void> {
const minimistOpts = {
string: ["lookback", "relayer"],
string: ["lookback", "relayer", "spokepool"],
};
const args = minimist(argv, minimistOpts);

({ chainId } = args);
const { lookback, relayer = null, maxBlockRange = 10_000 } = args;
({ chainid: chainId } = args);
const { 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})`);

const { quorum = getChainQuorum(chainId) } = args;
assert(Number.isInteger(quorum), "quorum must be numeric ");

let { spokepool: spokePoolAddr } = args;
assert(
!isDefined(spokePoolAddr) || ethersUtils.isAddress(spokePoolAddr),
`Invalid SpokePool address (${spokePoolAddr})`
);

chain = getNetworkName(chainId);

const quorumProvider = await getProvider(chainId);
Expand All @@ -197,16 +204,21 @@ async function run(argv: string[]): Promise<void> {
logger.debug({ at: "RelayerSpokePoolListener::run", message: `Skipping lookback on ${chain}.` });
}

const spokePool = getSpokePool(chainId, spokePoolAddr);
if (!isDefined(spokePoolAddr)) {
({ address: spokePoolAddr } = spokePool);
}

const opts = {
quorum,
spokePool: spokePoolAddr,
deploymentBlock,
lookback: latestBlock.number - startBlock,
maxBlockRange,
filterArgs: getEventFilterArgs(relayer),
quorum,
};

logger.debug({ at: "RelayerSpokePoolListener::run", message: `Starting ${chain} SpokePool Indexer.`, opts });
const spokePool = await utils.getSpokePoolContract(chainId);

process.on("SIGHUP", () => {
logger.debug({ at: "Relayer#run", message: `Received SIGHUP in ${chain} listener, stopping...` });
Expand Down
35 changes: 23 additions & 12 deletions src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import { getNetworkName, Contract, Signer, getDeployedAddress, getDeployedBlockNumber } from ".";

import * as typechain from "@across-protocol/contracts"; // TODO: refactor once we've fixed export from contract repo
import { CHAIN_IDs, getNetworkName, Contract, Signer, getDeployedAddress, getDeployedBlockNumber } from ".";

// Return an ethers contract instance for a deployed contract, imported from the Across-protocol contracts repo.
export function getDeployedContract(contractName: string, networkId: number, signer?: Signer): Contract {
try {
const address = getDeployedAddress(contractName, networkId);
// If the contractName is SpokePool then we need to modify it to find the correct contract factory artifact.
const factoryName = contractName === "SpokePool" ? castSpokePoolName(networkId) : contractName;
const artifact = typechain[`${[factoryName.replace("_", "")]}__factory`];
const factoryName = `${contractName === "SpokePool" ? castSpokePoolName(networkId) : contractName}__factory`;
const artifact = typechain[factoryName];
return new Contract(address, artifact.abi, signer);
} catch (error) {
throw new Error(`Could not find address for contract ${contractName} on ${networkId}`);
throw new Error(`Could not find address for contract ${contractName} on ${networkId} (${error})`);
}
}

// If the name of the contract is SpokePool then we need to apply a transformation on the name to get the correct
// contract factory name. For example, if the network is "mainnet" then the contract is called Ethereum_SpokePool.
export function castSpokePoolName(networkId: number): string {
let networkName = getNetworkName(networkId);
if (networkName == "Mainnet" || networkName == "Rinkeby" || networkName == "Kovan" || networkName == "Goerli") {
return "Ethereum_SpokePool";
let networkName: string;
switch (networkId) {
case CHAIN_IDs.MAINNET:
case CHAIN_IDs.SEPOLIA:
return "Ethereum_SpokePool";
case CHAIN_IDs.ARBITRUM:
return "Arbitrum_SpokePool";
case CHAIN_IDs.ZK_SYNC:
return "ZkSync_SpokePool";
default:
networkName = getNetworkName(networkId);
}

if (networkName.includes("-")) {
networkName = networkName.substring(0, networkName.indexOf("-"));
}
return `${networkName}_SpokePool`;
return `${networkName.replace(" ", "")}_SpokePool`;
}

// For a chain ID and optional SpokePool address, return a Contract instance with the corresponding ABI.
export function getSpokePool(chainId: number, address?: string): Contract {
const factoryName = castSpokePoolName(chainId);
const artifact = typechain[`${factoryName}__factory`];
return new Contract(address ?? getDeployedAddress("SpokePool", chainId), artifact.abi);
}

export function getParamType(contractName: string, functionName: string, paramName: string): string {
Expand Down

0 comments on commit c3763a0

Please sign in to comment.