Skip to content

Commit

Permalink
chore(toolchain): removed the calculate profitability and improved er…
Browse files Browse the repository at this point in the history
…ror handling
  • Loading branch information
madhurMongia committed Dec 11, 2024
1 parent 6295b39 commit 2554e55
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 94 deletions.
31 changes: 13 additions & 18 deletions contracts/deploy/03-routers/03-gnosis-to-arb-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

// ----------------------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions contracts/test/merkle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
28 changes: 9 additions & 19 deletions relayer-cli/src/utils/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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: {
Expand All @@ -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 };
54 changes: 0 additions & 54 deletions validator-cli/src/ArbToEth/watcherArbToGnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2554e55

Please sign in to comment.