Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ CHIADO_RPC="https://rpc.chiadochain.net"
# There seems to be a bug with hardhat-deploy's implementation of etherscan-verify
# If ETHERSCAN_API_KEY is set, it overrides any hardhat configuration.
ETHERSCAN_API_KEY_FIX=
ARBISCAN_API_KEY=
ARBISCAN_API_KEY=

# Optional logging options
LOG_LEVEL=info
2 changes: 1 addition & 1 deletion contracts/L2/Switch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

pragma solidity ^0.8.18;

import "@kleros/vea-contracts/interfaces/inboxes/IVeaInbox.sol";
import "@kleros/vea-contracts/src/interfaces/inboxes/IVeaInbox.sol";
import "../interfaces/ILightBulb.sol";

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "yarn hardhat compile",
"lightbulb": "yarn build && yarn deploy && yarn verify && yarn ts-node",
"hit-switch": "yarn ts-node scripts/hit-switch.ts",
"hit-switch": "ts-node scripts/hit-switch.ts",
"lightbulb:chiado": "yarn build && yarn deploy:chiado && yarn verify:chiado",
"deploy": "yarn hardhat deploy --network goerli && yarn hardhat deploy --network arbitrumGoerli --tags switch-to-goerli",
"deploy:chiado": "yarn hardhat deploy --network chiado && yarn hardhat deploy --network arbitrumGoerli --tags switch-to-chiado",
Expand All @@ -23,7 +23,7 @@
"typescript": "^5.0.2"
},
"dependencies": {
"@kleros/vea-contracts": "^0.2.0",
"@kleros/vea-sdk": "^0.4.0",
"@typechain/ethers-v5": "^11.0.0",
"@typechain/hardhat": "^7.0.0",
"dotenv": "^8.2.0",
Expand Down
101 changes: 65 additions & 36 deletions scripts/hit-switch.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,75 @@
import { providers, Wallet } from 'ethers'
const { BigNumber } = require('@ethersproject/bignumber')
import * as dotenv from "dotenv";
import {Switch, Switch__factory, Lightbulb} from '../typechain-types/'
const switchDeployment = require('../deployments/arbitrumGoerli/SwitchArbitrumGoerliToGoerli.json')
dotenv.config();

const envVars = ['PRIVATE_KEY', 'GOERLI_RPC', 'ARBGOERLI_RPC'];

for (const envVar of envVars) {
if (!process.env[envVar]) {
throw new Error(`Error: set your '${envVar}' environmental variable `)
}
}
console.log('Environmental variables properly set 👍')
import { Wallet } from "ethers";
import VeaSdk from "@kleros/vea-sdk";
import env from "@kleros/vea-sdk/dist/utils/env";
import { Switch__factory } from "../typechain-types/";
const switchDeployment = require("../deployments/arbitrumGoerli/SwitchArbitrumGoerliToGoerli.json");

/**
* Set up: instantiate L1 / L2 wallets connected to providers
*/
// Optional logger configuration
const loggerOptions = {
transportTargetOptions: {
target: "@logtail/pino",
options: { sourceToken: env.require("LOGTAIL_TOKEN") },
level: env.optional("LOG_LEVEL", "info"),
},
};

const l2ProviderArbGoerli = new providers.JsonRpcProvider(process.env.ARBGOERLI_RPC)
// Create the Vea client
const vea = VeaSdk.ClientFactory.arbitrumGoerliToGoerliDevnet(
env.require("ARBGOERLI_RPC"),
env.require("GOERLI_RPC"),
loggerOptions
);

const main = async () => {
const privateKey = env.require("PRIVATE_KEY");
const logger = vea.logger
logger.info("Environmental variables properly set 👍");

const switchContract = Switch__factory.connect(switchDeployment.address, new Wallet(process.env.PRIVATE_KEY!, l2ProviderArbGoerli));
const main = async () => {
const wallet = new Wallet(privateKey, vea.inboxProvider);
const switchContract = Switch__factory.connect(
switchDeployment.address,
wallet
);
const switchTxn = await switchContract.turnOnLightBulb();
await switchTxn.wait()
console.log('Switch hit 🎚️: ', switchTxn.hash)
const switchTxnMined = await switchTxn.wait()
logger.info("Switch hit 🎚️:", switchTxn);
logger.info("Tx mined: %O", switchTxnMined?.events && switchTxnMined.events[1].args);
logger.debug(`Filtering on blockNumber: ${switchTxnMined.blockNumber}`);

const timeNow = Math.floor(Date.now()/1000)
const eta = Math.ceil((timeNow / 1800))*1800 - timeNow + 60;
console.log(`Waiting for Vea Devnet to Bridge Message. ETA ~ ${Math.floor(eta/60)} min ${eta % 60} seconds`)
await delay(eta*1000)
// TODO Proof Relay
}
const timeNow = Math.floor(Date.now() / 1000);
const eta = Math.ceil(timeNow / 1800) * 1800 - timeNow + 60;
logger.info(
`Waiting for Vea Devnet to Bridge Message. ETA ~ ${Math.floor(
eta / 60
)} min ${eta % 60} seconds`
);
await delay(eta * 1000);

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error)
process.exit(1)
})
const logs = await switchContract.queryFilter(
switchContract.filters.lightBulbToggled(),
switchTxnMined.blockNumber,
switchTxnMined.blockNumber
);
const messageId = logs[0].args.messageId.toNumber();
logger.info(`Message ID: ${messageId}`);

// Get the message proof and data
const messageInfo = await vea.getMessageInfo(messageId);
logger.info("Message Info: %O", messageInfo);

// Relay the message
const outboxWallet = new Wallet(privateKey, vea.outboxProvider);
await vea.relay(messageInfo, outboxWallet);
logger.info(`Message ID ${messageId} relayed ✅`);
};

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
VeaSdk.ClientFactory.logger.error(error);
process.exit(1);
});
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"compilerOptions": {
"target": "es2018",
"target": "es2021",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"noImplicitAny": false,
"resolveJsonModule": true
},
"include": ["./scripts", "./test", "./typechain-types"],
Expand Down
Loading