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" 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 diff --git a/script/SetupScript.sol b/script/SetupScript.sol index bf1e791..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; @@ -30,30 +29,21 @@ 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)); - 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/script/run-evmx-apps.sh b/script/run-evmx-apps.sh index 8311286..44b60c1 100644 --- a/script/run-evmx-apps.sh +++ b/script/run-evmx-apps.sh @@ -88,10 +88,11 @@ 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 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" } @@ -113,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}') @@ -137,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." @@ -261,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 @@ -296,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 @@ -341,75 +347,71 @@ 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 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 fi - # 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 + 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 - - 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 } @@ -420,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 @@ -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 @@ -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 @@ -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}" 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 8d1b7eb..9ef47e0 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"; @@ -48,14 +48,14 @@ 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); 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_); } /** @@ -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 f361c4c..0a6ba00 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"; /** @@ -31,8 +31,8 @@ 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_) { - _setOverrides(fees_); + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { + _setMaxFees(fees_); } /** @@ -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 e9f66f5..285f665 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"; @@ -41,9 +41,9 @@ 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_); + _setMaxFees(fees_); values = new uint256[](10); } @@ -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 81cfa80..5c592d6 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"; @@ -26,9 +26,9 @@ 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_); + _setMaxFees(fees_); } /** @@ -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 69bc537..9164f45 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 @@ -30,8 +30,8 @@ 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_) { - _setOverrides(fees_); + constructor(address addressResolver_, uint256 fees_) AppGatewayBase(addressResolver_) { + _setMaxFees(fees_); } /** @@ -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/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 4dfc668..f6b6ad2 100644 --- a/src/trigger-appgateway-onchain/OnchainTrigger.sol +++ b/src/trigger-appgateway-onchain/OnchainTrigger.sol @@ -2,7 +2,9 @@ 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"; + +import "./IOnchainAppGateway.sol"; /** * @title OnchainTrigger @@ -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 ea7af3d..b533da9 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; -import "socket-protocol/contracts/base/AppGatewayBase.sol"; -import "./OnchainTrigger.sol"; +import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; import "./IOnchainTrigger.sol"; +import "./OnchainTrigger.sol"; /** * @title OnchainTriggerAppGateway @@ -48,9 +48,9 @@ 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_); + _setMaxFees(fees_); } /** @@ -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,46 +77,31 @@ 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); } /** - * @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 - * 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 from the onchain contract on AppGateway */ - function callFromChain(uint32, address, bytes32, bytes calldata payload_) - external - override - async - 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 callFromChain(uint256 value) external async(bytes("")) onlyWatcherPrecompile { + valueOnGateway += value; } /** - * @notice Updates the fee configuration - * @dev Allows modification of fee settings for onchain operations - * @param fees_ New fee configuration + * @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 + * @param value Value to update on the other OnchainTrigger contract + * @param targetChain Chain where the value should be updated */ - function setFees(Fees memory fees_) public { - fees = fees_; + function propagateToChain(uint256 value, uint32 targetChain) external async(bytes("")) onlyWatcherPrecompile { + address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; + IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(value); } /** diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 37dabd9..1f5377f 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"; @@ -33,9 +33,9 @@ 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_); + _setMaxFees(fees_); } /** @@ -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 @@ -129,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_; + } } 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_); - } }