diff --git a/.env.sample b/.env.sample index a5db2d9..64b474a 100644 --- a/.env.sample +++ b/.env.sample @@ -6,10 +6,10 @@ 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="0xc4AC8186Dac133Cf132bb9FC7e2675e482670047" -AUCTION_MANAGER="0x6e156147B6fe75310D001d0eb0598173FBFB98E4" -FEES_MANAGER="0x9C92cC886Fe92f7700d045580d85A4D2BF3Ebf01" +# Find the most up to date addresses at: +# https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json +ADDRESS_RESOLVER="0xf3046B22F98C25305E8040286fB1b33378BA10a1" +FEES_MANAGER="0x603723100172D30171B7Fd9870ba80F8baf6FaD4" ARBITRUM_FEES_PLUG="0x89324F93d852cB4fcDC4Ee202456be466ce096bb" # Add your deployer private key here @@ -18,7 +18,3 @@ PRIVATE_KEY="0x" # Set app related values after deployment on EVMx APP_GATEWAY="0x" - -# FOR INFRASTRUCTURE DEPLOYMENT ONLY -# Removes hardhat issues related to linting and syntax checking -SOCKET_SIGNER_KEY="0000dead0000dead0000dead0000dead0000dead0000dead0000dead0000dead" diff --git a/.gitmodules b/.gitmodules index 38f7d81..5847cbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,5 +3,5 @@ url = https://github.com/foundry-rs/forge-std [submodule "lib/socket-protocol"] path = lib/socket-protocol - url = https://github.com/SocketDotTech/socket-protocol + url = https://github.com/SocketDotTech/socket-protocol.git branch = staging diff --git a/README.md b/README.md index 9a149af..460aef7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,85 @@ -This repository is to get you started with development on SOCKET protocol. -Follow the accompanying [guide](https://docs.socket.tech/getting-started). +# Deployment Steps for EVMx Read Tests + +Follow these steps to deploy and run the EVMx Read tests. + +### 1. **Deploy the EVMx Read Tests Script** +Run the following command to deploy the EVMx Read tests script: +```bash +forge script script/read/DeployEVMxReadTests.sol --broadcast --legacy --with-gas-price 0 +``` + +### 1a. **Verify the EVMx Contract** +Verify the `ReadAppGateway` contract on Blockscout: +```bash +forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/read/ReadAppGateway.sol:ReadAppGateway +``` + +### 2. **Update the `APP_GATEWAY` in `.env`** +Make sure to update the `APP_GATEWAY` address in your `.env` file. + +### 3. **Pay Fees in Arbitrum ETH** +Run the script to pay fees in Arbitrum ETH: +```bash +forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +``` + +### 4. **Deploy Onchain Contracts** +Deploy the onchain contracts using the following script: +```bash +forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" +``` + +### 4a. **Verify the Onchain Contract** +Verify the `ReadMultichain` contract on Arbitrum Sepolia Blockscout: +```bash +forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/read/ReadMultichain.sol:ReadMultichain +``` + +### 5. **Run EVMx Read Script** +Finally, run the EVMx Read script: +```bash +forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy +``` + +# Deployment Steps for EVMx Write Tests + +Follow these steps to deploy and run the EVMx Write tests. + +### 1. **Deploy the EVMx Write Tests Script** +Run the following command to deploy the EVMx Write tests script: +```bash +forge script script/write/DeployEVMxWriteTests.sol --broadcast --legacy --with-gas-price 0 +``` + +### 1a. **Verify the Contract** +Verify the `WriteAppGateway` contract on Blockscout: +```bash +forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/write/WriteAppGateway.sol:WriteAppGateway +``` + +### 2. **Update the `APP_GATEWAY` in `.env`** +Make sure to update the `APP_GATEWAY` address in your `.env` file. + +### 3. **Pay Fees in Arbitrum ETH** +Run the script to pay fees in Arbitrum ETH: +```bash +forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +``` + +### 4. **Deploy Onchain Contracts** +Deploy the onchain contracts using the following script: +```bash +forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" +``` + +### 4a. **Verify the Contract** +Verify the `WriteMultichain` contract on Arbitrum Sepolia Blockscout: +```bash +forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/write/WriteMultichain.sol:WriteMultichain +``` + +### 5. **Run EVMx Write Script** +Finally, run the EVMx Write script: +```bash +forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy +``` diff --git a/lib/socket-protocol b/lib/socket-protocol index 4f163cd..f80efc9 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit 4f163cd0c10d2b09b4c49d5956aea8c01687f42a +Subproject commit f80efc9db00288d91a83c33e761d02f522303f37 diff --git a/remappings.txt b/remappings.txt index 9b23047..4c31fa1 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,5 +1,3 @@ -ds-test/=lib/socket-protocol/lib/forge-std/lib/ds-test/src/ -forge-std/=lib/forge-std/src/ +forge-std/=lib/socket-protocol/lib/forge-std/src/ socket-protocol/=lib/socket-protocol/ solady/=lib/socket-protocol/lib/solady/src/ -solmate/=lib/socket-protocol/lib/solmate/src/ diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 192fc36..656705e 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -3,18 +3,15 @@ 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 {DepositFees} from "socket-protocol/script/helpers/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 {FeesManager} from "socket-protocol/contracts/protocol/payload-delivery/FeesManager.sol"; interface IAppGateway { - function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address recipient) external; -} - -interface IDeployer { function deployContracts(uint32 chainId) external; + function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address recipient) external; } abstract contract SetupScript is Script { @@ -22,16 +19,15 @@ abstract contract SetupScript is Script { 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 arbSepChainId = 421614; uint32 opSepChainId = 11155420; + uint32[2] chainIds = [opSepChainId, arbSepChainId]; Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); FeesManager feesManager = FeesManager(payable(feesManagerAddress)); @@ -91,12 +87,12 @@ abstract contract SetupScript is Script { } } - function deployOnchainContracts(uint32[] memory chainIds) internal { + function _deployOnchainContracts() internal { vm.createSelectFork(rpcEVMx); vm.startBroadcast(privateKey); for (uint256 i = 0; i < chainIds.length; i++) { - IDeployer(deployer()).deployContracts(chainIds[i]); + IAppGateway(appGateway()).deployContracts(chainIds[i]); } vm.stopBroadcast(); @@ -105,7 +101,6 @@ abstract contract SetupScript is Script { // 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 diff --git a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol index d7cba33..309abed 100644 --- a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol +++ b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol @@ -4,45 +4,25 @@ 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 {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; -import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.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}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - DeploymentMistakesDeployer deployer = - new DeploymentMistakesDeployer(addressResolver, auctionManager, FAST, fees); - - DeploymentMistakesAppGateway gateway = - new DeploymentMistakesAppGateway(addressResolver, address(deployer), auctionManager, fees); + DeploymentMistakesAppGateway appGateway = new DeploymentMistakesAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("DeploymentMistakesDeployer:", address(deployer)); - console.log("DeploymentMistakesAppGateway:", address(gateway)); - - console.log("DeploymentMistakesDeployer contract ids:"); - console.log("noPlugNoInititialize"); - console.logBytes32(deployer.noPlugNoInititialize()); - console.log("noPlugInitialize"); - console.logBytes32(deployer.noPlugInitialize()); - console.log("plugNoInitialize"); - console.logBytes32(deployer.plugNoInitialize()); - console.log("plugInitialize"); - console.logBytes32(deployer.plugInitialize()); - console.log("plugInitializeTwice"); - console.logBytes32(deployer.plugInitializeTwice()); - console.log("plugNoInitInitialize"); - console.logBytes32(deployer.plugNoInitInitialize()); + console.log("DeploymentMistakesAppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } diff --git a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol index 7e9d680..12e8584 100644 --- a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol +++ b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; -import {DeploymentMistakesDeployer} from "../../src/deployment-mistakes/DeploymentMistakesDeployer.sol"; import { NoPlugNoInititialize, NoPlugInitialize, @@ -15,7 +14,6 @@ import { } from "../../src/deployment-mistakes/DeployOnchainMistakes.sol"; contract RunEVMxDeploymentMistakes is SetupScript { - DeploymentMistakesDeployer mistakesDeployer; DeploymentMistakesAppGateway mistakesAppGateway; address noPlugNoInititializeForwarder; address noPlugInitializeForwarder; @@ -28,34 +26,31 @@ contract RunEVMxDeploymentMistakes is SetupScript { return address(mistakesAppGateway); } - function deployer() internal view override returns (address) { - return address(mistakesDeployer); - } - function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); noPlugNoInititializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugNoInititialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.noPlugNoInititialize(), arbSepChainId); console.log("No Plug No Init Forwarder:", noPlugNoInititializeForwarder); noPlugInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.noPlugInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.noPlugInitialize(), arbSepChainId); console.log("No Plug Init Forwarder:", noPlugInitializeForwarder); plugNoInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugNoInitialize(), arbSepChainId); console.log("Plug No Init Forwarder:", plugNoInitializeForwarder); - plugInitializeForwarder = mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitialize(), arbSepChainId); + plugInitializeForwarder = + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugInitialize(), arbSepChainId); console.log("Plug Init Forwarder:", plugInitializeForwarder); plugInitializeTwiceForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugInitializeTwice(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugInitializeTwice(), arbSepChainId); console.log("Plug Init Init Forwarder:", plugInitializeTwiceForwarder); plugNoInitInitializeForwarder = - mistakesDeployer.forwarderAddresses(mistakesDeployer.plugNoInitInitialize(), arbSepChainId); + mistakesAppGateway.forwarderAddresses(mistakesAppGateway.plugNoInitInitialize(), arbSepChainId); console.log("Plug No Init Init Forwarder:", plugNoInitInitializeForwarder); } @@ -105,16 +100,13 @@ contract RunEVMxDeploymentMistakes is SetupScript { vm.stopBroadcast(); } - function executeScriptSpecificLogic() internal override { - // Initialize contract references - mistakesDeployer = DeploymentMistakesDeployer(deployerAddress); + // Initialize contract references + function init() internal { mistakesAppGateway = DeploymentMistakesAppGateway(appGatewayAddress); + } - // Deploy only to Arbitrum Sepolia - uint32[] memory chainIds = new uint32[](1); - chainIds[0] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); validateMistakes(); } @@ -122,4 +114,9 @@ contract RunEVMxDeploymentMistakes is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } diff --git a/script/inbox/DeployEVMxInbox.s.sol b/script/inbox/DeployEVMxInbox.s.sol index 68da615..88c7a4b 100644 --- a/script/inbox/DeployEVMxInbox.s.sol +++ b/script/inbox/DeployEVMxInbox.s.sol @@ -4,29 +4,25 @@ 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 {ETH_ADDRESS} 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}); + Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - InboxDeployer deployer = new InboxDeployer(addressResolver, auctionManager, FAST, fees); - - InboxAppGateway gateway = new InboxAppGateway(addressResolver, address(deployer), auctionManager, fees); + InboxAppGateway appGateway = new InboxAppGateway(addressResolver, fees); console.log("Contracts deployed:"); - console.log("Deployer:", address(deployer)); - console.log("AppGateway:", address(gateway)); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); } } diff --git a/script/inbox/RunEVMxInbox.s.sol b/script/inbox/RunEVMxInbox.s.sol index 8535c55..c86c94a 100644 --- a/script/inbox/RunEVMxInbox.s.sol +++ b/script/inbox/RunEVMxInbox.s.sol @@ -3,11 +3,9 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; -import {InboxDeployer} from "../../src/inbox/InboxDeployer.sol"; import {InboxAppGateway, IInbox} from "../../src/inbox/InboxAppGateway.sol"; contract RunEVMxInbox is SetupScript { - InboxDeployer inboxDeployer; InboxAppGateway inboxAppGateway; address opSepForwarder; address arbSepForwarder; @@ -16,22 +14,18 @@ contract RunEVMxInbox is SetupScript { return address(inboxAppGateway); } - function deployer() internal view override returns (address) { - return address(inboxDeployer); - } - function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); - opSepForwarder = inboxDeployer.forwarderAddresses(inboxDeployer.inbox(), opSepChainId); - arbSepForwarder = inboxDeployer.forwarderAddresses(inboxDeployer.inbox(), arbSepChainId); + opSepForwarder = inboxAppGateway.forwarderAddresses(inboxAppGateway.inbox(), opSepChainId); + arbSepForwarder = inboxAppGateway.forwarderAddresses(inboxAppGateway.inbox(), arbSepChainId); console.log("Optimism Sepolia Forwarder:", opSepForwarder); console.log("Arbitrum Sepolia Forwarder:", arbSepForwarder); } function inboxTransactions() internal { - address opSepInboxAddress = inboxDeployer.getOnChainAddress(inboxDeployer.inbox(), opSepChainId); - address arbSepInboxAddress = inboxDeployer.getOnChainAddress(inboxDeployer.inbox(), arbSepChainId); + address opSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), opSepChainId); + address arbSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), arbSepChainId); vm.createSelectFork(rpcEVMx); vm.startBroadcast(privateKey); @@ -47,17 +41,13 @@ contract RunEVMxInbox is SetupScript { console.log("All inbox transactions executed successfully"); } - function executeScriptSpecificLogic() internal override { - // Initialize contract references - inboxDeployer = InboxDeployer(deployerAddress); + // Initialize contract references + function init() internal { inboxAppGateway = InboxAppGateway(appGatewayAddress); + } - // Deploy to both test chains - uint32[] memory chainIds = new uint32[](2); - chainIds[0] = opSepChainId; - chainIds[1] = arbSepChainId; - deployOnchainContracts(chainIds); - + function executeScriptSpecificLogic() internal override { + init(); getForwarderAddresses(); inboxTransactions(); } @@ -65,4 +55,9 @@ contract RunEVMxInbox is SetupScript { function run() external { _run(arbSepChainId); } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } } diff --git a/script/read/DeployEVMxReadTests.sol b/script/read/DeployEVMxReadTests.sol new file mode 100644 index 0000000..763c6be --- /dev/null +++ b/script/read/DeployEVMxReadTests.sol @@ -0,0 +1,28 @@ +// 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} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; + +import {ReadAppGateway} from "../../src/read/ReadAppGateway.sol"; + +contract DeployEVMxContracts is Script { + function run() external { + address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); + 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.0005 ether}); + + ReadAppGateway appGateway = new ReadAppGateway(addressResolver, fees); + + console.log("Contracts deployed:"); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); + } +} diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol new file mode 100644 index 0000000..b5aa387 --- /dev/null +++ b/script/read/RunEVMxRead.s.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {console} from "forge-std/console.sol"; +import {SetupScript} from "../SetupScript.sol"; +import {ReadAppGateway} from "../../src/read/ReadAppGateway.sol"; + +contract RunEVMxRead is SetupScript { + ReadAppGateway readAppGateway; + address opSepForwarder; + address arbSepForwarder; + + function appGateway() internal view override returns (address) { + return address(readAppGateway); + } + + function getForwarderAddresses() internal { + vm.createSelectFork(rpcEVMx); + opSepForwarder = readAppGateway.forwarderAddresses(readAppGateway.multichain(), opSepChainId); + arbSepForwarder = readAppGateway.forwarderAddresses(readAppGateway.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 Parallel Read + console.log("triggerParallelRead..."); + readAppGateway.triggerParallelRead(opSepForwarder); + checkResults(); + + // 2. Trigger Alternating Read between chains + console.log("triggerAltRead..."); + readAppGateway.triggerAltRead(opSepForwarder, arbSepForwarder); + checkResults(); + vm.stopBroadcast(); + console.log("All triggers executed successfully"); + } + + function checkResults() internal view { + console.log("\n----- RESULTS -----"); + // TODO: monitor events as Foundry reads are not reliable + + // Check values array + console.log("Values array:"); + for (uint256 i = 0; i < 10; i++) { + try readAppGateway.values(i) returns (uint256 value) { + console.log("values[%s]: %s", i, value); + } catch { + console.log("values[%s]: not set", i); + break; + } + } + } + + // Initialize contract references + function init() internal { + readAppGateway = ReadAppGateway(appGatewayAddress); + } + + function executeScriptSpecificLogic() internal override { + init(); + getForwarderAddresses(); + runAllTriggers(); + } + + function run() external { + _run(arbSepChainId); + } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } +} diff --git a/script/robust/DeployEVMxRobustnessTests.sol b/script/robust/DeployEVMxRobustnessTests.sol deleted file mode 100644 index 4e57518..0000000 --- a/script/robust/DeployEVMxRobustnessTests.sol +++ /dev/null @@ -1,33 +0,0 @@ -// 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 {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol"; -import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.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)); - } -} diff --git a/script/robust/RunEVMxRobustness.s.sol b/script/robust/RunEVMxRobustness.s.sol deleted file mode 100644 index e819cb7..0000000 --- a/script/robust/RunEVMxRobustness.s.sol +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {console} from "forge-std/console.sol"; -import {SetupScript} from "../SetupScript.sol"; -import {RobustnessDeployer} from "../../src/robustness/RobustnessDeployer.sol"; -import {RobustnessAppGateway} from "../../src/robustness/RobustnessAppGateway.sol"; - -contract RunEVMxRobustness is SetupScript { - RobustnessDeployer robustnessDeployer; - RobustnessAppGateway robustnessAppGateway; - address opSepForwarder; - address arbSepForwarder; - - function appGateway() internal view override returns (address) { - return address(robustnessAppGateway); - } - - function deployer() internal view override returns (address) { - return address(robustnessDeployer); - } - - function getForwarderAddresses() internal { - vm.createSelectFork(rpcEVMx); - opSepForwarder = robustnessDeployer.forwarderAddresses(robustnessDeployer.multichain(), opSepChainId); - arbSepForwarder = robustnessDeployer.forwarderAddresses(robustnessDeployer.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..."); - robustnessAppGateway.triggerSequentialWrite(opSepForwarder); - - // 2. Trigger Parallel Write - console.log("triggerParallelWrite..."); - robustnessAppGateway.triggerParallelWrite(arbSepForwarder); - - // 3. Trigger Alternating Write between chains - console.log("triggerAltWrite..."); - robustnessAppGateway.triggerAltWrite(opSepForwarder, arbSepForwarder); - - // 4. Trigger Parallel Read - console.log("triggerParallelRead..."); - robustnessAppGateway.triggerParallelRead(opSepForwarder); - - // 5. Trigger Alternating Read between chains - console.log("triggerAltRead..."); - robustnessAppGateway.triggerAltRead(opSepForwarder, arbSepForwarder); - - // 6. Trigger Read and Write - console.log("triggerReadAndWrite..."); - robustnessAppGateway.triggerReadAndWrite(arbSepForwarder); - - // 7. Trigger Timeouts - console.log("triggerTimeouts..."); - robustnessAppGateway.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 robustnessAppGateway.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 = robustnessAppGateway.resolveTimes(i); - uint256 duration = robustnessAppGateway.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 executeScriptSpecificLogic() internal override { - // Initialize contract references - robustnessDeployer = RobustnessDeployer(deployerAddress); - robustnessAppGateway = RobustnessAppGateway(appGatewayAddress); - - // Deploy to both test chains - uint32[] memory chainIds = new uint32[](2); - chainIds[0] = opSepChainId; - chainIds[1] = arbSepChainId; - deployOnchainContracts(chainIds); - - getForwarderAddresses(); - runAllTriggers(); - checkResults(); - } - - function run() external { - _run(arbSepChainId); - } -} diff --git a/script/update-socket-protocol-commit.sh b/script/update-socket-protocol-commit.sh index ee25f6a..e8b21b9 100644 --- a/script/update-socket-protocol-commit.sh +++ b/script/update-socket-protocol-commit.sh @@ -1,8 +1,8 @@ #!/bin/bash -# Check if there are modified or staged files -if [[ -n $(git status --porcelain) ]]; then - echo "Error: You have uncommitted changes. Commit or stash them before running this script." +# Check for modified or staged files, but ignore untracked files +if [[ -n $(git status --porcelain | grep '^[ MRAUCD]') ]]; then + echo "Error: You have modified or staged files. Commit or stash them before running this script." exit 1 fi diff --git a/script/write/DeployEVMxWriteTests.sol b/script/write/DeployEVMxWriteTests.sol new file mode 100644 index 0000000..44f65fe --- /dev/null +++ b/script/write/DeployEVMxWriteTests.sol @@ -0,0 +1,28 @@ +// 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} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; + +import {WriteAppGateway} from "../../src/write/WriteAppGateway.sol"; + +contract DeployEVMxContracts is Script { + function run() external { + address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); + 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.0005 ether}); + + WriteAppGateway appGateway = new WriteAppGateway(addressResolver, fees); + + console.log("Contracts deployed:"); + console.log("AppGateway:", address(appGateway)); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); + } +} diff --git a/script/write/RunEVMxWrite.s.sol b/script/write/RunEVMxWrite.s.sol new file mode 100644 index 0000000..5bc82fd --- /dev/null +++ b/script/write/RunEVMxWrite.s.sol @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {console} from "forge-std/console.sol"; +import {SetupScript} from "../SetupScript.sol"; +import {WriteAppGateway} from "../../src/write/WriteAppGateway.sol"; + +contract RunEVMxWrite is SetupScript { + WriteAppGateway writeAppGateway; + address opSepForwarder; + address arbSepForwarder; + + function appGateway() internal view override returns (address) { + return address(writeAppGateway); + } + + function getForwarderAddresses() internal { + vm.createSelectFork(rpcEVMx); + opSepForwarder = writeAppGateway.forwarderAddresses(writeAppGateway.multichain(), opSepChainId); + arbSepForwarder = writeAppGateway.forwarderAddresses(writeAppGateway.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..."); + writeAppGateway.triggerSequentialWrite(opSepForwarder); + + // 2. Trigger Parallel Write + console.log("triggerParallelWrite..."); + writeAppGateway.triggerParallelWrite(arbSepForwarder); + + // 3. Trigger Alternating Write between chains + console.log("triggerAltWrite..."); + writeAppGateway.triggerAltWrite(opSepForwarder, arbSepForwarder); + + vm.stopBroadcast(); + console.log("All triggers executed successfully"); + } + + function checkResults() internal { + vm.createSelectFork(rpcEVMx); + console.log("\n----- RESULTS -----"); + // TODO: Add check for Counter value and/or onchain event + } + + // Initialize contract references + function init() internal { + writeAppGateway = WriteAppGateway(appGatewayAddress); + } + + function executeScriptSpecificLogic() internal override { + init(); + getForwarderAddresses(); + runAllTriggers(); + checkResults(); + } + + function run() external { + _run(arbSepChainId); + } + + function deployOnchainContracts() external { + init(); + _deployOnchainContracts(); + } +} diff --git a/src/deployment-mistakes/DeploymentMistakesAppGateway.sol b/src/deployment-mistakes/DeploymentMistakesAppGateway.sol index 98b1b47..fa350dc 100644 --- a/src/deployment-mistakes/DeploymentMistakesAppGateway.sol +++ b/src/deployment-mistakes/DeploymentMistakesAppGateway.sol @@ -5,13 +5,44 @@ import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./DeployOnchainMistakes.sol"; contract DeploymentMistakesAppGateway is AppGatewayBase { - constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) - AppGatewayBase(addressResolver_, auctionManager_) - { - addressResolver__.setContractsToGateways(deployerContract_); + bytes32 public noPlugNoInititialize = _createContractId("noPlugNoInititialize"); + bytes32 public noPlugInitialize = _createContractId("noPlugInitialize"); + bytes32 public plugNoInitialize = _createContractId("plugNoInitialize"); + bytes32 public plugInitialize = _createContractId("plugInitialize"); + bytes32 public plugInitializeTwice = _createContractId("plugInitializeTwice"); + bytes32 public plugNoInitInitialize = _createContractId("plugNoInitInitialize"); + + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked(type(NoPlugNoInititialize).creationCode); + creationCodeWithArgs[noPlugInitialize] = abi.encodePacked(type(NoPlugInitialize).creationCode); + creationCodeWithArgs[plugNoInitialize] = abi.encodePacked(type(PlugNoInitialize).creationCode); + creationCodeWithArgs[plugInitialize] = abi.encodePacked(type(PlugInitialize).creationCode); + creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked(type(PlugInitializeTwice).creationCode); + creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked(type(PlugNoInitInitialize).creationCode); _setOverrides(fees_); } + function deployContracts(uint32 chainSlug_) external async { + _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); + _deploy( + noPlugInitialize, chainSlug_, IsPlug.NO, abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) + ); + _deploy(plugNoInitialize, chainSlug_, IsPlug.YES); + _deploy(plugInitialize, chainSlug_, IsPlug.YES, abi.encodeWithSelector(PlugInitialize.initialise.selector, 10)); + _deploy( + plugInitializeTwice, + chainSlug_, + IsPlug.YES, + abi.encodeWithSelector(PlugInitializeTwice.initialise.selector, 10) + ); + _deploy(plugNoInitInitialize, chainSlug_, IsPlug.YES); + } + + function initialize(uint32 chainSlug_) public override async { + PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); + PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); + } + function setFees(Fees memory fees_) public { fees = fees_; } diff --git a/src/deployment-mistakes/DeploymentMistakesDeployer.sol b/src/deployment-mistakes/DeploymentMistakesDeployer.sol deleted file mode 100644 index 5476d75..0000000 --- a/src/deployment-mistakes/DeploymentMistakesDeployer.sol +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "./DeployOnchainMistakes.sol"; -import "socket-protocol/contracts/base/AppDeployerBase.sol"; - -contract DeploymentMistakesDeployer is AppDeployerBase { - bytes32 public noPlugNoInititialize = - _createContractId("noPlugNoInititialize"); - bytes32 public noPlugInitialize = _createContractId("noPlugInitialize"); - bytes32 public plugNoInitialize = _createContractId("plugNoInitialize"); - bytes32 public plugInitialize = _createContractId("plugInitialize"); - bytes32 public plugInitializeTwice = - _createContractId("plugInitializeTwice"); - bytes32 public plugNoInitInitialize = - _createContractId("plugNoInitInitialize"); - - constructor( - address addressResolver_, - address auctionManager_, - bytes32 sbType_, - Fees memory fees_ - ) AppDeployerBase(addressResolver_, auctionManager_, sbType_) { - creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked( - type(NoPlugNoInititialize).creationCode - ); - creationCodeWithArgs[noPlugInitialize] = abi.encodePacked( - type(NoPlugInitialize).creationCode - ); - creationCodeWithArgs[plugNoInitialize] = abi.encodePacked( - type(PlugNoInitialize).creationCode - ); - creationCodeWithArgs[plugInitialize] = abi.encodePacked( - type(PlugInitialize).creationCode - ); - creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked( - type(PlugInitializeTwice).creationCode - ); - creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked( - type(PlugNoInitInitialize).creationCode - ); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); - _deploy( - noPlugInitialize, - chainSlug_, - IsPlug.NO, - abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) - ); - _deploy(plugNoInitialize, chainSlug_, IsPlug.YES); - _deploy( - plugInitialize, - chainSlug_, - IsPlug.YES, - abi.encodeWithSelector(PlugInitialize.initialise.selector, 10) - ); - _deploy( - plugInitializeTwice, - chainSlug_, - IsPlug.YES, - abi.encodeWithSelector(PlugInitializeTwice.initialise.selector, 10) - ); - _deploy(plugNoInitInitialize, chainSlug_, IsPlug.YES); - } - - function initialize(uint32 chainSlug_) public override async { - PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]) - .initialise(10); - PlugNoInitInitialize( - forwarderAddresses[plugNoInitInitialize][chainSlug_] - ).initialise(10); - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} diff --git a/src/inbox/Inbox.sol b/src/inbox/Inbox.sol index 0daf05a..47da32d 100644 --- a/src/inbox/Inbox.sol +++ b/src/inbox/Inbox.sol @@ -12,17 +12,11 @@ contract Inbox is Ownable, PlugBase { uint32 public constant PROPAGATE_TO_ANOTHER = 2; function increaseOnGateway(uint256 value_) external returns (bytes32) { - return _callAppGateway( - abi.encode(INCREASE_ON_GATEWAY, abi.encode(value_)), - bytes32(0) - ); + return _callAppGateway(abi.encode(INCREASE_ON_GATEWAY, abi.encode(value_)), bytes32(0)); } function propagateToAnother(uint32 targetChain) external returns (bytes32) { - return _callAppGateway( - abi.encode(PROPAGATE_TO_ANOTHER, abi.encode(value, targetChain)), - bytes32(0) - ); + return _callAppGateway(abi.encode(PROPAGATE_TO_ANOTHER, abi.encode(value, targetChain)), bytes32(0)); } function updateFromGateway(uint256 value_) external onlySocket { diff --git a/src/inbox/InboxAppGateway.sol b/src/inbox/InboxAppGateway.sol index 55e3caa..62c5627 100644 --- a/src/inbox/InboxAppGateway.sol +++ b/src/inbox/InboxAppGateway.sol @@ -1,14 +1,16 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; + import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "./Inbox.sol"; interface IInboxDeployer { function inbox() external pure returns (bytes32 bytecode); - function forwarderAddresses( - bytes32 contractId_, - uint32 chainSlug_ - ) external view returns (address forwarderAddress); + function forwarderAddresses(bytes32 contractId_, uint32 chainSlug_) + external + view + returns (address forwarderAddress); } interface IInbox { @@ -19,6 +21,7 @@ interface IInbox { } contract InboxAppGateway is AppGatewayBase { + bytes32 public inbox = _createContractId("inbox"); uint256 public valueOnGateway; address deployerAddress; @@ -26,35 +29,34 @@ contract InboxAppGateway is AppGatewayBase { uint32 public constant INCREASE_ON_GATEWAY = 1; uint32 public constant PROPAGATE_TO_ANOTHER = 2; - constructor( - address addressResolver_, - address deployerContract_, - address auctionManager_, - Fees memory fees_ - ) AppGatewayBase(addressResolver_, auctionManager_) { - addressResolver__.setContractsToGateways(deployerContract_); - deployerAddress = deployerContract_; + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[inbox] = abi.encodePacked(type(Inbox).creationCode); _setOverrides(fees_); } + function deployContracts(uint32 chainSlug_) external async { + _deploy(inbox, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + function updateOnchain(uint32 targetChain) public { - address inboxForwarderAddress = IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + address inboxForwarderAddress = + IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); IInbox(inboxForwarderAddress).updateFromGateway(valueOnGateway); } - function callFromInbox( - uint32, - address, - bytes calldata payload_, - bytes32 - ) external override onlyWatcherPrecompile { + function callFromChain(uint32, address, bytes calldata payload_, bytes32) external override onlyWatcherPrecompile { (uint32 msgType, bytes memory payload) = abi.decode(payload_, (uint32, bytes)); if (msgType == INCREASE_ON_GATEWAY) { uint256 valueOnchain = abi.decode(payload, (uint256)); valueOnGateway += valueOnchain; } else if (msgType == PROPAGATE_TO_ANOTHER) { (uint256 valueOnchain, uint32 targetChain) = abi.decode(payload, (uint256, uint32)); - address inboxForwarderAddress = IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + address inboxForwarderAddress = + IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); IInbox(inboxForwarderAddress).updateFromGateway(valueOnchain); } else { revert("InboxGateway: invalid message type"); diff --git a/src/inbox/InboxDeployer.sol b/src/inbox/InboxDeployer.sol deleted file mode 100644 index f1dca30..0000000 --- a/src/inbox/InboxDeployer.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.0; - -import "socket-protocol/contracts/base/AppDeployerBase.sol"; -import "./Inbox.sol"; - -contract InboxDeployer is AppDeployerBase { - bytes32 public inbox = _createContractId("inbox"); - - constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) - AppDeployerBase(addressResolver_, auctionManager_, sbType_) - { - creationCodeWithArgs[inbox] = abi.encodePacked(type(Inbox).creationCode); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(inbox, chainSlug_, IsPlug.YES); - } - - function initialize(uint32) public pure override { - return; - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} diff --git a/src/read/IReadMultichain.sol b/src/read/IReadMultichain.sol new file mode 100644 index 0000000..93c966d --- /dev/null +++ b/src/read/IReadMultichain.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +interface IReadMultichain { + function values(uint256) external; + + function increase() external; + + function connectSocket(address appGateway_, address socket_, address switchboard_) external; +} diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol new file mode 100644 index 0000000..759cb81 --- /dev/null +++ b/src/read/ReadAppGateway.sol @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/interfaces/IForwarder.sol"; +import "socket-protocol/contracts/interfaces/IPromise.sol"; +import "./IReadMultichain.sol"; +import "./ReadMultichain.sol"; + +contract ReadAppGateway is AppGatewayBase { + bytes32 public multichain = _createContractId("ReadMultichain"); + uint256[] public values; + + error OutOfBounds(); + + event ValueRead(address instance, uint256 index, uint256 value); + + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); + _setOverrides(fees_); + values = new uint256[](10); + } + + function deployContracts(uint32 chainSlug_) external async { + _deploy(multichain, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + + function triggerParallelRead(address instance_) public async { + _setOverrides(Read.ON, Parallel.ON); + for (uint256 i = 0; i < 10; i++) { + IReadMultichain(instance_).values(i); + IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); + } + } + + function triggerAltRead(address instance1_, address instance2_) public async { + _setOverrides(Read.ON, Parallel.ON); + for (uint256 i = 0; i < 10; i++) { + if (i % 2 == 0) { + IReadMultichain(instance1_).values(i); + IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); + } else { + IReadMultichain(instance2_).values(i); + IPromise(instance2_).then(this.handleValue.selector, abi.encode(i, instance2_)); + } + } + } + + function handleValue(bytes memory data, bytes memory returnData) public onlyPromises { + (uint256 index_, address instance) = abi.decode(data, (uint256, address)); + uint256 value_ = abi.decode(returnData, (uint256)); + + if (index_ >= 10) revert OutOfBounds(); + values[index_] = value_; + emit ValueRead(instance, index_, value_); + } + + function setFees(Fees memory fees_) public { + fees = fees_; + } + + function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + } +} diff --git a/src/read/ReadMultichain.sol b/src/read/ReadMultichain.sol new file mode 100644 index 0000000..3c2acea --- /dev/null +++ b/src/read/ReadMultichain.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/PlugBase.sol"; + +contract ReadMultichain is PlugBase { + uint256[] public values; + + event ValuesInitialized(uint256[] values); + + constructor() { + values = new uint256[](10); + uint256 baseSeed = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, msg.sender))); + + for (uint256 i = 0; i < 10; i++) { + uint256 uniqueSeed = uint256(keccak256(abi.encodePacked(baseSeed, i))); + values[i] = (uniqueSeed % 10) + 1; + } + + emit ValuesInitialized(values); + } + + function connectSocket(address appGateway_, address socket_, address switchboard_) external { + _connectSocket(appGateway_, socket_, switchboard_); + } +} diff --git a/src/robustness/IRobustnessMultichain.sol b/src/robustness/IRobustnessMultichain.sol deleted file mode 100644 index eadbf8b..0000000 --- a/src/robustness/IRobustnessMultichain.sol +++ /dev/null @@ -1,20 +0,0 @@ -// 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; -} diff --git a/src/robustness/RobustnessAppGateway.sol b/src/robustness/RobustnessAppGateway.sol deleted file mode 100644 index b385fcb..0000000 --- a/src/robustness/RobustnessAppGateway.sol +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "socket-protocol/contracts/base/AppGatewayBase.sol"; -import "./IRobustnessMultichain.sol"; - -contract RobustnessAppGateway is AppGatewayBase { - - uint256[] public values; - uint256[] public resolveTimes = new uint256[](10); - - uint256[] public timeoutDurations = [1, 10, 20, 30, 40, 50, 100, 500, 1000, 10000]; - - constructor(address addressResolver_, address deployerContract_, address auctionManager_, Fees memory fees_) - AppGatewayBase(addressResolver_, auctionManager_) - { - addressResolver__.setContractsToGateways(deployerContract_); - _setOverrides(fees_); - } - - function triggerSequentialWrite(address instance_) public async { - _setOverrides(Read.OFF, Parallel.OFF); - for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).increase(); - } - } - - function triggerParallelWrite(address instance_) public async { - _setOverrides(Read.OFF, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).increase(); - } - } - - function triggerAltWrite(address instance1_, address instance2_) public async { - _setOverrides(Read.OFF, Parallel.OFF); - for (uint256 i = 0; i < 5; i++) { - IRobustnessMultichain(instance1_).increase(); - IRobustnessMultichain(instance2_).increase(); - } - } - - function triggerParallelRead(address instance_) public async { - _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { - IRobustnessMultichain(instance_).getValue(i); - IPromise(instance_).then(this.setValue.selector, abi.encode(i)); - } - } - - function triggerAltRead(address instance1_, address instance2_) public async { - _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { - if (i % 2 == 0) { - IRobustnessMultichain(instance1_).getValue(i); - IPromise(instance1_).then(this.setValue.selector, abi.encode(i)); - } else { - IRobustnessMultichain(instance2_).getValue(i); - IPromise(instance2_).then(this.setValue.selector, abi.encode(i)); - } - } - } - - function triggerReadAndWrite(address instance_) public async { - _setOverrides(Read.ON, Parallel.OFF); - IRobustnessMultichain(instance_).getValue(0); - IPromise(instance_).then(this.setValue.selector, abi.encode(0)); - IRobustnessMultichain(instance_).getValue(1); - IPromise(instance_).then(this.setValue.selector, abi.encode(1)); - - _setOverrides(Read.OFF); - IRobustnessMultichain(instance_).increase(); - IRobustnessMultichain(instance_).increase(); - - _setOverrides(Read.ON); - IRobustnessMultichain(instance_).getValue(2); - IPromise(instance_).then(this.setValue.selector, abi.encode(2)); - IRobustnessMultichain(instance_).getValue(3); - IPromise(instance_).then(this.setValue.selector, abi.encode(3)); - - _setOverrides(Read.OFF); - IRobustnessMultichain(instance_).increase(); - IRobustnessMultichain(instance_).increase(); - } - - function triggerTimeouts() public { - for (uint256 i = 0; i < timeoutDurations.length; i++) { - watcherPrecompile__().setTimeout( - address(this), - abi.encodeWithSelector( - this.resolveTimeout.selector, - i - ), - timeoutDurations[i] - ); - } - } - - function resolveTimeout(uint256 index_) public { - resolveTimes[index_] = block.timestamp; - } - - function setValue(bytes memory data, bytes memory returnData) public onlyPromises { - uint256 index_ = abi.decode(data, (uint256)); - uint256 value_ = abi.decode(returnData, (uint256)); - values[index_] = value_; - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } - - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); - } -} diff --git a/src/robustness/RobustnessDeployer.sol b/src/robustness/RobustnessDeployer.sol deleted file mode 100644 index 01d9250..0000000 --- a/src/robustness/RobustnessDeployer.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "./RobustnessMultichain.sol"; -import "socket-protocol/contracts/base/AppDeployerBase.sol"; - -contract RobustnessDeployer is AppDeployerBase { - bytes32 public multichain = _createContractId("RobustnessMultichain"); - - constructor(address addressResolver_, address auctionManager_, bytes32 sbType_, Fees memory fees_) - AppDeployerBase(addressResolver_, auctionManager_, sbType_) - { - creationCodeWithArgs[multichain] = abi.encodePacked(type(RobustnessMultichain).creationCode); - _setOverrides(fees_); - } - - function deployContracts(uint32 chainSlug_) external async { - _deploy(multichain, chainSlug_, IsPlug.YES); - } - - function initialize(uint32) public pure override { - return; - } - - function setFees(Fees memory fees_) public { - fees = fees_; - } -} diff --git a/src/robustness/RobustnessMultichain.sol b/src/robustness/RobustnessMultichain.sol deleted file mode 100644 index 1f657df..0000000 --- a/src/robustness/RobustnessMultichain.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -import "socket-protocol/contracts/base/PlugBase.sol"; - -contract RobustnessMultichain is PlugBase { - uint256 public counter; - - uint256[] public values; - - function increase() external onlySocket { - counter++; - } - - function setValues(uint256[] memory values_) external { - values = new uint256[](10); - values[0] = values_[0]; - values[1] = values_[1]; - values[2] = values_[2]; - values[3] = values_[3]; - values[4] = values_[4]; - values[5] = values_[5]; - values[6] = values_[6]; - values[7] = values_[7]; - values[8] = values_[8]; - values[9] = values_[9]; - } - - function getValue(uint256 index_) external view returns (uint256) { - return values[index_]; - } - - function connectSocket( - address appGateway_, - address socket_, - address switchboard_ - ) external { - _connectSocket(appGateway_, socket_, switchboard_); - } -} diff --git a/src/write/IWriteMultichain.sol b/src/write/IWriteMultichain.sol new file mode 100644 index 0000000..99f5d60 --- /dev/null +++ b/src/write/IWriteMultichain.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +interface IWriteMultichain { + function counter() external; + + function increase() external; + + function connectSocket(address appGateway_, address socket_, address switchboard_) external; +} diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol new file mode 100644 index 0000000..da4b0c3 --- /dev/null +++ b/src/write/WriteAppGateway.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "./IWriteMultichain.sol"; +import "./WriteMultichain.sol"; + +contract WriteAppGateway is AppGatewayBase { + bytes32 public multichain = _createContractId("WriteMultichain"); + + constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); + _setOverrides(fees_); + } + + function deployContracts(uint32 chainSlug_) external async { + _deploy(multichain, chainSlug_, IsPlug.YES); + } + + function initialize(uint32) public pure override { + return; + } + + function triggerSequentialWrite(address instance_) public async { + _setOverrides(Read.OFF, Parallel.OFF); + for (uint256 i = 0; i < 10; i++) { + IWriteMultichain(instance_).increase(); + } + } + + function triggerParallelWrite(address instance_) public async { + _setOverrides(Read.OFF, Parallel.ON); + for (uint256 i = 0; i < 10; i++) { + IWriteMultichain(instance_).increase(); + } + } + + function triggerAltWrite(address instance1_, address instance2_) public async { + _setOverrides(Read.OFF, Parallel.OFF); + for (uint256 i = 0; i < 5; i++) { + IWriteMultichain(instance1_).increase(); + IWriteMultichain(instance2_).increase(); + } + } + + function setFees(Fees memory fees_) public { + fees = fees_; + } + + function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + } +} diff --git a/src/write/WriteMultichain.sol b/src/write/WriteMultichain.sol new file mode 100644 index 0000000..9ff5c63 --- /dev/null +++ b/src/write/WriteMultichain.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.7.0 <0.9.0; + +import "socket-protocol/contracts/base/PlugBase.sol"; + +contract WriteMultichain is PlugBase { + uint256 public counter; + + event CounterIncreasedTo(uint256); + + function increase() external onlySocket { + counter++; + emit CounterIncreasedTo(counter); + } + + function connectSocket(address appGateway_, address socket_, address switchboard_) external { + _connectSocket(appGateway_, socket_, switchboard_); + } +}