Skip to content

Commit

Permalink
fix: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
zengzengzenghuy committed Oct 25, 2023
1 parent 91981fe commit c902049
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 34 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
**/.coverage_contracts
**/dist
**/node_modules
**/types
**/.yarn

# files
Expand Down
4 changes: 4 additions & 0 deletions packages/reporter/src/BlockListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class BlocksListener {
this.queryBlockLength = configs.queryBlockLength
this.blockBuffer = configs.blockBuffer
this.timeFetchBlocksMs = configs.timeFetchBlocksMs

if (this.queryBlockLength > 256 - this.blockBuffer) {
throw new Error(`Please choose a block length less than ${256 - this.blockBuffer}!`)
}
}

start() {
Expand Down
7 changes: 3 additions & 4 deletions packages/reporter/src/controllers/AMBReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Chain } from "viem"
import winston from "winston"
import "dotenv/config"

import contractABI from "../ABIs/AMBReporterContractABI.json"
import Multiclient from "../MultiClient"
Expand All @@ -12,7 +11,7 @@ class AMBReporterController {
name: string = "amb"
logger: winston.Logger
multiClient: Multiclient
reporterAddress: string
reporterAddress: `0x${string}`
adapterAddresses: { [chainName: string]: `0x${string}` }
gas: string

Expand All @@ -21,7 +20,7 @@ class AMBReporterController {
this.destinationChains = configs.destinationChains
this.logger = configs.logger
this.multiClient = configs.multiClient
this.reporterAddress = configs.reporterAddress !== undefined ? configs.reporterAddress : ""
this.reporterAddress = configs.reporterAddress as `0x${string}`
this.adapterAddresses = configs.adapterAddresses
this.gas = configs.data.gas
}
Expand All @@ -42,7 +41,7 @@ class AMBReporterController {
})

const txhash = await client.writeContract(request)
this.logger.info(`AMB: TxHash from AMB Controller: ${txhash}`)
this.logger.info(`AMB: TxHash from AMB Controller: ${txhash} on ${chain.name}`)
}
} catch (error) {
this.logger.error(`AMB: Error from AMB Controller: ${error}`)
Expand Down
9 changes: 4 additions & 5 deletions packages/reporter/src/controllers/SygmaReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parseEther, Chain } from "viem"
import winston from "winston"
import "dotenv/config"

