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
12 changes: 5 additions & 7 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
# Your Private key
PRIVATE_KEY="0x your key here"

# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Goerli TestnET.
ARBGOERLI_RPC="https://goerli-rollup.arbitrum.io/rpc"
# Hosted Aggregator Node (JSON-RPC Endpoint). This is Arbitrum Sepolia TestnET.
ARBSEPOLIA_RPC="https://Sepolia-rollup.arbitrum.io/rpc"

# Ethereum RPC; i.e., for Goerli https://goerli.infura.io/v3/<your infura key>
GOERLI_RPC=""
# Ethereum RPC; i.e., for Sepolia https://sepolia.infura.io/v3/<your infura key>
SEPOLIA_RPC=""

# Gnosis RPC; i.e., for Chiado https://rpc.chiadochain.net
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=
ETHERSCAN_API_KEY=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ artifacts/
cache/
build/
node_modules/
.env
.env
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
20 changes: 13 additions & 7 deletions contracts/L1/Lightbulb.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: MIT

import "../interfaces/IReceiverGateway.sol";

/**
* @authors: [@shotaronowhere]
* @authors: [@shotaronowhere, @mani99brar]
* @reviewers: []
* @auditors: []
* @bounties: []
Expand All @@ -15,7 +17,7 @@ pragma solidity ^0.8.18;
* @dev A lightbulb controlled by a cross-chain switch connected with the Vea bridge.
**/

