Skip to content

Commit

Permalink
fix: naming of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zengzengzenghuy committed Oct 24, 2023
1 parent a7fe83e commit afb0e58
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 55 deletions.
1 change: 0 additions & 1 deletion packages/reporter/src/BlockListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
26 changes: 13 additions & 13 deletions packages/reporter/src/controllers/AMBReporterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions packages/reporter/src/controllers/SygmaReporterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand All @@ -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",
],
Expand Down
37 changes: 18 additions & 19 deletions packages/reporter/src/controllers/TelepathyReporterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,41 @@ 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
destinationChains: Chain[]
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

Expand All @@ -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",
Expand Down
27 changes: 16 additions & 11 deletions packages/reporter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand All @@ -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
Expand Down

0 comments on commit afb0e58

Please sign in to comment.