Skip to content

Commit

Permalink
chore(devnet): upgraded devent and review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurMongia committed Dec 10, 2024
1 parent 9855dbc commit 0756c69
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseEther, parseUnits } from "ethers";
import { parseEther } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../../deploy-helpers/getContractAddress";
Expand Down
4 changes: 4 additions & 0 deletions contracts/deploy/03-routers/03-gnosis-to-arb-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const deployRouter: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const contractBaseName = "RouterGnosisToArb";
const deploymentName = `${contractBaseName}${suffix}`;

if (!(RouterChains[chainId] in paramsByChainId)) {
throw new Error(`Unsupported chain ID: ${chainId}`);
}

// ----------------------------------------------------------------------------------------------
const hardhatDeployer = async () => {
const [veaOutbox, veaInbox] = await Promise.all([
Expand Down
6 changes: 3 additions & 3 deletions validator-cli/src/ArbToEth/watcherArbToGnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ const watch = async () => {

const wethAddress = (await retryOperation(() => veaOutbox.weth(), 1000, 10)) as string;
const weth = getWETH(wethAddress, process.env.PRIVATE_KEY, process.env.RPC_GNOSIS);
const balance = (await retryOperation(() => weth.balanceOf(watcherAddress), 1000, 10)) as BigInt;
const allowance = (await retryOperation(() => weth.allowance(watcherAddress, veaOutboxAddress), 1000, 10)) as BigInt;
const balance = (await retryOperation(() => weth.balanceOf(watcherAddress), 1000, 10)) as bigint;
const allowance = (await retryOperation(() => weth.allowance(watcherAddress, veaOutboxAddress), 1000, 10)) as bigint;

// get Arb sequencer params
const l2Network = await getArbitrumNetwork(providerArb);
const sequencer = SequencerInbox__factory.connect(l2Network.ethBridge.sequencerInbox, providerEth);
const maxDelaySeconds = Number((await retryOperation(() => sequencer.maxTimeVariation(), 1000, 10))[1] as BigInt);

// get vea outbox params
const deposit = await retryOperation(() => veaOutbox.deposit(), 1000, 10);
const deposit = (await retryOperation(() => veaOutbox.deposit(), 1000, 10)) as bigint;
const epochPeriod = Number(await retryOperation(() => veaOutbox.epochPeriod(), 1000, 10));
const sequencerDelayLimit = Number(await retryOperation(() => veaOutbox.sequencerDelayLimit(), 1000, 10));

Expand Down
40 changes: 18 additions & 22 deletions validator-cli/src/utils/devnet.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { BigNumber, utils } from "ethers";
import { getVeaInboxArbToEthProvider, getVeaOutboxArbToEthDevnetProvider } from "../utils/ethers";
import { ethers } from "ethers";
import { getVeaInboxArbToEth, getVeaOutboxArbToEthDevnet } from "../utils/ethers";
import { VeaInboxArbToEth, VeaOutboxArbToEthDevnet } from "@kleros/vea-contracts/typechain-types";
import { JsonRpcProvider } from "@ethersproject/providers";

async function initialize(
veaOutboxAddress: string,
veaInboxAddress: string,
outboxRPCUrl: string
): Promise<[VeaInboxArbToEth, number, BigNumber, VeaOutboxArbToEthDevnet, BigNumber]> {
): Promise<[VeaInboxArbToEth, number, BigInt, VeaOutboxArbToEthDevnet, BigInt]> {
const outboxProvider = new JsonRpcProvider(outboxRPCUrl);
const veaOutbox = getVeaOutboxArbToEthDevnetProvider(veaOutboxAddress, process.env.PRIVATE_KEY, outboxProvider);
const veaOutbox = getVeaOutboxArbToEthDevnet(veaOutboxAddress, process.env.PRIVATE_KEY, outboxRPCUrl);

const arbSepoliaProvider = new JsonRpcProvider(process.env.RPC_ARB_SEPOLIA);
const veaInbox = getVeaInboxArbToEthProvider(veaInboxAddress, process.env.PRIVATE_KEY, arbSepoliaProvider);
const veaInbox = getVeaInboxArbToEth(veaInboxAddress, process.env.PRIVATE_KEY, process.env.RPC_ARB_SEPOLIA);

const deposit = await veaOutbox.deposit();
const epochPeriod = (await veaOutbox.epochPeriod()).toNumber();
const epochPeriod = Number(await veaOutbox.epochPeriod());
let currentTS = Math.floor(Date.now() / 1000);
let claimableEpoch = Math.floor(currentTS / epochPeriod);

Expand All @@ -29,57 +29,53 @@ async function initialize(
// not really correct since l2 blocks are different, but just an estimate
const searchBlock = Math.max(0, (await arbSepoliaProvider.getBlockNumber()) - Math.floor(1209600 / 12));

const logs = await arbSepoliaProvider.getLogs({
address: veaInboxAddress,
topics: veaInbox.filters.SnapshotSaved(null).topics,
fromBlock: searchBlock,
});
const logs = await veaInbox.queryFilter(veaInbox.filters.SnapshotSaved(null), searchBlock);

let lastSavedCount =
logs.length > 0
? utils.defaultAbiCoder.decode(["bytes32", "uint256", "uint64"], logs[logs.length - 1].data)[2]
: BigNumber.from(0);
? ethers.AbiCoder.defaultAbiCoder().decode(["bytes32", "uint256", "uint64"], logs[logs.length - 1].data)[2]
: BigInt(0);
return [veaInbox, epochPeriod, lastSavedCount, veaOutbox, deposit];
}

async function happyPath(
veaInbox: VeaInboxArbToEth,
epochPeriod: number,
lastSavedCount: BigNumber,
lastSavedCount: BigInt,
veaOutbox: VeaOutboxArbToEthDevnet,
deposit: BigNumber
): Promise<BigNumber> {
deposit: BigInt
): Promise<BigInt> {
let currentTS = Math.floor(Date.now() / 1000);
let claimableEpoch = Math.floor(currentTS / epochPeriod);
let newCount = lastSavedCount;
const snapshot = await veaInbox.snapshots(claimableEpoch);

if (snapshot == "0x0000000000000000000000000000000000000000000000000000000000000000") {
// check if snapshot should be taken
const inboxCount = await veaInbox.count();
if (inboxCount.gt(lastSavedCount)) {
const inboxCount: BigInt = await veaInbox.count();
if (inboxCount > lastSavedCount) {
// should take snapshot
console.log("inbox updated: taking snapshot. . .");
const txn = await veaInbox.saveSnapshot();
const receipt = await txn.wait();

newCount = BigNumber.from(receipt.logs[0].data);
newCount = BigInt(receipt.logs[0].data);

const snapshot = await veaInbox.snapshots(claimableEpoch);
console.log(`Snapshot Txn: ${txn.hash}`);
console.log("snapshot count: ", receipt.logs[0].data);
lastSavedCount = inboxCount;
const txnOutbox = await veaOutbox.devnetAdvanceState(claimableEpoch, snapshot, { value: deposit });
const txnOutbox = await veaOutbox.devnetAdvanceState(claimableEpoch, snapshot, { value: Number(deposit) });
console.log(`DevnetAdvanceState Txn: ${txnOutbox.hash}`);
} else {
console.log("inbox not updated: not taking snapshot. . .");
}
} else {
console.log("snapshot already taken. . .");
const latestVerifiedEpoch = await veaOutbox.latestVerifiedEpoch();
if (latestVerifiedEpoch.toNumber() < claimableEpoch) {
if (latestVerifiedEpoch < claimableEpoch) {
console.log("advancing devnet state. . .");
const txnOutbox = await veaOutbox.devnetAdvanceState(claimableEpoch, snapshot, { value: deposit });
const txnOutbox = await veaOutbox.devnetAdvanceState(claimableEpoch, snapshot, { value: Number(deposit) });
console.log(`DevnetAdvanceState Txn: ${txnOutbox.hash}`);
}
}
Expand Down
30 changes: 1 addition & 29 deletions validator-cli/src/utils/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
VeaOutboxArbToEth__factory,
VeaOutboxArbToGnosis__factory,
VeaOutboxArbToEthDevnet__factory,
VeaOutboxArbToGnosisDevnet__factory,
VeaOutboxMultiChallenge__factory,
VeaInboxArbToEth__factory,
VeaInboxArbToGnosis__factory,
IWETH__factory,
Expand All @@ -24,26 +22,6 @@ function getVeaInboxArbToEth(veaInboxAddress: string, privateKey: string, web3Pr
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWallet(privateKey, web3ProviderURL));
}

function getVeaInboxArbToEthProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaInboxArbToEth__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
}

function getVeaOutboxArbToEthProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
}

function getVeaOutboxMultiChallengeProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaOutboxMultiChallenge__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
}

function getVeaOutboxArbToGnosisProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaOutboxArbToGnosis__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
}

function getVeaInboxArbToGnosisProvider(veaInboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaInboxArbToGnosis__factory.connect(veaInboxAddress, getWalletRPC(privateKey, rpc));
}

function getWETH(WETH: string, privateKey: string, web3ProviderURL: string) {
return IWETH__factory.connect(WETH, getWallet(privateKey, web3ProviderURL));
}
Expand All @@ -52,10 +30,6 @@ function getVeaOutboxArbToEth(veaOutboxAddress: string, privateKey: string, web3
return VeaOutboxArbToEth__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL));
}

function getVeaOutboxArbToEthDevnetProvider(veaOutboxAddress: string, privateKey: string, rpc: JsonRpcProvider) {
return VeaOutboxArbToEthDevnet__factory.connect(veaOutboxAddress, getWalletRPC(privateKey, rpc));
}

function getVeaOutboxArbToEthDevnet(veaOutboxAddress: string, privateKey: string, web3ProviderURL: string) {
return VeaOutboxArbToEthDevnet__factory.connect(veaOutboxAddress, getWallet(privateKey, web3ProviderURL));
}
Expand All @@ -79,10 +53,8 @@ export {
getVeaOutboxArbToEth,
getWalletRPC,
getWallet,
getVeaOutboxArbToEthDevnetProvider,
getVeaOutboxArbToEthDevnet,
getVeaInboxArbToEth,
getVeaInboxArbToEthProvider,
getVeaOutboxArbToEthProvider,
getVeaOutboxArbToGnosis,
getVeaInboxArbToGnosis,
getVeaRouterArbToGnosis,
Expand Down

0 comments on commit 0756c69

Please sign in to comment.