Skip to content
Merged
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
10 changes: 5 additions & 5 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# RPCs
EVMX_RPC="https://rpc-evmx.dev.socket.tech/"
EVMX_RPC="https://rpc-evmx.dev.socket.tech"
SEPOLIA_RPC="https://rpc.ankr.com/eth_sepolia/"
ARBITRUM_SEPOLIA_RPC="https://rpc.ankr.com/arbitrum_sepolia"
OPTIMISM_SEPOLIA_RPC="https://rpc.ankr.com/optimism_sepolia"
BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia"

# EVMx key addresses
# Find the most up to date addresses in deployments/dev_addresses.json
ADDRESS_RESOLVER="0x7480D8D4B1929e751984b01eE877A9D65e1F3737"
AUCTION_MANAGER="0x50E5140d3601812Dc11f49a39CF9520567731c82"
ARBITRUM_FEES_PLUG="0xa08Dac27E27c49A2535b36064c370e6e8B3A0B9a"
FEES_MANAGER="0x80bEc58A00993dc874Ab2fAe56621af24eF06bA5"
ADDRESS_RESOLVER="0x35a72Ef57aCC20a8e1Ef39A0f903cE23175779b1"
AUCTION_MANAGER="0xA9377140B51c8c5be91e73D03e5E32DC841Cd4C0"
ARBITRUM_FEES_PLUG="0xB45CD3697Bfd0F5dA17787F0e113C2807303BEAc"
FEES_MANAGER="0x2C4B5dac446AB96A3dd92b6bd7ec48151BDd8f9C"

# Add your deployer private key here
# or remove it from this file if it is already an env var
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ evm_version = 'paris'

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[etherscan]
7625382 = { key = "empty", url = "https://evms.cloud.blockscout.com/api?" }
7625382 = { key = "empty", url = "https://evmx2.cloud.blockscout.com/api?" }
421614 = { key = "${ARBISCAN_API_KEY}", url = "https://api-sepolia.arbiscan.io/api?" }
11155420 = { key = "${OPTIMISM_API_KEY}", url = "https://optimism-sepolia.blockscout.com/api?" }
195 changes: 195 additions & 0 deletions script/robust/RunEVMxRobustness.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol";
import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol";
import {DepositFees} from "socket-protocol/script/PayFeesInArbitrumETH.s.sol";
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
import {FeesPlug} from "socket-protocol/contracts/protocol/payload-delivery/FeesPlug.sol";
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";
import {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/app-gateway/FeesManager.sol";

contract RunEVMxRobustness is Script {
// ----- ENVIRONMENT VARIABLES -----
string rpcEVMx = vm.envString("EVMX_RPC");
string rpcArbSepolia = vm.envString("ARBITRUM_SEPOLIA_RPC");
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
address auctionManager = vm.envAddress("AUCTION_MANAGER");
address feesPlugArbSepolia = vm.envAddress("ARBITRUM_FEES_PLUG");
address feesManagerAddress = vm.envAddress("FEES_MANAGER");
uint256 privateKey = vm.envUint("PRIVATE_KEY");
address deployerAddress = vm.envAddress("DEPLOYER");
address appGatewayAddress = vm.envAddress("APP_GATEWAY");

// ----- SCRIPT VARIABLES -----
uint32 arbSepChainId = 411614;
uint32 opSepChainId = 11155420;

Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});
FeesManager feesManager = FeesManager(payable(feesManagerAddress));
FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia));

RobustnessDeployer deployer = RobustnessDeployer(deployerAddress);
RobustnessAppGateway appGateway = RobustnessAppGateway(appGatewayAddress);
address opSepForwarder;
address arbSepForwarder;

function checkDepositedFees(uint32 chainId) internal returns (uint256 availableFees) {
vm.createSelectFork(rpcEVMx);

(uint256 deposited, uint256 blocked) =
feesManager.appGatewayFeeBalances(appGatewayAddress, chainId, ETH_ADDRESS);
console.log("App Gateway:", appGatewayAddress);
console.log("Deposited fees:", deposited);
console.log("Blocked fees:", blocked);

availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
console.log("Available fees:", availableFees);
}

function withdrawAppFees(uint32 chainId) internal {
// EVMX Check available fees
vm.createSelectFork(rpcEVMx);

uint256 availableFees = feesManager.getAvailableFees(chainId, appGatewayAddress, ETH_ADDRESS);
console.log("Available fees:", availableFees);

if (availableFees > 0) {
// Switch to Arbitrum Sepolia to get gas price
vm.createSelectFork(rpcArbSepolia);

// Gas price from Arbitrum
uint256 arbitrumGasPrice = block.basefee + 0.1 gwei; // With buffer
uint256 gasLimit = 5_000_000; // Estimate
uint256 estimatedGasCost = gasLimit * arbitrumGasPrice;

console.log("Arbitrum gas price (wei):", arbitrumGasPrice);
console.log("Gas limit:", gasLimit);
console.log("Estimated gas cost:", estimatedGasCost);

// Calculate amount to withdraw
uint256 amountToWithdraw = availableFees > estimatedGasCost ? availableFees - estimatedGasCost : 0;

if (amountToWithdraw > 0) {
// Switch back to EVMX to perform withdrawal
vm.createSelectFork(rpcEVMx);
vm.startBroadcast(privateKey);
address sender = vm.addr(privateKey);
console.log("Withdrawing amount:", amountToWithdraw);
appGateway.withdrawFeeTokens(chainId, ETH_ADDRESS, amountToWithdraw, sender);
vm.stopBroadcast();

// Switch back to Arbitrum Sepolia to check final balance
vm.createSelectFork(rpcArbSepolia);
console.log("Final sender balance:", sender.balance);
} else {
console.log("Available fees less than estimated gas cost");
}
}
}

