Skip to content

Commit

Permalink
relayer: use auto-generated types as interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBuragev committed May 31, 2023
1 parent 2188936 commit b459360
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion relayer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"lint:fix": "eslint --ext .js,.ts --ignore-path .gitignore --fix .",
"test:unit": "jest unit",
"test:coverage": "jest --collect-coverage",
"generate-types": "typechain --target=ethers-v5 ./node_modules/@beamer-bridge/deployments/dist/abis/mainnet/**.json --out-dir=./types-gen/contracts/",
"generate-types": "typechain --target=ethers-v5 --glob='./node_modules/@beamer-bridge/deployments/dist/abis/mainnet/!(deployment).json' --out-dir=./types-gen/contracts/",
"postinstall": "yarn generate-types"
},
"dependencies": {
Expand Down
5 changes: 2 additions & 3 deletions relayer/src/common/events/FillInvalidated.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Log } from "@ethersproject/providers";
import { Interface } from "ethers/lib/utils";

import { abis } from "../../deployments";
import { FillManager__factory } from "../../../types-gen/contracts/beamer/factories/FillManager__factory";
import { isUndefined } from "../util";

interface Result extends ReadonlyArray<unknown> {
Expand All @@ -21,7 +20,7 @@ export const isValidFillInvalidatedEvent = (data: Result): data is FillInvalidat
};

export const parseFillInvalidatedEvent = (logs: Log[]): FillInvalidatedEventData | null => {
const iface = new Interface(abis.FillManager);
const iface = FillManager__factory.createInterface();

for (const log of logs) {
try {
Expand Down
5 changes: 2 additions & 3 deletions relayer/src/common/events/RequestFilled.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Log } from "@ethersproject/providers";
import type { BigNumber } from "ethers";
import { Interface } from "ethers/lib/utils";

import { abis } from "../../deployments";
import { FillManager__factory } from "../../../types-gen/contracts/beamer/factories/FillManager__factory";
import { isUndefined } from "../util";

interface Result extends ReadonlyArray<unknown> {
Expand Down Expand Up @@ -33,7 +32,7 @@ export const isValidRequestFilledEventData = (data: Result): data is RequestFill
};

export const parseRequestFilledEvent = (logs: Log[]): RequestFilledEventData | null => {
const iface = new Interface(abis.FillManager);
const iface = FillManager__factory.createInterface();

for (const log of logs) {
try {
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/common/events/polygon-zkevm/BridgeEvent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Log } from "@ethersproject/providers";
import type { BigNumber } from "ethers";

import { PolygonZKEvmBridge__factory } from "../../../../types-gen/contracts";
import { PolygonZKEvmBridge__factory } from "../../../../types-gen/contracts/external/";
import { isUndefined } from "../../util";

interface Result extends ReadonlyArray<unknown> {
Expand Down
5 changes: 0 additions & 5 deletions relayer/src/deployments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { abi as FillManagerABI } from "@beamer-bridge/deployments/dist/abis/mainnet/FillManager.json";
import { chain as chainEthereumGoerli } from "@beamer-bridge/deployments/dist/artifacts/goerli/5-ethereum.deployment.json";
import { base as baseArbitrumGoerli } from "@beamer-bridge/deployments/dist/artifacts/goerli/421613-arbitrum.deployment.json";
import { base as baseGoerli } from "@beamer-bridge/deployments/dist/artifacts/goerli/base.deployment.json";
Expand All @@ -25,7 +24,3 @@ export const contractsMeta = {
RESOLVER_DEPLOY_BLOCK_NUMBER: baseMainnet.Resolver.deployment_block,
},
};

export const abis = {
FillManager: FillManagerABI,
};
2 changes: 1 addition & 1 deletion relayer/src/services/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Signer } from "@ethersproject/abstract-signer";
import { BigNumber } from "ethers";
import { readFileSync } from "fs";

import { ArbitrumL1Messenger__factory } from "../../types-gen/contracts";
import { ArbitrumL1Messenger__factory } from "../../types-gen/contracts/beamer";
import { addresses } from "../deployments";
import type { TransactionHash } from "./types";
import { BaseRelayerService } from "./types";
Expand Down
9 changes: 5 additions & 4 deletions relayer/src/services/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from "ethers";
import { keccak256 } from "ethers/lib/utils";

import { EthereumL2Messenger__factory, Resolver__factory } from "../../types-gen/contracts";
import { EthereumL2Messenger__factory, Resolver__factory } from "../../types-gen/contracts/beamer";
import { parseFillInvalidatedEvent } from "../common/events/FillInvalidated";
import { parseRequestFilledEvent } from "../common/events/RequestFilled";
import { addresses, contractsMeta } from "../deployments";
Expand Down Expand Up @@ -78,16 +78,17 @@ export class EthereumRelayerService extends BaseRelayerService {
filler: string,
fillChainId: BigNumber,
resolverAddress: string,
): Promise<string | null> {
): Promise<string | undefined> {
const resolver = Resolver__factory.connect(resolverAddress, this.l1Wallet);
const currentBlock = await this.l1Wallet.provider.getBlock("latest");
let currentBlockNumber = currentBlock.number;
const resolverDeployBlockNumber =
CONTRACTS_DATA[await this.getL1ChainId()].RESOLVER_DEPLOY_BLOCK_NUMBER;

const filter = resolver.filters.Resolution();
while (currentBlockNumber > resolverDeployBlockNumber) {
const events = await resolver.queryFilter(
"Resolution" as unknown,
filter,
currentBlockNumber - FILTER_BLOCKS_PER_ITERATION,
currentBlockNumber,
);
Expand All @@ -110,7 +111,7 @@ export class EthereumRelayerService extends BaseRelayerService {
currentBlockNumber -= FILTER_BLOCKS_PER_ITERATION;
}

return null;
return undefined;
}

private createMessageHash(
Expand Down
8 changes: 3 additions & 5 deletions relayer/src/services/polygon-zkevm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TransactionReceipt } from "@ethersproject/abstract-provider";
import { readFileSync } from "fs";

import { PolygonZKEvmBridge__factory } from "../../types-gen/contracts";
import { PolygonZKEvmBridge__factory } from "../../types-gen/contracts/external/factories/";
import { parseBridgeEvent } from "../common/events/polygon-zkevm/BridgeEvent";
import { sleep } from "../common/util";
import type { TransactionHash } from "./types";
Expand Down Expand Up @@ -40,7 +40,7 @@ export class PolygonZKEvmRelayerService extends BaseRelayerService {
async getMessageMerkleProof(
depositCount: number,
originNetwork: number,
): Promise<MerkleProofResponse | undefined> {
): Promise<MerkleProofResponse> {
const networkConfig = await this.getNetworkConfig();

const merkleProofUrl = new URL(networkConfig.bridgeServiceUrl + this.MERKLE_PROOF_ENDPOINT);
Expand Down Expand Up @@ -96,9 +96,7 @@ export class PolygonZKEvmRelayerService extends BaseRelayerService {

checkTransactionValidity(transactionReceipt: TransactionReceipt, networkName: string): void {
if (!transactionReceipt) {
throw new Error(
`Transaction "${transactionReceipt.transactionHash}" cannot be found on ${networkName}...`,
);
throw new Error(`Transaction cannot be found on ${networkName}...`);
}
if (!transactionReceipt.status) {
throw new Error(
Expand Down

0 comments on commit b459360

Please sign in to comment.