diff --git a/script/checkCounters.s.sol b/script/checkCounters.s.sol deleted file mode 100644 index 0224058..0000000 --- a/script/checkCounters.s.sol +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; -import {CounterDeployer} from "../src/CounterDeployer.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CheckCounters is Script { - // bytes32 public counter = keccak256(abi.encode("counter")); - - function run() external { - CounterDeployer deployer = CounterDeployer( - vm.envAddress("COUNTER_DEPLOYER") - ); - - vm.createSelectFork(vm.envString("SOCKET_RPC")); - address counterInstanceArbitrumSepolia = deployer.getOnChainAddress( - deployer.counter(), - 421614 - ); - address counterInstanceOptimismSepolia = deployer.getOnChainAddress( - deployer.counter(), - 11155420 - ); - address counterInstanceBaseSepolia = deployer.getOnChainAddress( - deployer.counter(), - 84532 - ); - - if (counterInstanceArbitrumSepolia != address(0)) { - vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); - uint256 counterValueArbitrumSepolia = Counter( - counterInstanceArbitrumSepolia - ).counter(); - console.log( - "Counter value on Arbitrum Sepolia: ", - counterValueArbitrumSepolia - ); - } else { - console.log("Counter not yet deployed on Arbitrum Sepolia"); - } - - if (counterInstanceOptimismSepolia != address(0)) { - vm.createSelectFork(vm.envString("OPTIMISM_SEPOLIA_RPC")); - uint256 counterValueOptimismSepolia = Counter( - counterInstanceOptimismSepolia - ).counter(); - console.log( - "Counter value on Optimism Sepolia: ", - counterValueOptimismSepolia - ); - } else { - console.log("Counter not yet deployed on Optimism Sepolia"); - } - - if (counterInstanceBaseSepolia != address(0)) { - vm.createSelectFork(vm.envString("BASE_SEPOLIA_RPC")); - uint256 counterValueBaseSepolia = Counter( - counterInstanceBaseSepolia - ).counter(); - console.log( - "Counter value on Base Sepolia: ", - counterValueBaseSepolia - ); - } else { - console.log("Counter not yet deployed on Base Sepolia"); - } - } -} diff --git a/script/counter/checkCounters.s.sol b/script/counter/checkCounters.s.sol new file mode 100644 index 0000000..3d9c76b --- /dev/null +++ b/script/counter/checkCounters.s.sol @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {Script} from "forge-std/Script.sol"; +import {console} from "forge-std/console.sol"; +import {CounterDeployer} from "../../src/counter/CounterDeployer.sol"; +import {Counter} from "../../src/counter/Counter.sol"; + +contract CheckCounters is Script { + // bytes32 public counter = keccak256(abi.encode("counter")); + + function run() external { + CounterDeployer deployer = CounterDeployer(vm.envAddress("COUNTER_DEPLOYER")); + + vm.createSelectFork(vm.envString("SOCKET_RPC")); + address counterInstanceArbitrumSepolia = deployer.getOnChainAddress(deployer.counter(), 421614); + address counterInstanceOptimismSepolia = deployer.getOnChainAddress(deployer.counter(), 11155420); + address counterInstanceBaseSepolia = deployer.getOnChainAddress(deployer.counter(), 84532); + //address counterInstanceSepolia = deployer.getOnChainAddress( + // deployer.counter(), + // 11155111 + //); + + if (counterInstanceArbitrumSepolia != address(0)) { + vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); + uint256 counterValueArbitrumSepolia = Counter(counterInstanceArbitrumSepolia).counter(); + console.log("Counter value on Arbitrum Sepolia: ", counterValueArbitrumSepolia); + } else { + console.log("Counter not yet deployed on Arbitrum Sepolia"); + } + + if (counterInstanceOptimismSepolia != address(0)) { + vm.createSelectFork(vm.envString("OPTIMISM_SEPOLIA_RPC")); + uint256 counterValueOptimismSepolia = Counter(counterInstanceOptimismSepolia).counter(); + console.log("Counter value on Optimism Sepolia: ", counterValueOptimismSepolia); + } else { + console.log("Counter not yet deployed on Optimism Sepolia"); + } + + if (counterInstanceBaseSepolia != address(0)) { + vm.createSelectFork(vm.envString("BASE_SEPOLIA_RPC")); + uint256 counterValueBaseSepolia = Counter(counterInstanceBaseSepolia).counter(); + console.log("Counter value on Base Sepolia: ", counterValueBaseSepolia); + } else { + console.log("Counter not yet deployed on Base Sepolia"); + } + + //if (counterInstanceSepolia != address(0)) { + // vm.createSelectFork(vm.envString("SEPOLIA_RPC")); + // uint256 counterValueOptimismSepolia = Counter( + // counterInstanceOptimismSepolia + // ).counter(); + // console.log( + // "Counter value on Ethereum Sepolia: ", + // counterValueOptimismSepolia + // ); + //} else { + // console.log("Counter not yet deployed on Ethereum Sepolia"); + //} + } +} diff --git a/script/Deploy.s.sol b/script/counter/deployCounterOffchain.s.sol similarity index 61% rename from script/Deploy.s.sol rename to script/counter/deployCounterOffchain.s.sol index 6159731..a69b3f7 100644 --- a/script/Deploy.s.sol +++ b/script/counter/deployCounterOffchain.s.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {CounterAppGateway} from "../src/CounterAppGateway.sol"; -import {CounterDeployer} from "../src/CounterDeployer.sol"; +import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol"; +import {CounterDeployer} from "../../src/counter/CounterDeployer.sol"; import {FeesData} from "lib/socket-protocol/contracts/common/Structs.sol"; import {ETH_ADDRESS} from "lib/socket-protocol/contracts/common/Constants.sol"; @@ -19,22 +19,11 @@ contract CounterDeploy is Script { vm.startBroadcast(deployerPrivateKey); // Setting fee payment on Arbitrum Sepolia - FeesData memory feesData = FeesData({ - feePoolChain: 421614, - feePoolToken: ETH_ADDRESS, - maxFees: 0.01 ether - }); - - CounterDeployer deployer = new CounterDeployer( - addressResolver, - feesData - ); - - CounterAppGateway gateway = new CounterAppGateway( - addressResolver, - address(deployer), - feesData - ); + FeesData memory feesData = FeesData({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, maxFees: 0.01 ether}); + + CounterDeployer deployer = new CounterDeployer(addressResolver, feesData); + + CounterAppGateway gateway = new CounterAppGateway(addressResolver, address(deployer), feesData); console.log("Contracts deployed:"); console.log("CounterDeployer:", address(deployer)); diff --git a/script/deployOnchain.s.sol b/script/counter/deployCounterOnchain.s.sol similarity index 77% rename from script/deployOnchain.s.sol rename to script/counter/deployCounterOnchain.s.sol index 597c698..e2d8f4c 100644 --- a/script/deployOnchain.s.sol +++ b/script/counter/deployCounterOnchain.s.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {CounterDeployer} from "../src/CounterDeployer.sol"; +import {CounterDeployer} from "../../src/counter/CounterDeployer.sol"; import {ETH_ADDRESS} from "lib/socket-protocol/contracts/common/Constants.sol"; contract CounterDeployOnchain is Script { @@ -15,9 +15,7 @@ contract CounterDeployOnchain is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - CounterDeployer deployer = CounterDeployer( - vm.envAddress("COUNTER_DEPLOYER") - ); + CounterDeployer deployer = CounterDeployer(vm.envAddress("COUNTER_DEPLOYER")); console.log("Counter Deployer:", address(deployer)); @@ -27,5 +25,7 @@ contract CounterDeployOnchain is Script { deployer.deployContracts(11155420); console.log("Deploying contracts on Base Sepolia..."); deployer.deployContracts(84532); + //console.log("Deploying contracts on Ethereum Sepolia..."); + //deployer.deployContracts(11155111); } } diff --git a/script/incrementCounters.s.sol b/script/counter/incrementCounters.s.sol similarity index 64% rename from script/incrementCounters.s.sol rename to script/counter/incrementCounters.s.sol index 204cf5d..ac991b2 100644 --- a/script/incrementCounters.s.sol +++ b/script/counter/incrementCounters.s.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.0; import {Script} from "forge-std/Script.sol"; import {console} from "forge-std/console.sol"; -import {CounterDeployer} from "../src/CounterDeployer.sol"; -import {CounterAppGateway} from "../src/CounterAppGateway.sol"; +import {CounterDeployer} from "../../src/counter/CounterDeployer.sol"; +import {CounterAppGateway} from "../../src/counter/CounterAppGateway.sol"; contract IncrementCounters is Script { function run() external { @@ -13,36 +13,23 @@ contract IncrementCounters is Script { vm.createSelectFork(socketRPC); - CounterDeployer deployer = CounterDeployer( - vm.envAddress("COUNTER_DEPLOYER") - ); - CounterAppGateway gateway = CounterAppGateway( - vm.envAddress("COUNTER_APP_GATEWAY") - ); + CounterDeployer deployer = CounterDeployer(vm.envAddress("COUNTER_DEPLOYER")); + CounterAppGateway gateway = CounterAppGateway(vm.envAddress("COUNTER_APP_GATEWAY")); - address counterForwarderArbitrumSepolia = deployer.forwarderAddresses( - deployer.counter(), - 421614 - ); - address counterForwarderOptimismSepolia = deployer.forwarderAddresses( - deployer.counter(), - 11155420 - ); - address counterForwarderBaseSepolia = deployer.forwarderAddresses( - deployer.counter(), - 84532 - ); - address counterForwarderSepolia = deployer.forwarderAddresses( - deployer.counter(), - 11155111 - ); + address counterForwarderArbitrumSepolia = deployer.forwarderAddresses(deployer.counter(), 421614); + address counterForwarderOptimismSepolia = deployer.forwarderAddresses(deployer.counter(), 11155420); + address counterForwarderBaseSepolia = deployer.forwarderAddresses(deployer.counter(), 84532); + //address counterForwarderSepolia = deployer.forwarderAddresses( + // deployer.counter(), + // 11155111 + //); // Count non-zero addresses uint256 nonZeroCount = 0; if (counterForwarderArbitrumSepolia != address(0)) nonZeroCount++; if (counterForwarderOptimismSepolia != address(0)) nonZeroCount++; if (counterForwarderBaseSepolia != address(0)) nonZeroCount++; - if (counterForwarderSepolia != address(0)) nonZeroCount++; + //if (counterForwarderSepolia != address(0)) nonZeroCount++; address[] memory instances = new address[](nonZeroCount); uint256 index = 0; @@ -64,12 +51,12 @@ contract IncrementCounters is Script { } else { console.log("Base Sepolia forwarder not yet deployed"); } - if (counterForwarderSepolia != address(0)) { - instances[index] = counterForwarderSepolia; - index++; - } else { - console.log("Sepolia forwarder not yet deployed"); - } + //if (counterForwarderSepolia != address(0)) { + // instances[index] = counterForwarderSepolia; + // index++; + //} else { + // console.log("Ethereum Sepolia forwarder not yet deployed"); + //} vm.startBroadcast(deployerPrivateKey); gateway.incrementCounters(instances); diff --git a/script/transactionStatus.js b/script/transactionStatus.js index 19f66e1..7680d5b 100644 --- a/script/transactionStatus.js +++ b/script/transactionStatus.js @@ -34,7 +34,12 @@ const apiUrl = 'https://apiv2.dev.socket.tech/getDetailsByTxHash?txHash='; let intervalId; // Track statuses for each hash -let statusTracker = transactions.map(hash => ({ hash, status: 'PENDING', printed: false })); +let statusTracker = transactions.map(hash => ({ + hash, + status: 'PENDING', + printed: false, + printedPayloads: new Set() +})); let allDonePrinted = false; // Prevent multiple prints of the final message // Function to perform API requests @@ -50,10 +55,26 @@ const fetchTransactionStatus = async (hash) => { } }; +const processMultiplePayloads = (payloads, tx) => { + if (payloads.length > 1) { + payloads.forEach(payload => { + // Create a unique key for the payload to track printed status + const payloadKey = `${payload.executeDetails.executeTxHash}-${payload.callBackDetails.callbackStatus}`; + + if (payload.callBackDetails.callbackStatus === 'PROMISE_RESOLVED' && + payload.executeDetails.executeTxHash && + !tx.printedPayloads.has(payloadKey)) { + console.log(`Hash: ${payload.executeDetails.executeTxHash}, Status: ${payload.callBackDetails.callbackStatus}, ChainId: ${payload.chainSlug}`); + + tx.printedPayloads.add(payloadKey); + } + }); + } +}; + // Function to check transaction status const checkTransactionStatus = async () => { let allCompleted = true; - for (let i = 0; i < statusTracker.length; i++) { const tx = statusTracker[i]; @@ -76,26 +97,28 @@ const checkTransactionStatus = async () => { const transactionResponse = data.response[0]; // First response object const status = transactionResponse.status || 'UNKNOWN'; - const payload = transactionResponse.payloads?.[0]; - const chainSlug = payload?.chainSlug || 'N/A'; + const payloads = transactionResponse.payloads || []; // Update tracker tx.status = status; - if (status === 'COMPLETED' && !tx.printed) { - const deployerDetails = payload?.deployerDetails || {}; - console.log(`Hash: ${tx.hash}, Status: ${status}, ChainId: ${chainSlug}`); + processMultiplePayloads(payloads, tx); + + const deployerDetails = payloads[0].deployerDetails || {}; if (Object.keys(deployerDetails).length !== 0) { - const onChainAddress = deployerDetails.onChainAddress; - const forwarderAddress = deployerDetails.forwarderAddress; - console.log(`OnChainAddress: ${onChainAddress}`); - console.log(`ForwarderAddress: ${forwarderAddress}`); + console.log(`Hash: ${tx.hash}, Status: ${status}, ChainId: ${payloads[0].chainSlug}`); + console.log(`OnChainAddress: ${deployerDetails.onChainAddress}`); + console.log(`ForwarderAddress: ${deployerDetails.forwarderAddress}`); + } else { + console.log(`Hash: ${tx.hash}, Status: ${status}, ChainId: 7625382`); } - // Mark this transaction as printed tx.printed = true; } + else if (status === 'IN_PROGRESS') { + processMultiplePayloads(payloads, tx); + } } else { console.error(`Invalid or empty response for hash: ${tx.hash}`); } @@ -114,4 +137,4 @@ const checkTransactionStatus = async () => { // Start periodic polling every second console.log('Starting to monitor transaction statuses...'); -intervalId = setInterval(checkTransactionStatus, 1000); +intervalId = setInterval(checkTransactionStatus, 2000); diff --git a/src/Counter.sol b/src/counter/Counter.sol similarity index 100% rename from src/Counter.sol rename to src/counter/Counter.sol diff --git a/src/CounterAppGateway.sol b/src/counter/CounterAppGateway.sol similarity index 80% rename from src/CounterAppGateway.sol rename to src/counter/CounterAppGateway.sol index 2d95f2d..dfff98d 100644 --- a/src/CounterAppGateway.sol +++ b/src/counter/CounterAppGateway.sol @@ -5,11 +5,9 @@ import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./Counter.sol"; contract CounterAppGateway is AppGatewayBase { - constructor( - address _addressResolver, - address deployerContract_, - FeesData memory feesData_ - ) AppGatewayBase(_addressResolver) { + constructor(address _addressResolver, address deployerContract_, FeesData memory feesData_) + AppGatewayBase(_addressResolver) + { addressResolver.setContractsToGateways(deployerContract_); _setFeesData(feesData_); } diff --git a/src/CounterDeployer.sol b/src/counter/CounterDeployer.sol similarity index 86% rename from src/CounterDeployer.sol rename to src/counter/CounterDeployer.sol index 5c61280..7329a8b 100644 --- a/src/CounterDeployer.sol +++ b/src/counter/CounterDeployer.sol @@ -7,10 +7,7 @@ import "socket-protocol/contracts/base/AppDeployerBase.sol"; contract CounterDeployer is AppDeployerBase { bytes32 public counter = _createContractId("counter"); - constructor( - address addressResolver_, - FeesData memory feesData_ - ) AppDeployerBase(addressResolver_) { + constructor(address addressResolver_, FeesData memory feesData_) AppDeployerBase(addressResolver_) { creationCodeWithArgs[counter] = type(Counter).creationCode; _setFeesData(feesData_); } diff --git a/test/Counter.t.sol b/test/Counter.t.sol index ccc31e3..96594d3 100644 --- a/test/Counter.t.sol +++ b/test/Counter.t.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.13; import "socket-protocol/test/AuctionHouse.sol"; -import {Counter} from "../src/Counter.sol"; -import {CounterAppGateway} from "../src/CounterAppGateway.sol"; -import {CounterDeployer} from "../src/CounterDeployer.sol"; +import {Counter} from "../src/counter/Counter.sol"; +import {CounterAppGateway} from "../src/counter/CounterAppGateway.sol"; +import {CounterDeployer} from "../src/counter/CounterDeployer.sol"; contract CounterTest is AuctionHouseTest { CounterDeployer public counterDeployer; @@ -15,62 +15,29 @@ contract CounterTest is AuctionHouseTest { // core setUpAuctionHouse(); - FeesData memory feesData = FeesData({ - feePoolChain: arbChainSlug, - feePoolToken: ETH_ADDRESS, - maxFees: 100000000000000 - }); - counterDeployer = new CounterDeployer( - address(addressResolver), - feesData - ); - counterAppGateway = new CounterAppGateway( - address(addressResolver), - address(counterDeployer), - feesData - ); + FeesData memory feesData = + FeesData({feePoolChain: arbChainSlug, feePoolToken: ETH_ADDRESS, maxFees: 100000000000000}); + counterDeployer = new CounterDeployer(address(addressResolver), feesData); + counterAppGateway = new CounterAppGateway(address(addressResolver), address(counterDeployer), feesData); counterId = counterDeployer.counter(); } function testDeploy() public { - bytes32[] memory payloadIds = getWritePayloadIds( - arbChainSlug, - getPayloadDeliveryPlug(arbChainSlug), - 1 - ); + bytes32[] memory payloadIds = getWritePayloadIds(arbChainSlug, getPayloadDeliveryPlug(arbChainSlug), 1); PayloadDetails[] memory payloadDetails = new PayloadDetails[](1); payloadDetails[0] = createDeployPayloadDetail( - arbChainSlug, - address(counterDeployer), - counterDeployer.creationCodeWithArgs(counterId) - ); - payloadDetails[0].next[1] = predictAsyncPromiseAddress( - address(auctionHouse), - address(auctionHouse) + arbChainSlug, address(counterDeployer), counterDeployer.creationCodeWithArgs(counterId) ); + payloadDetails[0].next[1] = predictAsyncPromiseAddress(address(auctionHouse), address(auctionHouse)); - _deploy( - payloadIds, - arbChainSlug, - maxFees, - IAppDeployer(counterDeployer), - payloadDetails - ); + _deploy(payloadIds, arbChainSlug, maxFees, IAppDeployer(counterDeployer), payloadDetails); - address counterForwarder = counterDeployer.forwarderAddresses( - counterId, - arbChainSlug - ); - address deployedCounter = IForwarder(counterForwarder) - .getOnChainAddress(); + address counterForwarder = counterDeployer.forwarderAddresses(counterId, arbChainSlug); + address deployedCounter = IForwarder(counterForwarder).getOnChainAddress(); - payloadIds = getWritePayloadIds( - arbChainSlug, - getPayloadDeliveryPlug(arbChainSlug), - 1 - ); + payloadIds = getWritePayloadIds(arbChainSlug, getPayloadDeliveryPlug(arbChainSlug), 1); payloadDetails = new PayloadDetails[](1); payloadDetails[0] = createExecutePayloadDetail( @@ -78,22 +45,11 @@ contract CounterTest is AuctionHouseTest { deployedCounter, address(counterDeployer), counterForwarder, - abi.encodeWithSignature( - "setSocket(address)", - counterDeployer.getSocketAddress(arbChainSlug) - ) + abi.encodeWithSignature("setSocket(address)", counterDeployer.getSocketAddress(arbChainSlug)) ); - payloadDetails[0].next[1] = predictAsyncPromiseAddress( - address(auctionHouse), - address(auctionHouse) - ); + payloadDetails[0].next[1] = predictAsyncPromiseAddress(address(auctionHouse), address(auctionHouse)); - _configure( - payloadIds, - address(counterAppGateway), - maxFees, - payloadDetails - ); + _configure(payloadIds, address(counterAppGateway), maxFees, payloadDetails); } }