function deployOnchainContracts() internal {
vm.createSelectFork(rpcEVMx);
vm.startBroadcast(privateKey);
deployer.deployContracts(opSepChainId);
deployer.deployContracts(arbSepChainId);
vm.stopBroadcast();

console.log("Contracts deployed");
}

function getForwarderAddresses() internal {
vm.createSelectFork(rpcEVMx);
opSepForwarder = deployer.forwarderAddresses(deployer.multichain(), opSepChainId);
arbSepForwarder = deployer.forwarderAddresses(deployer.multichain(), arbSepChainId);

console.log("Optimism Sepolia Forwarder:", opSepForwarder);
console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder);
}

function runAllTriggers() internal {
vm.createSelectFork(rpcEVMx);
vm.startBroadcast(privateKey);

console.log("Running all trigger functions...");

// 1. Trigger Sequential Write
console.log("triggerSequentialWrite...");
appGateway.triggerSequentialWrite(opSepForwarder);

// 2. Trigger Parallel Write
console.log("triggerParallelWrite...");
appGateway.triggerParallelWrite(arbSepForwarder);

// 3. Trigger Alternating Write between chains
console.log("triggerAltWrite...");
appGateway.triggerAltWrite(opSepForwarder, arbSepForwarder);

// 4. Trigger Parallel Read
console.log("triggerParallelRead...");
appGateway.triggerParallelRead(opSepForwarder);

// 5. Trigger Alternating Read between chains
console.log("triggerAltRead...");
appGateway.triggerAltRead(opSepForwarder, arbSepForwarder);

// 6. Trigger Read and Write
console.log("triggerReadAndWrite...");
appGateway.triggerReadAndWrite(arbSepForwarder);

// 7. Trigger Timeouts
console.log("triggerTimeouts...");
appGateway.triggerTimeouts();

vm.stopBroadcast();
console.log("All triggers executed successfully");
}

function checkResults() internal {
vm.createSelectFork(rpcEVMx);

console.log("\n----- RESULTS -----");

// Check values array
console.log("Values array:");
for (uint256 i = 0; i < 10; i++) {
try appGateway.values(i) returns (uint256 value) {
console.log("values[%s]: %s", i, value);
} catch {
console.log("values[%s]: not set", i);
break;
}
}

// Check resolve times for timeouts
console.log("\nTimeout resolve times:");
for (uint256 i = 0; i < 10; i++) {
uint256 resolveTime = appGateway.resolveTimes(i);
uint256 duration = appGateway.timeoutDurations(i);
if (resolveTime > 0) {
console.log("Timeout %s (duration %s): resolved at timestamp %s", i, duration, resolveTime);
} else {
console.log("Timeout %s (duration %s): not yet resolved", i, duration);
}
}
}

function run() external {
uint256 availableFees = checkDepositedFees(arbSepChainId);

if (availableFees > 0) {
// Set up onchain deployments
deployOnchainContracts();
getForwarderAddresses();

runAllTriggers();
checkResults(); // TODO: Check if we need to wait before checking the results

withdrawAppFees(arbSepChainId);
} else {
console.log("NO AVAILABLE FEES - Please deposit fees before running this script");
}
}
}
32 changes: 32 additions & 0 deletions script/robust/deployEVMx.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.sol";
import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol";
import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol";
import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";

contract DeployEVMxContracts is Script {
function run() external {
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
address auctionManager = vm.envAddress("AUCTION_MANAGER");
string memory rpc = vm.envString("EVMX_RPC");
vm.createSelectFork(rpc);

uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.001 ether});

RobustnessDeployer deployer = new RobustnessDeployer(addressResolver, auctionManager, FAST, fees);

RobustnessAppGateway gateway =
new RobustnessAppGateway(addressResolver, address(deployer), auctionManager, fees);

console.log("Contracts deployed:");
console.log("Deployer:", address(deployer));
console.log("AppGateway:", address(gateway));
}
}
20 changes: 0 additions & 20 deletions src/apps/counter/Counter.sol

This file was deleted.

30 changes: 0 additions & 30 deletions src/apps/counter/CounterAppGateway.sol

This file was deleted.

20 changes: 20 additions & 0 deletions src/robustness/IRobustnessMultichain.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

interface IRobustnessMultichain {
function counter() external;

function values() external;

function increase() external;

function setValues(uint256[] memory values_) external;

function getValue(uint256 index_) external;

function connectSocket(
address appGateway_,
address socket_,
address switchboard_
) external;
}
Loading
Loading