Skip to content
4 changes: 3 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ds-test/=lib/forge-std/lib/ds-test/src/
ds-test/=lib/socket-protocol/lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
socket-protocol/=lib/socket-protocol/
solady/=lib/socket-protocol/lib/solady/src/
solmate/=lib/socket-protocol/lib/solmate/src/
125 changes: 125 additions & 0 deletions script/SetupScript.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.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";

interface IAppGateway {
function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address recipient) external;
}

interface IDeployer {
function deployContracts(uint32 chainId) external;
}

abstract contract SetupScript 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));

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);
IAppGateway(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(uint32[] memory chainIds) internal {
vm.createSelectFork(rpcEVMx);
vm.startBroadcast(privateKey);

for (uint256 i = 0; i < chainIds.length; i++) {
IDeployer(deployer()).deployContracts(chainIds[i]);
}

vm.stopBroadcast();
console.log("Contracts deployed");
}

// Abstract functions to be implemented by child contracts
function appGateway() internal view virtual returns (address);
function deployer() internal view virtual returns (address);

// Standard flow
// Each implementation script will call these functions
function _run(uint32 chainId) internal {
uint256 availableFees = checkDepositedFees(chainId);

if (availableFees > 0) {
executeScriptSpecificLogic();
withdrawAppFees(chainId);
} else {
console.log("NO AVAILABLE FEES - Please deposit fees before running this script");
}
}

// Abstract function to be implemented by child contracts
function executeScriptSpecificLogic() internal virtual;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common
import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol";
import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol";

contract DeployMistakes is Script {
contract DeployEVMxContracts is Script {
function run() external {
address addressResolver = vm.envAddress("ADDRESS_RESOLVER");
address auctionManager = vm.envAddress("AUCTION_MANAGER");
Expand Down
137 changes: 32 additions & 105 deletions script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from "forge-std/Script.sol";
import {console} from "forge-std/console.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";

import {SetupScript} from "../SetupScript.sol";
import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol";
import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol";
import {
Expand All @@ -20,117 +14,48 @@ import {
PlugNoInitInitialize
} from "../../src/deployment-mistakes/DeployOnchainMistakes.sol";

contract RunEVMxDeploy 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));

DeploymentMistakesDeployer deployer = DeploymentMistakesDeployer(deployerAddress);
DeploymentMistakesAppGateway appGateway = DeploymentMistakesAppGateway(appGatewayAddress);
contract RunEVMxDeploymentMistakes is SetupScript {
DeploymentMistakesDeployer mistakesDeployer;
DeploymentMistakesAppGateway mistakesAppGateway;
address noPlugNoInititializeForwarder;
address noPlugInitializeForwarder;
address plugNoInitializeForwarder;
address plugInitializeForwarder;
address plugInitializeTwiceForwarder;
address plugNoInitInitializeForwarder;

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 appGateway() internal view override returns (address) {
return address(mistakesAppGateway);
}

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(arbSepChainId);
vm.stopBroadcast();

console.log("Contracts deployed");
function deployer() internal view override returns (address) {
return address(mistakesDeployer);
}

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

noPlugNoInititializeForwarder = deployer.forwarderAddresses(deployer.noPlugNoInititialize(), arbSepChainId);
noPlugNoInititializeForwarder =
mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugNoInititialize(), arbSepChainId);
console.log("No Plug No Init Forwarder:", noPlugNoInititializeForwarder);

noPlugInitializeForwarder = deployer.forwarderAddresses(deployer.noPlugInitialize(), arbSepChainId);
noPlugInitializeForwarder =
mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugInitialize(), arbSepChainId);
console.log("No Plug Init Forwarder:", noPlugInitializeForwarder);

plugNoInitializeForwarder = deployer.forwarderAddresses(deployer.plugNoInitialize(), arbSepChainId);
plugNoInitializeForwarder =
mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitialize(), arbSepChainId);
console.log("Plug No Init Forwarder:", plugNoInitializeForwarder);

plugInitializeForwarder = deployer.forwarderAddresses(deployer.plugInitialize(), arbSepChainId);
plugInitializeForwarder = mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitialize(), arbSepChainId);
console.log("Plug Init Forwarder:", plugInitializeForwarder);

plugInitializeTwiceForwarder = deployer.forwarderAddresses(deployer.plugInitializeTwice(), arbSepChainId);
plugInitializeTwiceForwarder =
mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitializeTwice(), arbSepChainId);
console.log("Plug Init Init Forwarder:", plugInitializeTwiceForwarder);

plugNoInitInitializeForwarder = deployer.forwarderAddresses(deployer.plugNoInitInitialize(), arbSepChainId);
plugNoInitInitializeForwarder =
mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitInitialize(), arbSepChainId);
console.log("Plug No Init Init Forwarder:", plugNoInitInitializeForwarder);
}

Expand Down Expand Up @@ -180,19 +105,21 @@ contract RunEVMxDeploy is Script {
vm.stopBroadcast();
}

function run() external {
uint256 availableFees = checkDepositedFees(arbSepChainId);
function executeScriptSpecificLogic() internal override {
// Initialize contract references
mistakesDeployer = DeploymentMistakesDeployer(deployerAddress);
mistakesAppGateway = DeploymentMistakesAppGateway(appGatewayAddress);

if (availableFees > 0) {
// Set up onchain deployments
deployOnchainContracts();
getForwarderAddresses();
// Deploy only to Arbitrum Sepolia
uint32[] memory chainIds = new uint32[](1);
chainIds[0] = arbSepChainId;
deployOnchainContracts(chainIds);

validateMistakes();
getForwarderAddresses();
validateMistakes();
}

withdrawAppFees(arbSepChainId);
} else {
console.log("NO AVAILABLE FEES - Please deposit fees before running this script");
}
function run() external {
_run(arbSepChainId);
}
}
32 changes: 32 additions & 0 deletions script/inbox/DeployEVMxInbox.s.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 {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol";
import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/protocol/utils/common/Constants.sol";

import {InboxAppGateway} from "../../src/inbox/InboxAppGateway.sol";
import {InboxDeployer} from "../../src/inbox/InboxDeployer.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});

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

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

console.log("Contracts deployed:");
console.log("Deployer:", address(deployer));
console.log("AppGateway:", address(gateway));
}
}
Loading
Loading