From 2554e5529dee1047e41dbc7e70b896662d69d18c Mon Sep 17 00:00:00 2001 From: madhurMongia Date: Wed, 11 Dec 2024 22:37:47 +0700 Subject: [PATCH] chore(toolchain): removed the calculate profitability and improved error handling --- .../03-routers/03-gnosis-to-arb-router.ts | 31 +++++------ contracts/test/merkle/index.ts | 3 -- relayer-cli/src/utils/relay.ts | 28 ++++------ .../src/ArbToEth/watcherArbToGnosis.ts | 54 ------------------- 4 files changed, 22 insertions(+), 94 deletions(-) diff --git a/contracts/deploy/03-routers/03-gnosis-to-arb-router.ts b/contracts/deploy/03-routers/03-gnosis-to-arb-router.ts index 66c88076..7752a08f 100644 --- a/contracts/deploy/03-routers/03-gnosis-to-arb-router.ts +++ b/contracts/deploy/03-routers/03-gnosis-to-arb-router.ts @@ -75,24 +75,19 @@ const deployRouter: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const liveDeployer = async () => { const { outboxNetwork, inboxNetwork } = getNetworkConfig(chainId); - try { - const [veaOutbox, veaInbox] = await Promise.all([ - hre.companionNetworks[outboxNetwork].deployments.get(`VeaOutboxGnosisToArb${suffix}`), - hre.companionNetworks[inboxNetwork].deployments.get(`VeaInboxGnosisToArb${suffix}`), - ]); - - const router = await deploy(deploymentName, { - from: deployer, - contract: contractBaseName, - args: [arbitrumBridge, amb, veaInbox.address, veaOutbox.address, chainId], - log: true, - }); - - console.log(`${deploymentName} deployed to: ${router.address}`); - } catch (error) { - console.error("Failed to deploy:", error); - throw error; - } + const [veaOutbox, veaInbox] = await Promise.all([ + hre.companionNetworks[outboxNetwork].deployments.get(`VeaOutboxGnosisToArb${suffix}`), + hre.companionNetworks[inboxNetwork].deployments.get(`VeaInboxGnosisToArb${suffix}`), + ]); + + const router = await deploy(deploymentName, { + from: deployer, + contract: contractBaseName, + args: [arbitrumBridge, amb, veaInbox.address, veaOutbox.address, chainId], + log: true, + }); + + console.log(`${deploymentName} deployed to: ${router.address}`); }; // ---------------------------------------------------------------------------------------------- diff --git a/contracts/test/merkle/index.ts b/contracts/test/merkle/index.ts index b653e364..9a7fe2cc 100644 --- a/contracts/test/merkle/index.ts +++ b/contracts/test/merkle/index.ts @@ -39,9 +39,6 @@ describe("Merkle", () => { merkleTreeExposed = await merkleTreeExposedFactory.deploy(); merkleProofExposed = await merkleProofExposedFactory.deploy(); - - // Note: In ethers v6, we don't need to call deployed() anymore - // The deploy() promise resolves only after the contract is deployed }); it("Merkle Root verification", async () => { diff --git a/relayer-cli/src/utils/relay.ts b/relayer-cli/src/utils/relay.ts index 5ce3a9fc..3b3a0f06 100644 --- a/relayer-cli/src/utils/relay.ts +++ b/relayer-cli/src/utils/relay.ts @@ -35,14 +35,9 @@ const relay = async (chainId: number, nonce: number) => { getMessageDataToRelay(chainId, nonce), ]); - try { - const txn = await veaOutbox.sendMessage(proof, nonce, to, data); - const receipt = await txn.wait(); - return receipt; - } catch (error) { - console.error("Transaction failed:", error); - throw error; - } + const txn = await veaOutbox.sendMessage(proof, nonce, to, data); + const receipt = await txn.wait(); + return receipt; }; const relayBatch = async (chainId: number, nonce: number, maxBatchSize: number) => { @@ -121,12 +116,11 @@ const relayAllFrom = async (chainId: number, nonce: number, msgSender: string): }; const getNonceFrom = async (chainId: number, nonce: number, msgSender: string) => { - try { - const subgraph = getInboxSubgraph(chainId); + const subgraph = getInboxSubgraph(chainId); - const result = await request( - `https://api.studio.thegraph.com/query/${subgraph}`, - `{ + const result = await request( + `https://api.studio.thegraph.com/query/${subgraph}`, + `{ messageSents( first: 1000, where: { @@ -139,13 +133,9 @@ const getNonceFrom = async (chainId: number, nonce: number, msgSender: string) = nonce } }` - ); + ); - return result[`messageSents`].map((a: { nonce: number }) => a.nonce); - } catch (e) { - console.error("Error getting nonces:", e); - return undefined; - } + return result[`messageSents`].map((a: { nonce: number }) => a.nonce); }; export { relayAllFrom, relay, relayBatch }; diff --git a/validator-cli/src/ArbToEth/watcherArbToGnosis.ts b/validator-cli/src/ArbToEth/watcherArbToGnosis.ts index 80efca20..890382e6 100644 --- a/validator-cli/src/ArbToEth/watcherArbToGnosis.ts +++ b/validator-cli/src/ArbToEth/watcherArbToGnosis.ts @@ -332,7 +332,6 @@ const watch = async () => { "challenge progess for epoch " + veaEpochOutboxCheck + " is " + JSON.stringify(challengeProgress) ); //TODO : check profitablity of the whole dispute resolution - //const profitablity = await calculateDisputeResolutionProfitability(veaEpochOutboxCheck,claim,veaOutbox,veaInbox,providerGnosis,providerArb,providerEth); if (claim.challenger == ethers.ZeroAddress) { if (challengeProgress?.challenge.status == "pending") continue; const txnChallenge = (await retryOperation( @@ -746,59 +745,6 @@ async function getClaimForEpoch( return null; } -// async function calculateDisputeResolutionProfitability( -// epoch: number, -// claim: ClaimStruct, -// veaOutbox: VeaOutboxArbToGnosis, -// veaInbox: VeaInboxArbToGnosis, -// providerGnosis: JsonRpcProvider, -// providerArb: JsonRpcProvider, -// providerEth: JsonRpcProvider -// ): Promise<{ profitable: boolean; estimatedProfit: BigInt }> { -// try { -// const deposit = await retryOperation(() => veaOutbox.deposit(), 1000, 10) as bigint; -// const totalReward = deposit; -// const minimumProfit = totalReward * BigInt(40) / BigInt(100); // 40% of total reward -// let maximumAllowableCost = totalReward - minimumProfit; -// let totalCost = BigInt(0); - -// // 1. Costs on Gnosis Chain -// const gnosisGasEstimate = await veaOutbox.challenge.estimateGas(epoch, claim); - -// const gnosisGasPrice = await providerGnosis.getGasPrice(); -// const gnosisCost = gnosisGasEstimate * gnosisGasPrice; - -// if (gnosisCost > maximumAllowableCost) { -// return { profitable: false, estimatedProfit: BigInt(0) }; -// } -// totalCost = totalCost + gnosisCost; -// maximumAllowableCost = maximumAllowableCost - gnosisCost; - -// const l2Network = await getArbitrumNetwork(providerArb); - -// const arbGasEstimate = (await retryOperation( -// () => veaInbox.sendSnapshot.estimateGas(epoch, 200000, claim), -// 1000, -// 10 -// )) as BigInt; - -// const arbGasPrice = (await retryOperation(() => providerArb.getGasPrice(), 1000, 10)) as BigInt; -// const arbCost = arbGasEstimate * arbGasPrice; - -// if (arbCost > maximumAllowableCost) { -// return { profitable: false, estimatedProfit: BigInt(0) }; -// } -// totalCost = totalCost + arbCost; -// maximumAllowableCost = maximumAllowableCost - arbCost; - -// // 3. Costs on Ethereum (for Arbitrum -> Ethereum message) -// //TODO : L2 to L1 message execution gas cost -// } catch (error) { -// console.error("Error calculating profitability:", error); -// return { profitable: false, estimatedProfit: BigInt(0) }; -// } -// } - function needsRetry(current: ChallengeProgress, previous: ChallengeProgress | undefined): boolean { if (!previous) return false;