Skip to content

Commit

Permalink
remove process.env in class and add data field as constructor parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
zengzengzenghuy committed Oct 24, 2023
1 parent 79883e0 commit a7fe83e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
9 changes: 4 additions & 5 deletions packages/reporter/src/controllers/AMBReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Chain } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import winston from "winston"
import "dotenv/config"

Expand All @@ -15,13 +14,16 @@ class AMBReporterController {
multiClient: Multiclient
reporterAddr: string
adapterAddr: { [chainName: string]: 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
}

async onBlocks(blockNumbers: bigint[]) {
Expand All @@ -30,16 +32,13 @@ class AMBReporterController {

const client = this.multiClient.getClientByChain(this.sourceChain)

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)

for (const chain of this.destinationChains) {
let chainName = chain.name.toLocaleLowerCase()
const { result, request } = await client.simulateContract({
account, // calling from account
address: this.reporterAddr as `0x${string}`,
abi: contractABI,
functionName: "reportHeaders",
args: [blockNumbers, this.adapterAddr[chainName], process.env.GAS],
args: [blockNumbers, this.adapterAddr[chainName], this.gas],
})

const txhash = await client.writeContract(request)
Expand Down
8 changes: 3 additions & 5 deletions packages/reporter/src/controllers/SygmaReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { parseEther, Chain } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import winston from "winston"
import "dotenv/config"

Expand All @@ -16,26 +15,25 @@ class SygmaReporterController {
multiClient: Multiclient
reporterAddress: string
adapterAddress: { [chainName: string]: 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
}

async onBlocks(blockNumbers: string[]) {
try {
this.logger.info("Sygma: Starting Sygma Reporter")
const client = this.multiClient.getClientByChain(this.sourceChain)

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)

for (const chain of this.destinationChains) {
const chainName = chain.name.toLocaleLowerCase()
const { result, request } = await client.simulateContract({
account, // calling from account
address: this.reporterAddress as `0x${string}`,
abi: contractABI,
functionName: "reportHeadersToDomain",
Expand All @@ -45,7 +43,7 @@ class SygmaReporterController {
settings.sygmaDomainID[chainName as keyof typeof settings.sygmaDomainID],
"0x",
],
value: parseEther("0.0001"),
value: parseEther(this.gas),
})
const txhash = await client.writeContract(request)
this.logger.info(`Sygma: TxHash from Sygma Controller: ${txhash}`)
Expand Down
10 changes: 5 additions & 5 deletions packages/reporter/src/controllers/TelepathyReporterController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import axios from "axios"
import { hexToNumber, Chain } from "viem"
import { privateKeyToAccount } from "viem/accounts"
import winston from "winston"
import "dotenv/config"

Expand All @@ -18,21 +17,22 @@ class TelepathyReporterController {
multiClient: Multiclient
reporterAddr: string
adapterAddr: { [chainName: string]: 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
}
async onBlocks(blockNumbers: string[]) {
try {
// Telepathy on support light client on Gnosis at the moment

for (const chain of this.destinationChains) {
const client = this.multiClient.getClientByChain(chain)
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)

const adapterAddr = this.adapterAddr[chain.name.toLocaleLowerCase()]
const lightClientAddr = settings.contractAddresses.gnosis.TelepathyLightClient
Expand Down Expand Up @@ -65,13 +65,13 @@ class TelepathyReporterController {
// get slot value from first indexed
const slotValue = event.topics[1]
this.logger.info(`Fetching proof for slot ${slotValue}`)
const postUrl = process.env.TELEPATHY_PROOF_API_URL + "5" + "/" + hexToNumber(slotValue!)
const postUrl = this.data + "5" + "/" + hexToNumber(slotValue!)

const response = await axios.post(postUrl)
this.logger.info(`Telepathy: Response from telepathy proof provider: ${response.data}`)
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({
account,
address: adapterAddr as `0x${string}`,
abi: adapterContractABI,
functionName: "storeBlockHeader",
Expand Down
5 changes: 4 additions & 1 deletion packages/reporter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function main() {
multiClient: multiClient,
reporterAddress: settings.contractAddresses.goerli.AMBReporter,
adapterAddress: { gnosis: settings.contractAddresses.gnosis.AMBAdapter },
data: process.env.GAS, // gas to call amb
})
const sygmaReporterController = new SygmaReporterController({
sourceChain: goerli,
Expand All @@ -44,14 +45,16 @@ function main() {
multiClient: multiClient,
reporterAddress: settings.contractAddresses.goerli.SygmaReporter,
adapterAddress: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter },
data: "0.0001", // msg.value in ether
})
const telepathyReporterController = new TelepathyReporterController({
sourceChain: goerli,
destinationChains: [gnosis],
logger: logger,
multiClient: multiClient,
reporterAddress: "",
reporterAddress: "", // reporter address is not required in telepathy
adapterAddress: { gnosis: settings.contractAddresses.gnosis.SygmaAdapter },
data: process.env.TELEPATHY_PROOF_API_URL,
})

const controllersEnabled = process.env.REPORTERS_ENABLED?.split(",")
Expand Down

0 comments on commit a7fe83e

Please sign in to comment.