contract Lightbulb{
contract Lightbulb is IReceiverGateway {

address public immutable veaOutbox; // vea bridge on L1
address public immutable lightBulbSwitch; // The switch on arbitrum that controls this lightbulb.
Expand All @@ -32,13 +34,17 @@ contract Lightbulb{
_;
}

function senderGateway() external view override returns (address) {
return lightBulbSwitch;
}

/**
* @dev Toggles the lightbulb on or off.
* @param _msgSender The address of the sender on the L2 side.
* @param lightBulbOwner The address of the owner of the lightbulb on the L2 side.
* @dev Receives the message from VeaOutbox and toggles the lightbulb on.
* @param msgSender The address of the sender on the L2 side.
* @param msgData The encoded data containing the lightbulb owner's address.
*/
function turnOn(address _msgSender, address lightBulbOwner) external onlyAuthenticatedFromVea(_msgSender) {
// lightBulbOwner authentication is done on the L2 switch side.
function receiveMessage(address msgSender, bytes calldata msgData) external override onlyAuthenticatedFromVea(msgSender) {
(address lightBulbOwner) = abi.decode(msgData, (address));
lightBulbIsOn[lightBulbOwner] = true;
}
}
9 changes: 4 additions & 5 deletions contracts/L2/Switch.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// SPDX-License-Identifier: MIT

/**
* @authors: [@shotaronowhere]
* @authors: [@shotaronowhere, @mani99brar]
* @reviewers: []
* @auditors: []
* @bounties: []
* @deployments: []
*/

pragma solidity ^0.8.18;
pragma solidity ^0.8.30;

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

/**
* @title Lightbulb
Expand All @@ -36,7 +35,7 @@ contract Switch{

function turnOnLightBulb() external {
bytes memory _msgData = abi.encode(msg.sender);
uint64 msgId = veaInbox.sendMessage(lightBulb, ILightBulb.turnOn.selector, _msgData);
uint64 msgId = veaInbox.sendMessage(lightBulb, _msgData);
emit lightBulbToggled(msgId, msg.sender);
}
}
17 changes: 17 additions & 0 deletions contracts/interfaces/IReceiverGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT

/// @custom:authors: [@jaybuidl, @shotaronowhere]
/// @custom:reviewers: []
/// @custom:auditors: []
/// @custom:bounties: []
/// @custom:deployments: []

pragma solidity ^0.8.24;

interface IReceiverGateway {
function veaOutbox() external view returns (address);

function senderGateway() external view returns (address);

function receiveMessage(address msgSender, bytes calldata msgData) external;
}
10 changes: 6 additions & 4 deletions deploy-helpers/getContractAddress.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const { BN, Address, toChecksumAddress } = require("ethereumjs-util");
const { getCreateAddress } = require("ethers");

/**
* Gets the address of a soon to be deployed contract.
* @param {string} deployer The address of the deployer account.
* @param {number|BN} nonce The current nonce for the deployer account.
* @param {number|bigint} nonce The current nonce for the deployer account.
* @return {string} The address of a contract if it is deployed in the next transaction sent by the deployer account.
*/
function getContractAddress(deployer, nonce) {
const deployAddress = Address.generate(Address.fromString(deployer), new BN(String(nonce)));
return toChecksumAddress(deployAddress.toString());
return getCreateAddress({
from: deployer,
nonce: nonce,
});
}

module.exports = getContractAddress;
32 changes: 0 additions & 32 deletions deploy/01-lightbulb-goerli.ts

This file was deleted.

35 changes: 35 additions & 0 deletions deploy/01-lightbulb-sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
import * as VeaOutboxArbToEthTestnet from "@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json";

const deployLightbulbSepolia: DeployFunction = async (
hre: HardhatRuntimeEnvironment
) => {
const { ethers, deployments, getNamedAccounts } = hre;
const { deploy } = deployments;

const deployer =
(await getNamedAccounts()).deployer ??
(await ethers.getSigners())[0].address;
console.log("Deploying L1 Lightbulb on Sepolia 💡");
const senderChainProvider = new ethers.JsonRpcProvider(
process.env.ARBSEPOLIA_RPC
);
let nonce = await senderChainProvider.getTransactionCount(deployer);
const lightBulbsSwitch = getContractAddress(deployer, nonce);
const lightbulb = await deploy("LightbulbSepolia", {
from: deployer,
contract: "Lightbulb",
args: [VeaOutboxArbToEthTestnet.address, lightBulbsSwitch],
log: true,
});

console.log(`deployed to ${lightbulb.address}`);
};

deployLightbulbSepolia.skip = async ({ getChainId }) => {
return Number(await getChainId()) != 11155111;
};

export default deployLightbulbSepolia;
25 changes: 15 additions & 10 deletions deploy/02-lightbulb-chiado.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../deploy-helpers/getContractAddress";
import * as veaOutboxDevnetGnosis from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisDevnet.json";
import * as VeaOutboxArbToGnosisTestnet from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json";

const deployLightbulbChiado: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments } = hre;
const deployLightbulbChiado: DeployFunction = async (
hre: HardhatRuntimeEnvironment
) => {
const { ethers, deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { providers } = ethers;

const deployer = (await hre.ethers.getSigners())[0].address;
console.log('Deploying L1 Lightbulb on Chiado 💡')
const deployer =
(await getNamedAccounts()).deployer ??
(await ethers.getSigners())[0].address;
console.log("Deploying L1 Lightbulb on Chiado 💡");

const senderChainProvider = new providers.JsonRpcProvider(process.env.ARBGOERLI_RPC);
const senderChainProvider = new ethers.JsonRpcProvider(
process.env.ARBGOERLI_RPC
);

let nonce = await senderChainProvider.getTransactionCount(deployer) + 1;
let nonce = (await senderChainProvider.getTransactionCount(deployer)) + 1;
const lightBulbsSwitch = getContractAddress(deployer, nonce);
const lightbulb = await deploy("Lightbulb", {
from: deployer,
contract: "Lightbulb",
args: [veaOutboxDevnetGnosis.address, lightBulbsSwitch],
args: [VeaOutboxArbToGnosisTestnet.address, lightBulbsSwitch],
log: true,
});

console.log(`deployed to ${lightbulb.address}`)
console.log(`deployed to ${lightbulb.address}`);
};

deployLightbulbChiado.skip = async ({ getChainId }) => {
Expand Down
30 changes: 0 additions & 30 deletions deploy/03-switch-arbitrum-goerli.ts

This file was deleted.

29 changes: 29 additions & 0 deletions deploy/03-switch-arbitrum-sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import * as VeaInboxTestnetEthereum from "@kleros/vea-contracts/deployments/arbitrumSepolia/VeaInboxArbToEthTestnet.json";

const deploySwitches: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers,deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const deployer =
(await getNamedAccounts()).deployer ??
(await ethers.getSigners())[0].address;

const LightBulbSepolia = await hre.companionNetworks.sepolia.deployments.get("LightbulbSepolia");
console.log('Deploying Arbitrum Sepolia L2 Switch 🎚️ For Sepolia Lightbulb 💡')

const switchToSepolia = await deploy("SwitchArbitrumSepoliaToSepolia", {
from: deployer,
contract: "Switch",
args: [VeaInboxTestnetEthereum.address, LightBulbSepolia.address],
log: true,
});
console.log("Switch deployed to: %s", switchToSepolia.address);
};

deploySwitches.skip = async ({ getChainId }) => {
return Number(await getChainId()) != 421614;
};
deploySwitches.runAtTheEnd = true;
deploySwitches.tags = ["switch-to-sepolia"];
export default deploySwitches;
22 changes: 14 additions & 8 deletions deploy/04-switch-arbitrum-chiado.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import * as veaInboxDevnetGnosis from "@kleros/vea-contracts/deployments/arbitrumGoerli/VeaInboxArbToEthDevnet.json";
import * as VeaInboxArbToEthTestnet from "@kleros/vea-contracts/deployments/arbitrumSepolia/VeaInboxArbToEthTestnet.json";

const deploySwitches: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, } = hre;
const deploySwitches: DeployFunction = async (
hre: HardhatRuntimeEnvironment
) => {
const { ethers, deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const deployer = (await hre.ethers.getSigners())[0].address;
const deployer =
(await getNamedAccounts()).deployer ??
(await ethers.getSigners())[0].address;

console.log('Deploying Arbitrum Goerli L2 Switch 🎚️ For Chiado Lightbulb 💡')
console.log("Deploying Arbitrum Goerli L2 Switch 🎚️ For Chiado Lightbulb 💡");

const LightBulbChiado = await hre.companionNetworks.chiado.deployments.get("Lightbulb");
const LightBulbChiado = await hre.companionNetworks.chiado.deployments.get(
"Lightbulb"
);
const switchToChiado = await deploy("SwitchArbitrumGoerliToChiado", {
from: deployer,
contract: "Switch",
args: [veaInboxDevnetGnosis.address, LightBulbChiado.address],
args: [VeaInboxArbToEthTestnet.address, LightBulbChiado.address],
log: true,
});

console.log("Switch deployed to: %s", switchToChiado.address);
};

deploySwitches.skip = async ({ getChainId }) => {
return Number(await getChainId()) != 421613;
return Number(await getChainId()) != 421614;
};
deploySwitches.runAtTheEnd = true;
deploySwitches.tags = ["switch-to-chiado"];
Expand Down
1 change: 1 addition & 0 deletions deployments/arbitrumSepolia/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
421614
Loading
Loading