From 3b2d2ba9ee24c256b2622fd3d1742cc46c168186 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 19 May 2025 15:27:00 +0100 Subject: [PATCH 01/16] Update Fees memory to uint256 --- script/SetupScript.sol | 4 ++-- src/deploy/DeploymentAppGateway.sol | 2 +- src/forwarder-on-evmx/UploadAppGateway.sol | 2 +- src/read/ReadAppGateway.sol | 2 +- src/revert/RevertAppGateway.sol | 2 +- src/schedule/ScheduleAppGateway.sol | 2 +- src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol | 2 +- src/write/WriteAppGateway.sol | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index bf1e791..3ba2319 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -30,8 +30,8 @@ abstract contract SetupScript is Script { uint32 opSepChainId = 11155420; uint32[2] chainIds = [opSepChainId, arbSepChainId]; - Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); - Fees deployFees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); + uint256 fees = 30 ether; + uint256 deployFees = 10 ether; FeesManager feesManager = FeesManager(payable(feesManagerAddress)); FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia)); diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 8d1b7eb..468a5b5 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -48,7 +48,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[noPlugNoInititialize] = abi.encodePacked(type(NoPlugNoInititialize).creationCode); creationCodeWithArgs[noPlugInitialize] = abi.encodePacked(type(NoPlugInitialize).creationCode); creationCodeWithArgs[plugNoInitialize] = abi.encodePacked(type(PlugNoInitialize).creationCode); diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index f361c4c..b6526c0 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -31,7 +31,7 @@ contract UploadAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { _setOverrides(fees_); } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index e9f66f5..5f0d3ef 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -41,7 +41,7 @@ contract ReadAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); _setOverrides(fees_); values = new uint256[](10); diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 81cfa80..40eb7e7 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -26,7 +26,7 @@ contract RevertAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode); _setOverrides(fees_); } diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 69bc537..ee9eea7 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -30,7 +30,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for onchain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { _setOverrides(fees_); } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index ea7af3d..ca9b405 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -48,7 +48,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[onchainToEVMx] = abi.encodePacked(type(OnchainTrigger).creationCode); _setOverrides(fees_); } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 37dabd9..6b3db63 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -33,7 +33,7 @@ contract WriteAppGateway is AppGatewayBase { * @param addressResolver_ Address of the SOCKET Protocol's AddressResolver contract * @param fees_ Fee configuration for multi-chain operations */ - constructor(address addressResolver_, Fees memory fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); _setOverrides(fees_); } From ac15c6b588dcf473b85ce01a9da988bcfcf491e0 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 19 May 2025 15:27:22 +0100 Subject: [PATCH 02/16] Update .env.sample --- .env.sample | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.env.sample b/.env.sample index 625c696..08ca53d 100644 --- a/.env.sample +++ b/.env.sample @@ -8,13 +8,15 @@ BASE_SEPOLIA_RPC="https://sepolia.base.org" # EVMx key addresses # Find the most up to date addresses at: # https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json -ADDRESS_RESOLVER="0x4846430BB142385e581C894AE92a4CF0722aEC21" -FEES_MANAGER="0x9745623Aaa299500F93d2B1B4Efb7b3EC5e60FFc" -ARBITRUM_FEES_PLUG="0x9E263f6c7C199d9c147E30764A8cae1175184CB8" +ADDRESS_RESOLVER="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e" +FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C" +ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b" +ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3" # Add your deployer private key here # or remove it from this file if it is already an env var PRIVATE_KEY="0x" +WALLET_ADDRESS="0x" # Set app related values after deployment on EVMx APP_GATEWAY="0x" From 69e12de95a3438385b1d455bedb755822a77abb3 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 19 May 2025 15:28:46 +0100 Subject: [PATCH 03/16] Update fee deposits --- script/run-evmx-apps.sh | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 8311286..ab12855 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -88,8 +88,9 @@ prepare_deployment() { export ARB_SEP_CHAIN_ID=421614 export OP_SEP_CHAIN_ID=11155420 export ETH_ADDRESS=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE - export DEPLOY_FEES_AMOUNT=500000000000000 # 0.0005 ETH in wei - export FEES_AMOUNT="1000000000000000" # 0.001 ETH in wei + export DEPLOY_FEES_AMOUNT=10000000000000000000 # 10 ETH in wei + export FEES_AMOUNT=30000000000000000000 # 30 ETH in wei + export TEST_USDC_AMOUNT="100000000" # 100 TEST USDC export GAS_BUFFER="100000000" # 0.1 Gwei in wei export GAS_LIMIT="3000000" # Gas limit estimate export EVMX_VERIFIER_URL="https://evmx.cloud.blockscout.com/api" @@ -391,25 +392,34 @@ check_available_fees() { attempt=$((attempt + 1)) done - echo -e "Funds available: $available_fees wei" - return 0 + # If we get here, we've exceeded maximum attempts + printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar + echo -e "${RED}Error:${NC} No funds available after 60 seconds." + exit 1 } # Function to deposit funds deposit_funds() { echo -e "${CYAN}Depositing funds${NC}" + # Mint test USDC + if ! send_transaction "$ARBITRUM_TEST_USDC" "mint(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$WALLET_ADDRESS" "$TEST_USDC_AMOUNT"; then + echo -e "${RED}Error:${NC} Failed to mint test USDC." + return 1 + fi + + # Approve USDC for FeesPlug + if ! send_transaction "$ARBITRUM_TEST_USDC" "approve(address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_FEES_PLUG" "$TEST_USDC_AMOUNT"; then + echo -e "${RED}Error:${NC} Failed to approve test USDC to FeesPlug." + return 1 + fi + # Deposit funds - # Note: This is a special case that needs value parameter - if ! output=$(cast send "$ARBITRUM_FEES_PLUG" \ - --rpc-url "$ARBITRUM_SEPOLIA_RPC" \ - --private-key "$PRIVATE_KEY" \ - --value "$FEES_AMOUNT" \ - "deposit(address,address,uint256)" "$ETH_ADDRESS" "$APP_GATEWAY" "$FEES_AMOUNT"); then - echo -e "${RED}Error:${NC} Failed to deposit fees." - exit 1 + if ! send_transaction "$ARBITRUM_FEES_PLUG" "depositToFeeAndNative(address,address,uint256)" "$ARBITRUM_SEPOLIA_RPC" "arbitrum-sepolia" "$ARBITRUM_TEST_USDC" "$APP_GATEWAY" "$TEST_USDC_AMOUNT"; then + echo -e "${RED}Error:${NC} Failed to deposit to fees and native." + return 1 fi - parse_txhash "$output" "arbitrum-sepolia" + check_available_fees } From a6fb88a19e98b2044731f9ccf499c24fdd78980f Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 19 May 2025 15:29:59 +0100 Subject: [PATCH 04/16] Update gateway deployment --- script/run-evmx-apps.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index ab12855..1a61583 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -114,11 +114,12 @@ deploy_appgateway() { --verify \ --verifier-url "$EVMX_VERIFIER_URL" \ --verifier blockscout \ - --constructor-args "$ADDRESS_RESOLVER" "($ARB_SEP_CHAIN_ID, $ETH_ADDRESS, $deploy_fees)"); then + --constructor-args "$ADDRESS_RESOLVER" "$deploy_fees"); then echo -e "${RED}Error:${NC} Contract deployment failed." exit 1 fi + parse_txhash "$output" "evmx.cloud" # Extract the deployed address local appgateway appgateway=$(echo "$output" | grep "Deployed to:" | awk '{print $3}') @@ -138,6 +139,10 @@ function parse_txhash() { local path=$2 local txhash txhash=$(echo "$output" | grep "^transactionHash" | awk '{print $2}') + if [ -z "$txhash" ]; then + txhash=$(echo "$output" | grep -i "Transaction hash:" | awk '{print $3}') + fi + # Check if txhash is empty or invalid if [ -z "$txhash" ] || ! [[ "$txhash" =~ ^0x[0-9a-fA-F]{64}$ ]]; then echo -e "${RED}Error:${NC} Failed to extract valid transactionHash from output." From 41fc3373733bd8c184ce34b325b82a9ff7f9f9f2 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 19 May 2025 15:30:24 +0100 Subject: [PATCH 05/16] Update check available fees --- script/run-evmx-apps.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 1a61583..f07a399 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -352,19 +352,20 @@ check_available_fees() { local width=50 local bar - while true; do + while [ $attempt -lt $max_attempts ]; do if ! output=$(cast call "$FEES_MANAGER" \ - "getAvailableFees(uint32,address,address)(uint256)" \ - "$ARB_SEP_CHAIN_ID" "$APP_GATEWAY" "$ETH_ADDRESS" \ + "getAvailableCredits(address)(uint256)" \ + "$APP_GATEWAY" \ --rpc-url "$EVMX_RPC" 2>/dev/null); then + printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar echo -e "${RED}Error:${NC} Failed to retrieve available fees." exit 1 else # Extract the fees value available_fees=$(echo "$output" | awk '{print $1}') - # Validate the fees value is a number if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then + printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar echo -e "${RED}Error:${NC} Invalid fee value received." exit 1 fi @@ -372,17 +373,9 @@ check_available_fees() { # Check if we got non-zero fees if [ "$available_fees" -ne 0 ]; then - if [ $attempt -ne 0 ]; then - printf "\n" # New line after progress bar only if not first attempt - fi - break - fi - - # Check if we've exceeded maximum attempts - if [ $attempt -ge $max_attempts ]; then - printf "\n" # New line before error message - echo -e "${RED}Error:${NC} No funds available after 60 seconds." - exit 1 + printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar + echo -e "Funds available: $available_fees wei" + return 0 fi # Calculate progress bar From d5bcdad9e334709ef07776c3995b4f33b32773a9 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 20 May 2025 13:03:48 +0100 Subject: [PATCH 06/16] Fix check for large numbers on available fees --- script/run-evmx-apps.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index f07a399..8310b13 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -347,11 +347,10 @@ fetch_forwarder_and_onchain_address() { check_available_fees() { local max_attempts=12 # 60 seconds / 5-second interval local attempt=0 - local available_fees=0 + local available_fees="0" local output local width=50 local bar - while [ $attempt -lt $max_attempts ]; do if ! output=$(cast call "$FEES_MANAGER" \ "getAvailableCredits(address)(uint256)" \ @@ -370,26 +369,21 @@ check_available_fees() { exit 1 fi fi - # Check if we got non-zero fees - if [ "$available_fees" -ne 0 ]; then + if [ "$available_fees" != "0" ]; then printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar echo -e "Funds available: $available_fees wei" return 0 fi - # Calculate progress bar local progress=$(( (attempt * width) / max_attempts )) local percent=$(( (attempt * 100) / max_attempts )) bar=$(printf "#%.0s" $(seq 1 $progress)) - # Print progress bar on the same line printf "\r${YELLOW}Checking fees:${NC} [%-${width}s] %d%%" "$bar" "$percent" - sleep 5 attempt=$((attempt + 1)) done - # If we get here, we've exceeded maximum attempts printf "\r%*s\r" $((width + 30)) "" # Clear the progress bar echo -e "${RED}Error:${NC} No funds available after 60 seconds." From 03f649df560c472df5934b936ab310e7b9c318e4 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 20 May 2025 14:10:52 +0100 Subject: [PATCH 07/16] Update socket-protocol submodule to latest master --- lib/socket-protocol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/socket-protocol b/lib/socket-protocol index aa83294..38accd5 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit aa832943bc2a943a6e7c2c5d69ef1cd1412226c5 +Subproject commit 38accd5f8a4144297048940122d56a08578c1783 From fd198e9c0a9e003a98a2a9c8683b002b6a0b3ad0 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 20 May 2025 14:38:14 +0100 Subject: [PATCH 08/16] Update contracts to match new protocol --- script/SetupScript.sol | 24 ++++++------------- src/deploy/DeployOnchain.sol | 2 +- src/deploy/DeploymentAppGateway.sol | 17 ++++--------- src/forwarder-on-evmx/UploadAppGateway.sol | 17 ++++--------- src/read/ReadAppGateway.sol | 21 +++++----------- src/read/ReadMultichain.sol | 13 +--------- src/revert/Counter.sol | 13 +--------- src/revert/RevertAppGateway.sol | 21 +++++----------- src/schedule/ScheduleAppGateway.sol | 13 ++-------- .../OnchainTrigger.sol | 6 ++--- .../OnchainTriggerAppGateway.sol | 18 ++++---------- src/write/WriteAppGateway.sol | 19 ++++----------- src/write/WriteMultichain.sol | 13 +--------- 13 files changed, 45 insertions(+), 152 deletions(-) diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 3ba2319..3b59233 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -4,10 +4,9 @@ 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/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/FeesManager.sol"; +import {FeesPlug} from "socket-protocol/contracts/evmx/payload-delivery/FeesPlug.sol"; +import {ETH_ADDRESS, FAST} from "socket-protocol/contracts/utils/common/Constants.sol"; +import {FeesManager} from "socket-protocol/contracts/evmx/payload-delivery/FeesManager.sol"; interface IAppGateway { function deployContracts(uint32 chainId) external; @@ -35,25 +34,16 @@ abstract contract SetupScript is Script { FeesManager feesManager = FeesManager(payable(feesManagerAddress)); FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia)); - function checkDepositedFees(uint32 chainId) internal returns (uint256 availableFees) { + function checkDepositedFees() internal returns (uint256 availableFees) { vm.createSelectFork(rpcEVMx); - (uint256 deposited, uint256 blocked) = - feesManager.appGatewayFeeBalances(appGatewayAddress, chainId, ETH_ADDRESS); + availableFees = feesManager.getAvailableCredits(appGatewayAddress); 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); + uint256 availableFees = checkDepositedFees(); if (availableFees > 0) { // Switch to Arbitrum Sepolia to get gas price @@ -126,7 +116,7 @@ abstract contract SetupScript is Script { // Standard flow // Each implementation script will call these functions function _run(uint32 chainId) internal { - uint256 availableFees = checkDepositedFees(chainId); + uint256 availableFees = checkDepositedFees(); if (availableFees > 0) { executeScriptSpecificLogic(); diff --git a/src/deploy/DeployOnchain.sol b/src/deploy/DeployOnchain.sol index 7a6d53b..b1e7c0a 100644 --- a/src/deploy/DeployOnchain.sol +++ b/src/deploy/DeployOnchain.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title NoPlugNoInititialize diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 468a5b5..17d2ecf 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -1,7 +1,7 @@ // 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/evmx/base/AppGatewayBase.sol"; import "./DeployOnchain.sol"; import "./IDeployOnchain.sol"; @@ -63,7 +63,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @dev Triggers asynchronous multi-chain deployments with different initialization scenarios * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(noPlugNoInititialize, chainSlug_, IsPlug.NO); _deploy( noPlugInitialize, chainSlug_, IsPlug.NO, abi.encodeWithSelector(NoPlugInitialize.initialise.selector, 10) @@ -84,7 +84,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @dev Calls initialize functions on specific contracts after deployment * @param chainSlug_ The identifier of the chain where contracts were deployed */ - function initialize(uint32 chainSlug_) public override async { + function initialize(uint32 chainSlug_) public override async(bytes("")) { PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); } @@ -94,7 +94,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @dev Performs checks on each contract type to ensure proper initialization and functionality * @param chainSlug_ The identifier of the chain where contracts were deployed */ - function contractValidation(uint32 chainSlug_) external async { + function contractValidation(uint32 chainSlug_) external async(bytes("")) { address noPlugNoInititializeForwarder = forwarderAddresses[noPlugNoInititialize][chainSlug_]; address noPlugInitializeForwarder = forwarderAddresses[noPlugInitialize][chainSlug_]; address plugNoInitializeForwarder = forwarderAddresses[plugNoInitialize][chainSlug_]; @@ -162,15 +162,6 @@ contract DeploymentAppGateway is AppGatewayBase { require(onchainSocket != notSocket, "Should return socket address"); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index b6526c0..ab2ce57 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; -import "socket-protocol/contracts/base/AppGatewayBase.sol"; -import "socket-protocol/contracts/interfaces/IPromise.sol"; +import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./ICounter.sol"; /** @@ -40,7 +40,7 @@ contract UploadAppGateway is AppGatewayBase { * @dev Required by AppGatewayBase but not used in this implementation * @param chainSlug_ The identifier of the target chain (unused) */ - function deployContracts(uint32 chainSlug_) external async {} + function deployContracts(uint32 chainSlug_) external async(bytes("")) {} /** * @notice Empty initialization function as no post-deployment setup is needed @@ -64,7 +64,7 @@ contract UploadAppGateway is AppGatewayBase { * @dev Initiates an asynchronous read operation with parallel execution enabled * Sets up a promise to handle the read result via the handleRead function */ - function read() public async { + function read() public async(bytes("")) { _setOverrides(Read.ON, Parallel.ON); // TODO: Remove Parallel.ON after new contract deployment to devnet ICounter(counterForwarder).counter(); @@ -86,15 +86,6 @@ contract UploadAppGateway is AppGatewayBase { emit ReadOnchain(instance, value_); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 5f0d3ef..9fd4608 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -1,9 +1,9 @@ // 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 "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/evmx/interfaces/IForwarder.sol"; +import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./IReadMultichain.sol"; import "./ReadMultichain.sol"; @@ -52,7 +52,7 @@ contract ReadAppGateway is AppGatewayBase { * @dev Triggers an asynchronous multi-chain deployment via SOCKET Protocol. * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(multichain, chainSlug_, IsPlug.YES); } @@ -71,7 +71,7 @@ contract ReadAppGateway is AppGatewayBase { * and stores the results in the values array. * @param instance_ Address of the ReadMultichain instance to read from */ - function triggerParallelRead(address instance_) public async { + function triggerParallelRead(address instance_) public async(bytes("")) { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { IReadMultichain(instance_).values(i); @@ -87,7 +87,7 @@ contract ReadAppGateway is AppGatewayBase { * @param instance1_ Address of the first ReadMultichain instance * @param instance2_ Address of the second ReadMultichain instance */ - function triggerAltRead(address instance1_, address instance2_) public async { + function triggerAltRead(address instance1_, address instance2_) public async(bytes("")) { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { if (i % 2 == 0) { @@ -115,15 +115,6 @@ contract ReadAppGateway is AppGatewayBase { emit ValueRead(instance, index_, value_); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for multi-chain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/read/ReadMultichain.sol b/src/read/ReadMultichain.sol index 7b1c0fd..746bc59 100644 --- a/src/read/ReadMultichain.sol +++ b/src/read/ReadMultichain.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title ReadMultichain @@ -38,15 +38,4 @@ contract ReadMultichain is PlugBase { emit ValuesInitialized(values); } - - /** - * @notice Connects the contract to the SOCKET Protocol - * @dev Sets up the contract for EVMx communication by calling the parent PlugBase method - * @param appGateway_ Address of the application gateway contract - * @param socket_ Address of the SOCKET Protocol contract - * @param switchboard_ Address of the switchboard contract - */ - function connectSocket(address appGateway_, address socket_, address switchboard_) external onlySocket { - _connectSocket(appGateway_, socket_, switchboard_); - } } diff --git a/src/revert/Counter.sol b/src/revert/Counter.sol index cef0d44..0a5f3ca 100644 --- a/src/revert/Counter.sol +++ b/src/revert/Counter.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title Counter @@ -22,15 +22,4 @@ contract Counter is PlugBase { function increment() public { counter++; } - - /** - * @notice Connects the contract to the SOCKET Protocol - * @dev Sets up the contract for EVMx communication by calling the parent PlugBase method - * @param appGateway_ Address of the application gateway contract - * @param socket_ Address of the SOCKET Protocol contract - * @param switchboard_ Address of the switchboard contract - */ - function connectSocket(address appGateway_, address socket_, address switchboard_) external onlySocket { - _connectSocket(appGateway_, socket_, switchboard_); - } } diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 40eb7e7..ebfa768 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -1,8 +1,8 @@ // 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/IPromise.sol"; +import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./ICounter.sol"; import "./Counter.sol"; @@ -36,7 +36,7 @@ contract RevertAppGateway is AppGatewayBase { * @dev Triggers an asynchronous multi-chain deployment via SOCKET Protocol * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(counter, chainSlug_, IsPlug.YES); } @@ -45,7 +45,7 @@ contract RevertAppGateway is AppGatewayBase { * @dev Sets up the validity of the deployed OnchainTrigger contract on the specified chain * @param chainSlug_ The identifier of the chain where the contract was deployed */ - function initialize(uint32 chainSlug_) public override async { + function initialize(uint32 chainSlug_) public override async(bytes("")) { address instance = forwarderAddresses[counter][chainSlug_]; ICounter(instance).increment(); } @@ -57,7 +57,7 @@ contract RevertAppGateway is AppGatewayBase { * unexistentFunction exists on the interface but not on the onchain contract. This will cause an onchain revert. * @param chainSlug A uint32 identifier for the target chain to test the revert on */ - function testOnChainRevert(uint32 chainSlug) public async { + function testOnChainRevert(uint32 chainSlug) public async(bytes("")) { address instance = forwarderAddresses[counter][chainSlug]; ICounter(instance).unexistentFunction(); } @@ -69,7 +69,7 @@ contract RevertAppGateway is AppGatewayBase { * notCorrectInputArgs that will revert due to wrong input parameters * @param chainSlug A uint32 identifier for the target chain to test the callback revert on */ - function testCallbackRevertWrongInputArgs(uint32 chainSlug) public async { + function testCallbackRevertWrongInputArgs(uint32 chainSlug) public async(bytes("")) { _setOverrides(Read.ON, Parallel.ON); address instance = forwarderAddresses[counter][chainSlug]; ICounter(instance).counter(); @@ -89,15 +89,6 @@ contract RevertAppGateway is AppGatewayBase { emit CallbackEvent(someWrongParam, 0); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index ee9eea7..e7d79f9 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -1,7 +1,7 @@ // 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/evmx/base/AppGatewayBase.sol"; /** * @title ScheduleAppGateway @@ -39,7 +39,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @dev This function is a placeholder for the ScheduleAppGateway since no contracts need deployment * The chainSlug parameter is required by the interface but not used. */ - function deployContracts(uint32) external async { + function deployContracts(uint32) external async(bytes("")) { return; } @@ -73,15 +73,6 @@ contract ScheduleAppGateway is AppGatewayBase { emit TimeoutResolved(index_, creationTimestamp_, block.timestamp); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/trigger-appgateway-onchain/OnchainTrigger.sol b/src/trigger-appgateway-onchain/OnchainTrigger.sol index 4dfc668..cf45e48 100644 --- a/src/trigger-appgateway-onchain/OnchainTrigger.sol +++ b/src/trigger-appgateway-onchain/OnchainTrigger.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.21; import "solady/auth/Ownable.sol"; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title OnchainTrigger @@ -36,7 +36,7 @@ contract OnchainTrigger is Ownable, PlugBase { * @return The transaction ID of the onchain message */ 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)); } /** @@ -46,7 +46,7 @@ contract OnchainTrigger is Ownable, PlugBase { * @return The transaction ID of the onchain message */ 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)); } /** diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index ca9b405..ca83836 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; -import "socket-protocol/contracts/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; import "./OnchainTrigger.sol"; import "./IOnchainTrigger.sol"; @@ -58,7 +58,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @dev Triggers an asynchronous multi-chain deployment via SOCKET Protocol * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(onchainToEVMx, chainSlug_, IsPlug.YES); } @@ -77,7 +77,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @dev Sends the current valueOnGateway to the OnchainTrigger contract on the specified chain * @param targetChain The identifier of the destination chain */ - function updateOnchain(uint32 targetChain) public async { + function updateOnchain(uint32 targetChain) public async(bytes("")) { address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(valueOnGateway); } @@ -93,8 +93,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { */ function callFromChain(uint32, address, bytes32, bytes calldata payload_) external - override - async + async(bytes("")) onlyWatcherPrecompile { (uint32 msgType, bytes memory payload) = abi.decode(payload_, (uint32, bytes)); @@ -110,15 +109,6 @@ contract OnchainTriggerAppGateway is AppGatewayBase { } } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 6b3db63..495f0a7 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -1,7 +1,7 @@ // 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/evmx/base/AppGatewayBase.sol"; import "./IWriteMultichain.sol"; import "./WriteMultichain.sol"; @@ -43,7 +43,7 @@ contract WriteAppGateway is AppGatewayBase { * @dev Triggers an asynchronous multi-chain deployment via SOCKET Protocol * @param chainSlug_ The identifier of the target chain */ - function deployContracts(uint32 chainSlug_) external async { + function deployContracts(uint32 chainSlug_) external async(bytes("")) { _deploy(multichain, chainSlug_, IsPlug.YES); } @@ -61,7 +61,7 @@ contract WriteAppGateway is AppGatewayBase { * @dev Calls the increase function 10 times in sequence and processes the return values * @param instance_ Address of the WriteMultichain instance to write to */ - function triggerSequentialWrite(address instance_) public async { + function triggerSequentialWrite(address instance_) public async(bytes("")) { for (uint256 i = 0; i < 10; i++) { IWriteMultichain(instance_).increase(); IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); @@ -73,7 +73,7 @@ contract WriteAppGateway is AppGatewayBase { * @dev Calls the increase function 10 times in parallel and processes the return values * @param instance_ Address of the WriteMultichain instance to write to */ - function triggerParallelWrite(address instance_) public async { + function triggerParallelWrite(address instance_) public async(bytes("")) { _setOverrides(Parallel.ON); for (uint256 i = 0; i < 10; i++) { IWriteMultichain(instance_).increase(); @@ -88,7 +88,7 @@ contract WriteAppGateway is AppGatewayBase { * @param instance1_ Address of the first WriteMultichain instance * @param instance2_ Address of the second WriteMultichain instance */ - function triggerAltWrite(address instance1_, address instance2_) public async { + function triggerAltWrite(address instance1_, address instance2_) public async(bytes("")) { for (uint256 i = 0; i < 5; i++) { IWriteMultichain(instance1_).increase(); IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); @@ -109,15 +109,6 @@ contract WriteAppGateway is AppGatewayBase { emit CounterIncreased(instance, index_, value_); } - /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for multi-chain operations - * @param fees_ New fee configuration - */ - function setFees(Fees memory fees_) public { - fees = fees_; - } - /** * @notice Withdraws fee tokens from the SOCKET Protocol * @dev Allows withdrawal of accumulated fees to a specified receiver diff --git a/src/write/WriteMultichain.sol b/src/write/WriteMultichain.sol index f10ead2..718144e 100644 --- a/src/write/WriteMultichain.sol +++ b/src/write/WriteMultichain.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; -import "socket-protocol/contracts/base/PlugBase.sol"; +import "socket-protocol/contracts/protocol/base/PlugBase.sol"; /** * @title WriteMultichain @@ -33,15 +33,4 @@ contract WriteMultichain is PlugBase { emit CounterIncreasedTo(counter); return counter; } - - /** - * @notice Connects the contract to the SOCKET Protocol - * @dev Sets up the contract for EVMx communication by calling the parent PlugBase method - * @param appGateway_ Address of the application gateway contract - * @param socket_ Address of the SOCKET Protocol contract - * @param switchboard_ Address of the switchboard contract - */ - function connectSocket(address appGateway_, address socket_, address switchboard_) external onlySocket { - _connectSocket(appGateway_, socket_, switchboard_); - } } From 0f19ac0c616f35aca4681a9786461078499f4878 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 20 May 2025 16:02:14 +0100 Subject: [PATCH 09/16] Set max fees on AppGateway --- script/run-evmx-apps.sh | 6 ++++++ src/deploy/DeploymentAppGateway.sol | 2 +- src/forwarder-on-evmx/UploadAppGateway.sol | 2 +- src/read/ReadAppGateway.sol | 2 +- src/revert/RevertAppGateway.sol | 2 +- src/schedule/ScheduleAppGateway.sol | 2 +- .../OnchainTriggerAppGateway.sol | 2 +- src/write/WriteAppGateway.sol | 11 ++++++++++- 8 files changed, 22 insertions(+), 7 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 8310b13..f3d3c66 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -413,6 +413,12 @@ deposit_funds() { fi check_available_fees + # Set Max Fees on AppGateway + if ! send_transaction "$APP_GATEWAY" "setMaxFees(uint256)" "$EVMX_RPC" "arbitrum-sepolia" "$FEES_AMOUNT"; then + echo -e "${RED}Error:${NC} Failed to set max fees on AppGateway." + return 1 + fi + } # Function to withdraw funds diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 17d2ecf..9ef47e0 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -55,7 +55,7 @@ contract DeploymentAppGateway is AppGatewayBase { creationCodeWithArgs[plugInitialize] = abi.encodePacked(type(PlugInitialize).creationCode); creationCodeWithArgs[plugInitializeTwice] = abi.encodePacked(type(PlugInitializeTwice).creationCode); creationCodeWithArgs[plugNoInitInitialize] = abi.encodePacked(type(PlugNoInitInitialize).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); } /** diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index ab2ce57..0a6ba00 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -32,7 +32,7 @@ contract UploadAppGateway is AppGatewayBase { * @param fees_ Fee configuration for multi-chain operations */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { - _setOverrides(fees_); + _setMaxFees(fees_); } /** diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 9fd4608..285f665 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -43,7 +43,7 @@ contract ReadAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); values = new uint256[](10); } diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index ebfa768..5c592d6 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -28,7 +28,7 @@ contract RevertAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); } /** diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index e7d79f9..9164f45 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -31,7 +31,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @param fees_ Fee configuration for onchain operations */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { - _setOverrides(fees_); + _setMaxFees(fees_); } /** diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index ca83836..3963726 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -50,7 +50,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[onchainToEVMx] = abi.encodePacked(type(OnchainTrigger).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); } /** diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 495f0a7..1f5377f 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -35,7 +35,7 @@ contract WriteAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); - _setOverrides(fees_); + _setMaxFees(fees_); } /** @@ -120,4 +120,13 @@ contract WriteAppGateway is AppGatewayBase { function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); } + + /** + * @notice Updates the fee max value + * @dev Allows modification of fee settings for multi-chain operations + * @param fees_ New fee configuration + */ + function setMaxFees(uint256 fees_) public { + maxFees = fees_; + } } From 534888c4b34a1ce719a09514b6c7943910d38ebc Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 20 May 2025 17:33:39 +0100 Subject: [PATCH 10/16] Remove set max fees after deposit --- script/run-evmx-apps.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index f3d3c66..8310b13 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -413,12 +413,6 @@ deposit_funds() { fi check_available_fees - # Set Max Fees on AppGateway - if ! send_transaction "$APP_GATEWAY" "setMaxFees(uint256)" "$EVMX_RPC" "arbitrum-sepolia" "$FEES_AMOUNT"; then - echo -e "${RED}Error:${NC} Failed to set max fees on AppGateway." - return 1 - fi - } # Function to withdraw funds From d3513b2efd3018caf1998c56549072d064f82c97 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 21 May 2025 10:24:09 +0100 Subject: [PATCH 11/16] Update withdraw function to deal with larger amounts --- script/run-evmx-apps.sh | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 8310b13..d149d30 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -92,7 +92,7 @@ prepare_deployment() { export FEES_AMOUNT=30000000000000000000 # 30 ETH in wei export TEST_USDC_AMOUNT="100000000" # 100 TEST USDC export GAS_BUFFER="100000000" # 0.1 Gwei in wei - export GAS_LIMIT="3000000" # Gas limit estimate + export GAS_LIMIT="50000000000" # Gas limit estimate export EVMX_VERIFIER_URL="https://evmx.cloud.blockscout.com/api" export EVMX_API_BASE_URL="https://api-evmx-devnet.socket.tech" } @@ -422,43 +422,41 @@ withdraw_funds() { # Get available fees from EVMX chain local output if ! output=$(cast call "$FEES_MANAGER" \ - "getAvailableFees(uint32,address,address)(uint256)" \ - "$ARB_SEP_CHAIN_ID" "$APP_GATEWAY" "$ETH_ADDRESS" \ - --rpc-url "$EVMX_RPC"); then - echo -e "${RED}Error:${NC} Failed to get available fees." + "getAvailableCredits(address)(uint256)" \ + "$APP_GATEWAY" \ + --rpc-url "$EVMX_RPC" 2>/dev/null); then + echo -e "${RED}Error:${NC} Failed to retrieve available fees." exit 1 fi local available_fees available_fees=$(echo "$output" | awk '{print $1}') - - # Ensure it's a valid integer before proceeding + # Validate the fees value is a number if ! [[ "$available_fees" =~ ^[0-9]+$ ]]; then - echo -e "${RED}Error:${NC} Invalid available fees value: $available_fees" + echo -e "${RED}Error:${NC} Invalid fee value received." exit 1 fi echo "Available Fees: $available_fees wei" - # Check if there are funds to withdraw - if [ "$available_fees" -gt 0 ]; then + if [ "$available_fees" != "0" ]; then # Fetch gas price on Arbitrum Sepolia local arb_gas_price arb_gas_price=$(cast base-fee --rpc-url "$ARBITRUM_SEPOLIA_RPC") - # Add buffer to gas price - local gas_price=$((arb_gas_price + GAS_BUFFER)) - local estimated_gas_cost=$((GAS_LIMIT * gas_price)) - + local gas_price + local estimated_gas_cost + gas_price=$(echo "$arb_gas_price + $GAS_BUFFER" | bc) + estimated_gas_cost=$(echo "$GAS_LIMIT * $gas_price" | bc) # Calculate withdrawal amount local amount_to_withdraw=0 - if [ "$available_fees" -gt "$estimated_gas_cost" ]; then - amount_to_withdraw=$((available_fees - estimated_gas_cost)) + if (( $(echo "$available_fees > $estimated_gas_cost" | bc -l) )); then + amount_to_withdraw=$(echo "$available_fees - $estimated_gas_cost" | bc) fi - - if [ "$amount_to_withdraw" -gt 0 ]; then + echo "Withdrawing $amount_to_withdraw wei" + if (( $(echo "$amount_to_withdraw > 0" | bc -l) )); then # Withdraw funds using send_transaction - if ! send_transaction "$APP_GATEWAY" "withdrawFeeTokens(uint32,address,uint256,address)" "$EVMX_RPC" "evmx.cloud" "$ARB_SEP_CHAIN_ID" "$ETH_ADDRESS" "$amount_to_withdraw" "$SENDER_ADDRESS"; then + if ! send_transaction "$APP_GATEWAY" "withdrawFeeTokens(uint32,address,uint256,address)" "$EVMX_RPC" "evmx.cloud" "$ARB_SEP_CHAIN_ID" "$ARBITRUM_TEST_USDC" "$amount_to_withdraw" "$SENDER_ADDRESS"; then echo -e "${RED}Error:${NC} Failed to withdraw fees." exit 1 fi From fe9fbbef126673e70f7fbf93e003f2e5a95f4c76 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 21 May 2025 10:24:40 +0100 Subject: [PATCH 12/16] Update forwarder address refresh rate --- script/run-evmx-apps.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index d149d30..f10eebb 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -267,7 +267,7 @@ fetch_forwarder_and_onchain_address() { # Retrieve forwarder address with timeout local forwarder local attempts=0 - local max_attempts=12 # 60 seconds / 5 second sleep = 12 attempts + local max_attempts=30 # 60 seconds / 2 second sleep = 30 attempts local width=50 # Width of the progress bar local bar @@ -302,7 +302,7 @@ fetch_forwarder_and_onchain_address() { # Print progress bar on the same line printf "\r${YELLOW}Waiting for forwarder:${NC} [%-${width}s] %d%%" "$bar" "$percent" - sleep 5 + sleep 2 attempts=$((attempts + 1)) done From 674d5812efe8f1675ab6e2643f4e8d8444e981c1 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 21 May 2025 15:17:33 +0100 Subject: [PATCH 13/16] Fix read test validation --- script/run-evmx-apps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index f10eebb..225da31 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -621,7 +621,7 @@ run_read_tests() { echo -e "${RED}Error:${NC} Failed to trigger parallel read" return 1 fi - await_events 10 + await_events 10 "ValueRead(address,uint256,uint256)" # 2. Trigger Alternating Read between chains if ! send_transaction "$APP_GATEWAY" "triggerAltRead(address,address)" "$EVMX_RPC" "evmx.cloud" "$OP_FORWARDER" "$ARB_FORWARDER"; then From 696d53d2743797ec2b2af985105dd8273c752d90 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 21 May 2025 15:17:56 +0100 Subject: [PATCH 14/16] Add deposit credits for scheduler tests --- script/run-evmx-apps.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 225da31..8ca2721 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -1099,6 +1099,7 @@ main() { # Scheduler Tests function run_scheduler_tests_func() { deploy_appgateway schedule ScheduleAppGateway + deposit_funds read_timeouts trigger_timeouts echo -e "${CYAN}Waiting for the highest timeout before reading logs...${NC}" From 510ec7ef3f669f25400348ac5ff4f02ddf5b16c8 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 21 May 2025 16:16:32 +0100 Subject: [PATCH 15/16] Update onchain trigger example --- .../IOnchainAppGateway.sol | 18 ++++++++ .../OnchainTrigger.sol | 18 ++------ .../OnchainTriggerAppGateway.sol | 41 ++++++++----------- 3 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 src/trigger-appgateway-onchain/IOnchainAppGateway.sol diff --git a/src/trigger-appgateway-onchain/IOnchainAppGateway.sol b/src/trigger-appgateway-onchain/IOnchainAppGateway.sol new file mode 100644 index 0000000..fa50bdc --- /dev/null +++ b/src/trigger-appgateway-onchain/IOnchainAppGateway.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +interface IOnchainAppGateway { + /** + * @notice Triggers an operation to increase a value on the gateway + * @param value The amount to increase + * @return The transaction ID of the onchain message + */ + function callFromChain(uint256 value) external returns (bytes32); + + /** + * @notice Propagates the current value to another chain + * @param targetChain The identifier of the destination chain + * @return The transaction ID of the onchain message + */ + function propagateToChain(uint256 value, uint32 targetChain) external returns (bytes32); +} diff --git a/src/trigger-appgateway-onchain/OnchainTrigger.sol b/src/trigger-appgateway-onchain/OnchainTrigger.sol index cf45e48..f6b6ad2 100644 --- a/src/trigger-appgateway-onchain/OnchainTrigger.sol +++ b/src/trigger-appgateway-onchain/OnchainTrigger.sol @@ -4,6 +4,8 @@ pragma solidity ^0.8.21; import "solady/auth/Ownable.sol"; import "socket-protocol/contracts/protocol/base/PlugBase.sol"; +import "./IOnchainAppGateway.sol"; + /** * @title OnchainTrigger * @dev A contract that can send and receive values across chains via SOCKET Protocol. @@ -17,18 +19,6 @@ contract OnchainTrigger is Ownable, PlugBase { */ uint256 public value; - /** - * @notice Message type identifier for increasing value on the gateway - * @dev Used to differentiate message types in multi-chain communication - */ - uint32 public constant INCREASE_ON_GATEWAY = 1; - - /** - * @notice Message type identifier for propagating value to another chain - * @dev Used to differentiate message types in multi-chain communication - */ - uint32 public constant PROPAGATE_TO_ANOTHER = 2; - /** * @notice Triggers an operation to increase a value on the gateway * @dev Sends a message to the gateway to increase its value using SOCKET Protocol @@ -36,7 +26,7 @@ contract OnchainTrigger is Ownable, PlugBase { * @return The transaction ID of the onchain message */ function increaseOnGateway(uint256 value_) external returns (bytes32) { - //return _callAppGateway(abi.encode(INCREASE_ON_GATEWAY, abi.encode(value_)), bytes32(0)); + return IOnchainAppGateway(address(socket__)).callFromChain(value_); } /** @@ -46,7 +36,7 @@ contract OnchainTrigger is Ownable, PlugBase { * @return The transaction ID of the onchain message */ function propagateToAnother(uint32 targetChain) external returns (bytes32) { - //return _callAppGateway(abi.encode(PROPAGATE_TO_ANOTHER, abi.encode(value, targetChain)), bytes32(0)); + return IOnchainAppGateway(address(socket__)).propagateToChain(value, targetChain); } /** diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 3963726..b533da9 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; -import "./OnchainTrigger.sol"; import "./IOnchainTrigger.sol"; +import "./OnchainTrigger.sol"; /** * @title OnchainTriggerAppGateway @@ -83,30 +83,25 @@ contract OnchainTriggerAppGateway is AppGatewayBase { } /** - * @notice Handles incoming messages from OnchainTrigger contracts - * @dev Processes different message types from OnchainTrigger contracts + * @notice Updates AppGateway value from OnchainTrigger contracts + * @dev Updates AppGateway value from OnchainTrigger contracts + * The onlyWatcherPrecompile modifier ensures the function can only be called by the watcher + * @param value Value to update from the onchain contract on AppGateway + */ + function callFromChain(uint256 value) external async(bytes("")) onlyWatcherPrecompile { + valueOnGateway += value; + } + + /** + * @notice Updates OnchainTrigger contract value from another OnchainTrigger contract + * @dev Updates OnchainTrigger contract value from another OnchainTrigger contract * The onlyWatcherPrecompile modifier ensures the function can only be called by the watcher - * chainSlug_ The identifier of the source chain (unused) - * sourceAddress The address of the sender contract (unused) - * @param payload_ The encoded message data containing the message type and payload - * msgId The transaction identifier (unused) + * @param value Value to update on the other OnchainTrigger contract + * @param targetChain Chain where the value should be updated */ - function callFromChain(uint32, address, bytes32, bytes calldata payload_) - external - async(bytes("")) - 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 onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; - IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(valueOnchain); - } else { - revert("OnchainTriggerGateway: invalid message type"); - } + function propagateToChain(uint256 value, uint32 targetChain) external async(bytes("")) onlyWatcherPrecompile { + address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; + IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(value); } /** From 2aae2a37f62fe4819af5a56196b49dbbecfa999f Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Thu, 22 May 2025 13:51:18 +0100 Subject: [PATCH 16/16] Increase await events timeout to 180sec --- script/run-evmx-apps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 8ca2721..44b60c1 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -474,7 +474,7 @@ withdraw_funds() { await_events() { local expected_new_events=$1 # Number of new events to expect local event=$2 # Event ABI - local timeout=60 # Maximum wait time in seconds + local timeout=180 # Maximum wait time in seconds local interval=2 # Check every 2 seconds local elapsed=0 # Time elapsed