import contractABI from "../ABIs/SygmaReporterContractABI.json"
import Multiclient from "../MultiClient"
Expand All @@ -12,7 +11,7 @@ class SygmaReporterController {
name: string = "sygma"
logger: winston.Logger
multiClient: Multiclient
reporterAddress: string
reporterAddress: `0x${string}`
adapterAddresses: { [chainName: string]: `0x${string}` }
destinationDomainID: string
fee: string
Expand All @@ -22,13 +21,13 @@ class SygmaReporterController {
this.destinationChains = configs.destinationChains
this.logger = configs.logger
this.multiClient = configs.multiClient
this.reporterAddress = configs.reporterAddress !== undefined ? configs.reporterAddress : ""
this.reporterAddress = configs.reporterAddress as `0x${string}`
this.adapterAddresses = configs.adapterAddresses
this.destinationDomainID = configs.data.destDomainID
this.fee = configs.data.fee
}

async onBlocks(blockNumbers: string[]) {
async onBlocks(blockNumbers: bigint[]) {
try {
this.logger.info("Sygma: Starting Sygma Reporter")
const client = this.multiClient.getClientByChain(this.sourceChain)
Expand All @@ -48,7 +47,7 @@ class SygmaReporterController {
value: parseEther(this.fee),
})
const txhash = await client.writeContract(request)
this.logger.info(`Sygma: TxHash from Sygma Controller: ${txhash}`)
this.logger.info(`Sygma: TxHash from Sygma Controller: ${txhash} on ${chain.name}`)
}
} catch (error) {
this.logger.error(`Sygma: Error from Sygma Controller: ${error}`)
Expand Down
16 changes: 8 additions & 8 deletions packages/reporter/src/controllers/TelepathyReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios from "axios"
import { hexToNumber, Chain } from "viem"
import winston from "winston"
import "dotenv/config"

import lightClientContractABI from "../ABIs/TelepathyContractABI.json"
import adapterContractABI from "../ABIs/TelepathyAdapterABI.json"
Expand All @@ -16,7 +15,7 @@ class TelepathyReporterController {
multiClient: Multiclient
adapterAddresses: { [chainName: string]: `0x${string}` }
lightClientAddresses: { [chainName: string]: `0x${string}` }
proofURL: string
baseProofUrl: string
queryBlockLength: string
blockBuffer: string

Expand All @@ -27,11 +26,11 @@ class TelepathyReporterController {
this.multiClient = configs.multiClient
this.adapterAddresses = configs.adapterAddresses
this.lightClientAddresses = configs.data.lightClientAddresses
this.proofURL = configs.data.proofURL
this.baseProofUrl = configs.data.baseProofUrl
this.queryBlockLength = configs.data.queryBlockLength
this.blockBuffer = configs.data.blockBuffer
}
async onBlocks(blockNumbers: string[]) {
async onBlocks(blockNumbers: bigint[]) {
try {
// Telepathy only support light client on Gnosis at the moment

Expand Down Expand Up @@ -68,10 +67,11 @@ class TelepathyReporterController {
logs.forEach(async (event: any) => {
// get slot value from first indexed
const slotValue = event.topics[1]
this.logger.info(`Fetching proof for slot ${slotValue}`)
const postUrl = this.proofURL + "5" + "/" + hexToNumber(slotValue!) // 5 is chainID for Goerli
this.logger.info(`Fetching proof for slot ${slotValue} on ${chain.name}`)

const response = await axios.post(postUrl)
const url = `${this.baseProofUrl}/${this.sourceChain.id}/${hexToNumber(slotValue!)}`
console.log("URL ", url)
const response = await axios.post(url)
const { chainId, slot, blockNumber, blockNumberProof, blockHash, blockHashProof } = response.data.result
this.logger.info(`Telepathy: Calling storeBlockHeader for block number ${blockNumber}`)

Expand All @@ -83,7 +83,7 @@ class TelepathyReporterController {
})

const txHash = await client.writeContract(request)
this.logger.info(`Telepathy: TxHash from Telepathy Controller: ${txHash} `)
this.logger.info(`Telepathy: TxHash from Telepathy Controller: ${txHash} on ${chain.name} `)
})
}
} catch (error) {
Expand Down
17 changes: 6 additions & 11 deletions packages/reporter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { gnosis, goerli } from "viem/chains"
import winston from "winston"
import "dotenv/config"

import Multiclient from "./MultiClient"
import AMBReporterController from "./controllers/AMBReporterController"
Expand Down Expand Up @@ -37,7 +36,7 @@ function main() {
multiClient,
reporterAddress: settings.contractAddresses.goerli.AMBReporter,
adapterAddresses: { gnosis: settings.contractAddresses.gnosis.AMBAdapter as `0x${string}` },
data: { gas: settings.reporterController.ambReporterController.gas },
data: { gas: settings.reporterControllers.AMBReporterController.gas },
})
const sygmaReporterController = new SygmaReporterController({
sourceChain: goerli,
Expand All @@ -47,8 +46,8 @@ function main() {
reporterAddress: settings.contractAddresses.goerli.SygmaReporter,
adapterAddresses: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter as `0x${string}` },
data: {
fee: settings.reporterController.sygmaReporterController.data,
destDomainID: settings.reporterController.sygmaReporterController.domainID,
fee: settings.reporterControllers.SygmaReporterController.data,
destDomainID: settings.reporterControllers.SygmaReporterController.domainID,
},
})
const telepathyReporterController = new TelepathyReporterController({
Expand All @@ -58,17 +57,13 @@ function main() {
multiClient,
adapterAddresses: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter as `0x${string}` },
data: {
proofURL: settings.reporterController.telepathyReporterController.proofURL,
baseProofUrl: settings.reporterControllers.TelepathyReporterController.baseProofUrl,
lightClientAddresses: { gnosis: settings.contractAddresses.gnosis.TelepathyLightClient },
queryBlockLength: settings.reporterController.telepathyReporterController.queryBlockLength,
blockBuffer: settings.reporterController.telepathyReporterController.blockBuffer,
queryBlockLength: settings.reporterControllers.TelepathyReporterController.queryBlockLength,
blockBuffer: settings.reporterControllers.TelepathyReporterController.blockBuffer,
},
})

if (queryBlockLength > 256 - blockBuffer) {
throw logger.error(`Please choose a block length less than ${256 - Number(settings.blockListener.blockBuffer)}!`)
}

const controllersEnabled = process.env.REPORTERS_ENABLED?.split(",")
const blocksListener = new BlocksListener({
controllers: [ambReporterController, sygmaReporterController, telepathyReporterController].filter(
Expand Down
10 changes: 5 additions & 5 deletions packages/reporter/src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ export const settings = {
TelapathyAdapter: "0x2f1E51a2763FB67fe09971Fd8d849716137A3357",
},
},
reporterController: {
ambReporterController: {
reporterControllers: {
AMBReporterController: {
gas: process.env.AMB_GAS,
},
sygmaReporterController: {
SygmaReporterController: {
domainID: {
gnosis: "101",
goerli: "1",
},
data: process.env.SYGMA_MSG_VALUE,
},
telepathyReporterController: {
proofURL: process.env.TELEPATHY_PROOF_API_URL,
TelepathyReporterController: {
baseProofUrl: process.env.TELEPATHY_PROOF_API_URL,
queryBlockLength: process.env.TELEPATHY_QUERY_BLOCK_LENGTH,
blockBuffer: process.env.TELEPATHY_BLOCK_BUFFER,
},
Expand Down
26 changes: 26 additions & 0 deletions packages/reporter/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Chain } from "viem"
import winston = require("winston")

import Multiclient from "../MultiClient"

type ControllerConfig = {
sourceChain: Chain
destinationChains: Chain[]
reporterAddress?: string
adapterAddresses: { [chainName: string]: `0x${string}` }
logger: winston.Logger
multiClient: Multiclient
data: any // controller-specific data
}

type BlockListenerConfig = {
controllers: any[]
logger: winston.Logger
timeFetchBlocksMs: number
multiclient: Multiclient
sourceChain: Chain
queryBlockLength: number
blockBuffer: number
}

export { ControllerConfig, BlockListenerConfig }

0 comments on commit c902049

Please sign in to comment.