From afb0e587ed39999dde051b315902fd9b8958866b Mon Sep 17 00:00:00 2001 From: zengzengzenghuy Date: Tue, 24 Oct 2023 14:35:27 +0800 Subject: [PATCH] fix: naming of variables --- packages/reporter/src/BlockListener.ts | 1 - .../src/controllers/AMBReporterController.ts | 26 ++++++------- .../controllers/SygmaReporterController.ts | 22 +++++------ .../TelepathyReporterController.ts | 37 +++++++++---------- packages/reporter/src/index.ts | 27 ++++++++------ 5 files changed, 58 insertions(+), 55 deletions(-) diff --git a/packages/reporter/src/BlockListener.ts b/packages/reporter/src/BlockListener.ts index 4aec356e..7d3bf649 100644 --- a/packages/reporter/src/BlockListener.ts +++ b/packages/reporter/src/BlockListener.ts @@ -40,7 +40,6 @@ class BlocksListener { const client = this.multiclient.getClientByChain(this.sourceChain) const currentBlockNumber = await client.getBlockNumber() - this.logger.info(`Current Block Number: ${currentBlockNumber} , on source chain: ${process.env.SOURCE_CHAIN}`) if (!this.lastProcessedBlock) { this.lastProcessedBlock = await client.getBlockNumber() } diff --git a/packages/reporter/src/controllers/AMBReporterController.ts b/packages/reporter/src/controllers/AMBReporterController.ts index 1e7ddebc..d3de5fde 100644 --- a/packages/reporter/src/controllers/AMBReporterController.ts +++ b/packages/reporter/src/controllers/AMBReporterController.ts @@ -12,18 +12,18 @@ class AMBReporterController { name: string = "amb" logger: winston.Logger multiClient: Multiclient - reporterAddr: string - adapterAddr: { [chainName: string]: string } + reporterAddress: string + adapterAddresses: { [chainName: string]: `0x${string}` } gas: string - constructor(props: ControllerConfig) { - this.sourceChain = props.sourceChain - this.destinationChains = props.destinationChains - this.logger = props.logger - this.multiClient = props.multiClient - this.reporterAddr = props.reporterAddress - this.adapterAddr = props.adapterAddress - this.gas = props.data + constructor(configs: ControllerConfig) { + this.sourceChain = configs.sourceChain + this.destinationChains = configs.destinationChains + this.logger = configs.logger + this.multiClient = configs.multiClient + this.reporterAddress = configs.reporterAddress + this.adapterAddresses = configs.adapterAddresses + this.gas = configs.data } async onBlocks(blockNumbers: bigint[]) { @@ -34,11 +34,11 @@ class AMBReporterController { for (const chain of this.destinationChains) { let chainName = chain.name.toLocaleLowerCase() - const { result, request } = await client.simulateContract({ - address: this.reporterAddr as `0x${string}`, + const { request } = await client.simulateContract({ + address: this.reporterAddress as `0x${string}`, abi: contractABI, functionName: "reportHeaders", - args: [blockNumbers, this.adapterAddr[chainName], this.gas], + args: [blockNumbers, this.adapterAddresses[chainName], this.gas], }) const txhash = await client.writeContract(request) diff --git a/packages/reporter/src/controllers/SygmaReporterController.ts b/packages/reporter/src/controllers/SygmaReporterController.ts index fd5a1d92..55a5ab3c 100644 --- a/packages/reporter/src/controllers/SygmaReporterController.ts +++ b/packages/reporter/src/controllers/SygmaReporterController.ts @@ -14,16 +14,16 @@ class SygmaReporterController { logger: winston.Logger multiClient: Multiclient reporterAddress: string - adapterAddress: { [chainName: string]: string } + adapterAddresses: { [chainName: string]: `0x${string}` } gas: string - constructor(props: ControllerConfig) { - this.sourceChain = props.sourceChain - this.destinationChains = props.destinationChains - this.logger = props.logger - this.multiClient = props.multiClient - this.reporterAddress = props.reporterAddress - this.adapterAddress = props.adapterAddress - this.gas = props.data + constructor(configs: ControllerConfig) { + this.sourceChain = configs.sourceChain + this.destinationChains = configs.destinationChains + this.logger = configs.logger + this.multiClient = configs.multiClient + this.reporterAddress = configs.reporterAddress + this.adapterAddresses = configs.adapterAddresses + this.gas = configs.data } async onBlocks(blockNumbers: string[]) { @@ -33,13 +33,13 @@ class SygmaReporterController { for (const chain of this.destinationChains) { const chainName = chain.name.toLocaleLowerCase() - const { result, request } = await client.simulateContract({ + const { request } = await client.simulateContract({ address: this.reporterAddress as `0x${string}`, abi: contractABI, functionName: "reportHeadersToDomain", args: [ blockNumbers, - this.adapterAddress[chainName], + this.adapterAddresses[chainName], settings.sygmaDomainID[chainName as keyof typeof settings.sygmaDomainID], "0x", ], diff --git a/packages/reporter/src/controllers/TelepathyReporterController.ts b/packages/reporter/src/controllers/TelepathyReporterController.ts index d703bd15..b5146b9b 100644 --- a/packages/reporter/src/controllers/TelepathyReporterController.ts +++ b/packages/reporter/src/controllers/TelepathyReporterController.ts @@ -7,7 +7,6 @@ import lightClientContractABI from "../ABIs/TelepathyContractABI.json" import adapterContractABI from "../ABIs/TelepathyAdapterABI.json" import Multiclient from "../MultiClient" import { ControllerConfig } from "../types/index" -import { settings } from "../settings" class TelepathyReporterController { sourceChain: Chain @@ -15,34 +14,34 @@ class TelepathyReporterController { name: string = "telepathy" logger: winston.Logger multiClient: Multiclient - reporterAddr: string - adapterAddr: { [chainName: string]: string } + reporterAddress: string + adapterAddresses: { [chainName: string]: `0x${string}` } data: any - constructor(props: ControllerConfig) { - this.sourceChain = props.sourceChain - this.destinationChains = props.destinationChains - this.logger = props.logger - this.multiClient = props.multiClient - this.reporterAddr = props.reporterAddress - this.adapterAddr = props.adapterAddress - this.data = props.data + constructor(configs: ControllerConfig) { + this.sourceChain = configs.sourceChain + this.destinationChains = configs.destinationChains + this.logger = configs.logger + this.multiClient = configs.multiClient + this.reporterAddress = configs.reporterAddress + this.adapterAddresses = configs.adapterAddresses + this.data = configs.data } async onBlocks(blockNumbers: string[]) { try { - // Telepathy on support light client on Gnosis at the moment + // Telepathy only support light client on Gnosis at the moment for (const chain of this.destinationChains) { const client = this.multiClient.getClientByChain(chain) - const adapterAddr = this.adapterAddr[chain.name.toLocaleLowerCase()] - const lightClientAddr = settings.contractAddresses.gnosis.TelepathyLightClient + const adapterAddr = this.adapterAddresses[chain.name.toLocaleLowerCase()] + const lightClientAddr = this.data.lightClientAddress // Getting the latest block number from provider const currentBlockNumber = await client.getBlockNumber() - // get contract events from latest block - 1000 : latest block - 10 - const queryBlockLength = 1000n // the number of blocks to query - const blockBuffer = 10n // put 10 blocks before the current block in case the node provider don't sync up at the head + // get contract events from latest block - queryBlockLength : latest block - blockBuffer + const queryBlockLength = BigInt(this.data.queryBlockLength) // the number of blocks to query + const blockBuffer = BigInt(this.data.blockBuffer) // put ${buffer} blocks before the current block in case the node provider don't sync up at the head const startBlock = currentBlockNumber - queryBlockLength const endBlock = currentBlockNumber - blockBuffer @@ -65,13 +64,13 @@ class TelepathyReporterController { // get slot value from first indexed const slotValue = event.topics[1] this.logger.info(`Fetching proof for slot ${slotValue}`) - const postUrl = this.data + "5" + "/" + hexToNumber(slotValue!) + const postUrl = this.data.proofURL + "5" + "/" + hexToNumber(slotValue!) const response = await axios.post(postUrl) const { chainId, slot, blockNumber, blockNumberProof, blockHash, blockHashProof } = response.data.result this.logger.info(`Telepathy: Calling storeBlockHeader for block number ${blockNumber}`) - const { request, result } = await client.simulateContract({ + const { request } = await client.simulateContract({ address: adapterAddr as `0x${string}`, abi: adapterContractABI, functionName: "storeBlockHeader", diff --git a/packages/reporter/src/index.ts b/packages/reporter/src/index.ts index 5d034bbb..2ed27d3d 100644 --- a/packages/reporter/src/index.ts +++ b/packages/reporter/src/index.ts @@ -32,29 +32,34 @@ function main() { const ambReporterController = new AMBReporterController({ sourceChain: goerli, destinationChains: [gnosis], - logger: logger, - multiClient: multiClient, + logger, + multiClient, reporterAddress: settings.contractAddresses.goerli.AMBReporter, - adapterAddress: { gnosis: settings.contractAddresses.gnosis.AMBAdapter }, + adapterAddresses: { gnosis: settings.contractAddresses.gnosis.AMBAdapter as `0x${string}` }, data: process.env.GAS, // gas to call amb }) const sygmaReporterController = new SygmaReporterController({ sourceChain: goerli, destinationChains: [gnosis], - logger: logger, - multiClient: multiClient, + logger, + multiClient, reporterAddress: settings.contractAddresses.goerli.SygmaReporter, - adapterAddress: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter }, + adapterAddresses: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter as `0x${string}` }, data: "0.0001", // msg.value in ether }) const telepathyReporterController = new TelepathyReporterController({ sourceChain: goerli, destinationChains: [gnosis], - logger: logger, - multiClient: multiClient, + logger, + multiClient, reporterAddress: "", // reporter address is not required in telepathy - adapterAddress: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter }, - data: process.env.TELEPATHY_PROOF_API_URL, + adapterAddresses: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter as `0x${string}` }, + data: { + proofURL: process.env.TELEPATHY_PROOF_API_URL, + lightClientAddress: settings.contractAddresses.gnosis.TelepathyLightClient, + queryBlockLength: 1000, + blockBuffer: 10, + }, }) const controllersEnabled = process.env.REPORTERS_ENABLED?.split(",") @@ -63,7 +68,7 @@ function main() { (controller) => controllersEnabled?.includes(controller.name), ), timeFetchBlocksMs: timeFetchBlocksMs, - logger: logger, + logger, multiclient: multiClient, sourceChain: goerli, queryBlockLength: 100, // modify the query block length here, <256