From ce4df91ccf2d3955eaaf0b55fc52ff787affcadb Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 10:24:59 +0100 Subject: [PATCH 01/39] Update socket-protocol submodule to latest dev --- .gitmodules | 2 +- lib/socket-protocol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index b41225c..c6035df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,4 @@ [submodule "lib/socket-protocol"] path = lib/socket-protocol url = https://github.com/SocketDotTech/socket-protocol.git - branch = master + branch = dev diff --git a/lib/socket-protocol b/lib/socket-protocol index 38accd5..e33312e 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit 38accd5f8a4144297048940122d56a08578c1783 +Subproject commit e33312e550e726bad472a2ade011f35d6ba3315e From c5dda8ab3da3e6b9fcfb38a0eda1de53016da2d4 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 10:59:10 +0100 Subject: [PATCH 02/39] chore: change DeliveryHelper.t.sol to SetupTest.t.sol --- test/Dummy.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Dummy.t.sol b/test/Dummy.t.sol index 1d0e27e..5707dd4 100644 --- a/test/Dummy.t.sol +++ b/test/Dummy.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.21; -import "socket-protocol/test/DeliveryHelper.t.sol"; +import "socket-protocol/test/SetupTest.t.sol"; -contract DummyTest is DeliveryHelperTest { +contract DummyTest is AppGatewayBaseSetup { function testDummy() external {} } From dc7d779e915baefe02bfad5b2e231ced9230a9ac Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:01:34 +0100 Subject: [PATCH 03/39] chore: update initialize to initializeOnChain --- 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 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 9ef47e0..84e5d83 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -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(bytes("")) { + function initializeOnChain(uint32 chainSlug_) public override async(bytes("")) { PlugInitializeTwice(forwarderAddresses[plugInitializeTwice][chainSlug_]).initialise(10); PlugNoInitInitialize(forwarderAddresses[plugNoInitInitialize][chainSlug_]).initialise(10); } diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 0a6ba00..8a16bee 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -47,7 +47,7 @@ contract UploadAppGateway is AppGatewayBase { * @dev Required by AppGatewayBase but not used in this implementation * @param chainSlug_ The identifier of the chain (unused) */ - function initialize(uint32 chainSlug_) public override {} + function initializeOnChain(uint32 chainSlug_) public override {} /** * @notice Uploads an existing onchain contract to EVMx diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 285f665..c9e8128 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -61,7 +61,7 @@ contract ReadAppGateway is AppGatewayBase { * @dev No initialization needed for this application, so implementation is empty. * The chainSlug parameter is required by the interface but not used. */ - function initialize(uint32) public pure override { + function initializeOnChain(uint32) public pure override { return; } diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 5c592d6..8dce912 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -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(bytes("")) { + function initializeOnChain(uint32 chainSlug_) public override async(bytes("")) { address instance = forwarderAddresses[counter][chainSlug_]; ICounter(instance).increment(); } diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 9164f45..b731d47 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -48,7 +48,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @dev No initialization needed for this application, so implementation is empty. * The chainSlug parameter is required by the interface but not used. */ - function initialize(uint32) public pure override { + function initializeOnChain(uint32) public pure override { return; } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index b533da9..9b998f2 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -67,7 +67,7 @@ contract OnchainTriggerAppGateway 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 { + function initializeOnChain(uint32 chainSlug_) public override { address onchainAddress = getOnChainAddress(onchainToEVMx, chainSlug_); watcherPrecompileConfig().setIsValidPlug(chainSlug_, onchainAddress, true); } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 1f5377f..a9d94f2 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -52,7 +52,7 @@ contract WriteAppGateway is AppGatewayBase { * @dev No initialization needed for this application, so implementation is empty. * The chainSlug parameter is required by the interface but not used. */ - function initialize(uint32) public pure override { + function initializeOnChain(uint32) public pure override { return; } From 81deadf5461c3f9dd292cf90d5bcfe7470d0cb75 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:06:42 +0100 Subject: [PATCH 04/39] chore: update withdrawFeeTokens to withdrawCredits --- script/utils/fees-manager.ts | 4 ++-- src/deploy/DeploymentAppGateway.sol | 4 ++-- src/forwarder-on-evmx/UploadAppGateway.sol | 4 ++-- src/read/ReadAppGateway.sol | 4 ++-- src/revert/RevertAppGateway.sol | 4 ++-- src/schedule/ScheduleAppGateway.sol | 4 ++-- src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol | 4 ++-- src/write/WriteAppGateway.sol | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index 0aefa6e..d0f0ddd 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -124,12 +124,12 @@ export async function withdrawFunds( if (amountToWithdraw > 0n) { const abi = parseAbi([ - 'function withdrawFeeTokens(uint32 chainId, address token, uint256 amount, address to) external' + 'function withdrawCredits(uint32 chainId, address token, uint256 amount, address to) external' ]); await sendTransaction( appGateway, - 'withdrawFeeTokens', + 'withdrawCredits', [CHAIN_IDS.ARB_SEP, process.env.ARBITRUM_TEST_USDC, amountToWithdraw, arbChain.walletClient.account?.address], evmxChain, abi diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 84e5d83..e37d175 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -170,7 +170,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } } diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 8a16bee..9b8c035 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -94,7 +94,7 @@ contract UploadAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index c9e8128..28004cd 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -123,8 +123,8 @@ contract ReadAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } /** diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 8dce912..8d63d97 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -97,7 +97,7 @@ contract RevertAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } } diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index b731d47..0617529 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -81,7 +81,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 9b998f2..4de19d4 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -112,7 +112,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index a9d94f2..d31e375 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -117,8 +117,8 @@ contract WriteAppGateway is AppGatewayBase { * @param amount_ The amount to withdraw * @param receiver_ The address that will receive the withdrawn fees */ - function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); + function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { + _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } /** From 5cc291965ab25ce6b4aa1b26b5fc5c273020ce14 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:08:17 +0100 Subject: [PATCH 05/39] chore: update timeouts to schedules --- script/tests/scheduler_tests.ts | 38 ++++++++++++++--------------- src/schedule/ScheduleAppGateway.sol | 38 ++++++++++++++--------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/script/tests/scheduler_tests.ts b/script/tests/scheduler_tests.ts index 55616b1..98136ef 100644 --- a/script/tests/scheduler_tests.ts +++ b/script/tests/scheduler_tests.ts @@ -10,53 +10,53 @@ export async function runSchedulerTests( appGateway: Address, evmxChain: ChainConfig ): Promise { - console.log(`${COLORS.CYAN}Reading timeouts from the contract:${COLORS.NC}`); + console.log(`${COLORS.CYAN}Reading schedules from the contract:${COLORS.NC}`); const abi = parseAbi([ - 'function timeoutsInSeconds(uint256) external view returns (uint256)', - 'function triggerTimeouts() external' + 'function schedulesInSeconds(uint256) external view returns (uint256)', + 'function triggerSchedules() external' ]); - let maxTimeout = 0; - let numberOfTimeouts = 0; + let maxSchedule = 0; + let numberOfSchedules = 0; while (true) { try { - const timeout = await evmxChain.client.readContract({ + const schedule = await evmxChain.client.readContract({ address: appGateway, abi, - functionName: 'timeoutsInSeconds', - args: [numberOfTimeouts] + functionName: 'schedulesInSeconds', + args: [numberOfSchedules] }) as number; - if (timeout === 0) break; + if (schedule === 0) break; - console.log(`Timeout ${numberOfTimeouts}: ${timeout} seconds`); - numberOfTimeouts++; + console.log(`Schedule ${numberOfSchedules}: ${schedule} seconds`); + numberOfSchedules++; - if (timeout > maxTimeout) { - maxTimeout = timeout; + if (schedule > maxSchedule) { + maxSchedule = schedule; } } catch (error) { break; } } - console.log(`${COLORS.CYAN}Triggering timeouts...${COLORS.NC}`); + console.log(`${COLORS.CYAN}Triggering schedules...${COLORS.NC}`); await sendTransaction( appGateway, - 'triggerTimeouts', + 'triggerSchedules', [], evmxChain, abi ); - console.log(`${COLORS.CYAN}Fetching TimeoutResolved events...${COLORS.NC}`); + console.log(`${COLORS.CYAN}Fetching ScheduleResolved events...${COLORS.NC}`); - await awaitEvents(numberOfTimeouts, 'TimeoutResolved(uint256,uint256,uint256)', appGateway, evmxChain, Number(maxTimeout)); + await awaitEvents(numberOfSchedules, 'ScheduleResolved(uint256,uint256,uint256)', appGateway, evmxChain, Number(maxSchedule)); const logs = await evmxChain.client.getLogs({ address: appGateway, - event: parseAbi(['event TimeoutResolved(uint256,uint256,uint256)'])[0], + event: parseAbi(['event ScheduleResolved(uint256,uint256,uint256)'])[0], fromBlock: 'earliest', toBlock: 'latest' }); @@ -69,7 +69,7 @@ export async function runSchedulerTests( const creationTimestamp = BigInt('0x' + dataHex.slice(64, 128)); const executionTimestamp = BigInt('0x' + dataHex.slice(128, 192)); - console.log(`${COLORS.GREEN}Timeout Resolved:${COLORS.NC}`); + console.log(`${COLORS.GREEN}Schedule Resolved:${COLORS.NC}`); console.log(` Index: ${index}`); console.log(` Created at: ${creationTimestamp}`); console.log(` Executed at: ${executionTimestamp}`); diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 0617529..cc9ed54 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -11,18 +11,18 @@ import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; */ contract ScheduleAppGateway is AppGatewayBase { /** - * @notice Array of timeout durations in seconds + * @notice Array of schedule durations in seconds * @dev These values define the delay periods in seconds for scheduled executions */ - uint256[] public timeoutsInSeconds = [1, 20, 60, 120, 600, 1200, 5000]; + uint256[] public schedulesInSeconds = [1, 20, 60, 120, 600, 1200, 5000]; /** - * @notice Emitted when a scheduled timeout is resolved - * @param index The index of the timeout in the timeoutsInSeconds array - * @param creationTimestamp The timestamp when the timeout was created - * @param executionTimestamp The timestamp when the timeout was executed + * @notice Emitted when a scheduled schedule is resolved + * @param index The index of the schedule in the schedulesInSeconds array + * @param creationTimestamp The timestamp when the schedule was created + * @param executionTimestamp The timestamp when the schedule was executed */ - event TimeoutResolved(uint256 index, uint256 creationTimestamp, uint256 executionTimestamp); + event ScheduleResolved(uint256 index, uint256 creationTimestamp, uint256 executionTimestamp); /** * @notice Constructs the ScheduleAppGateway @@ -53,24 +53,24 @@ contract ScheduleAppGateway is AppGatewayBase { } /** - * @notice Triggers multiple timeouts with different delay periods - * @dev Sets up scheduled calls to resolveTimeout with various delay periods defined in timeoutsInSeconds + * @notice Triggers multiple schedules with different delay periods + * @dev Sets up scheduled calls to resolveSchedule with various delay periods defined in schedulesInSeconds */ - function triggerTimeouts() public { - for (uint256 i = 0; i < timeoutsInSeconds.length; i++) { - bytes memory payload = abi.encodeWithSelector(this.resolveTimeout.selector, i, block.timestamp); - watcherPrecompile__().setTimeout(timeoutsInSeconds[i], payload); + function triggerSchedules() public { + for (uint256 i = 0; i < schedulesInSeconds.length; i++) { + _setSchedule(schedulesInSeconds[i]); + then(this.resolveSchedule.selector, abi.encode(i, block.timestamp)); } } /** - * @notice Callback function executed when a timeout is reached - * @dev Emits a TimeoutResolved event with timing information - * @param index_ The index of the timeout in the timeoutsInSeconds array - * @param creationTimestamp_ The timestamp when the timeout was created + * @notice Callback function executed when a schedule is reached + * @dev Emits a ScheduleResolved event with timing information + * @param index_ The index of the schedule in the schedulesInSeconds array + * @param creationTimestamp_ The timestamp when the schedule was created */ - function resolveTimeout(uint256 index_, uint256 creationTimestamp_) public { - emit TimeoutResolved(index_, creationTimestamp_, block.timestamp); + function resolveSchedule(uint256 index_, uint256 creationTimestamp_) public { + emit ScheduleResolved(index_, creationTimestamp_, block.timestamp); } /** From d8dc4503fb2e30736b0b65f52387b5b40ed16eb5 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:09:14 +0100 Subject: [PATCH 06/39] chore: change watcher precompile to watcher --- .../OnchainTriggerAppGateway.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 4de19d4..98a4364 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -68,8 +68,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param chainSlug_ The identifier of the chain where the contract was deployed */ function initializeOnChain(uint32 chainSlug_) public override { - address onchainAddress = getOnChainAddress(onchainToEVMx, chainSlug_); - watcherPrecompileConfig().setIsValidPlug(chainSlug_, onchainAddress, true); + _setValidPlug(true, chainSlug_, onchainToEVMx); } /** @@ -88,7 +87,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * 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 { + function callFromChain(uint256 value) external async(bytes("")) onlyWatcher { valueOnGateway += value; } @@ -99,7 +98,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param value Value to update on the other OnchainTrigger contract * @param targetChain Chain where the value should be updated */ - function propagateToChain(uint256 value, uint32 targetChain) external async(bytes("")) onlyWatcherPrecompile { + function propagateToChain(uint256 value, uint32 targetChain) external async(bytes("")) onlyWatcher { address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(value); } From a6c754ba53e8ca16910b2b311bdf7275ca70fb8a Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:12:27 +0100 Subject: [PATCH 07/39] chore: update constructor initialization params --- 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 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index e37d175..a7c3fa2 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { 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 9b8c035..979a823 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { _setMaxFees(fees_); } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 28004cd..f0d5f2c 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); _setMaxFees(fees_); values = new uint256[](10); diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 8d63d97..8654d0c 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode); _setMaxFees(fees_); } diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index cc9ed54..2fe2c28 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { _setMaxFees(fees_); } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 98a4364..dc7b3e3 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[onchainToEVMx] = abi.encodePacked(type(OnchainTrigger).creationCode); _setMaxFees(fees_); } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index d31e375..cd07d13 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_, uint256 fees_) AppGatewayBase(addressResolver_) { + constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); _setMaxFees(fees_); } From abd2db774cccf6dc861bfb29378c7cbb97963f3f Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:14:38 +0100 Subject: [PATCH 08/39] chore: revert modifier async(bytes()) to async --- src/deploy/DeploymentAppGateway.sol | 6 +++--- src/forwarder-on-evmx/UploadAppGateway.sol | 4 ++-- src/read/ReadAppGateway.sol | 6 +++--- src/revert/RevertAppGateway.sol | 8 ++++---- src/schedule/ScheduleAppGateway.sol | 2 +- .../OnchainTriggerAppGateway.sol | 8 ++++---- src/write/WriteAppGateway.sol | 8 ++++---- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index a7c3fa2..275e159 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.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(bytes("")) { + function deployContracts(uint32 chainSlug_) external async { _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 initializeOnChain(uint32 chainSlug_) public override async(bytes("")) { + function initializeOnChain(uint32 chainSlug_) public override async { 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(bytes("")) { + function contractValidation(uint32 chainSlug_) external async { address noPlugNoInititializeForwarder = forwarderAddresses[noPlugNoInititialize][chainSlug_]; address noPlugInitializeForwarder = forwarderAddresses[noPlugInitialize][chainSlug_]; address plugNoInitializeForwarder = forwarderAddresses[plugNoInitialize][chainSlug_]; diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 979a823..6a4edea 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.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(bytes("")) {} + function deployContracts(uint32 chainSlug_) external async {} /** * @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(bytes("")) { + function read() public async { _setOverrides(Read.ON, Parallel.ON); // TODO: Remove Parallel.ON after new contract deployment to devnet ICounter(counterForwarder).counter(); diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index f0d5f2c..54bf45b 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.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(bytes("")) { + function deployContracts(uint32 chainSlug_) external async { _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(bytes("")) { + function triggerParallelRead(address instance_) public async { _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(bytes("")) { + function triggerAltRead(address instance1_, address instance2_) public async { _setOverrides(Read.ON, Parallel.ON); for (uint256 i = 0; i < 10; i++) { if (i % 2 == 0) { diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 8654d0c..309b0fa 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.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(bytes("")) { + function deployContracts(uint32 chainSlug_) external async { _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 initializeOnChain(uint32 chainSlug_) public override async(bytes("")) { + function initializeOnChain(uint32 chainSlug_) public override async { 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(bytes("")) { + function testOnChainRevert(uint32 chainSlug) public async { 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(bytes("")) { + function testCallbackRevertWrongInputArgs(uint32 chainSlug) public async { _setOverrides(Read.ON, Parallel.ON); address instance = forwarderAddresses[counter][chainSlug]; ICounter(instance).counter(); diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 2fe2c28..9bba38f 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -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(bytes("")) { + function deployContracts(uint32) external async { return; } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index dc7b3e3..bd40a4c 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.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(bytes("")) { + function deployContracts(uint32 chainSlug_) external async { _deploy(onchainToEVMx, chainSlug_, IsPlug.YES); } @@ -76,7 +76,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(bytes("")) { + function updateOnchain(uint32 targetChain) public async { address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(valueOnGateway); } @@ -87,7 +87,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * 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("")) onlyWatcher { + function callFromChain(uint256 value) external async onlyWatcher { valueOnGateway += value; } @@ -98,7 +98,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param value Value to update on the other OnchainTrigger contract * @param targetChain Chain where the value should be updated */ - function propagateToChain(uint256 value, uint32 targetChain) external async(bytes("")) onlyWatcher { + function propagateToChain(uint256 value, uint32 targetChain) external async onlyWatcher { address onchainToEVMxForwarderAddress = forwarderAddresses[onchainToEVMx][targetChain]; IOnchainTrigger(onchainToEVMxForwarderAddress).updateFromGateway(value); } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index cd07d13..2aa1f32 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.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(bytes("")) { + function deployContracts(uint32 chainSlug_) external async { _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(bytes("")) { + function triggerSequentialWrite(address instance_) public async { 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(bytes("")) { + function triggerParallelWrite(address instance_) public async { _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(bytes("")) { + function triggerAltWrite(address instance1_, address instance2_) public async { for (uint256 i = 0; i < 5; i++) { IWriteMultichain(instance1_).increase(); IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); From 9a0d548dc673b25ece7cacf93a8565aa2ae5a353 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:43:02 +0100 Subject: [PATCH 09/39] chore: getOrDeployForwarderContract with asyncDeployer --- src/forwarder-on-evmx/UploadAppGateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 6a4edea..c1a35a2 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -56,7 +56,7 @@ contract UploadAppGateway is AppGatewayBase { * @param chainSlug_ The identifier of the chain where the contract exists */ function uploadToEVMx(address onchainContract, uint32 chainSlug_) public { - counterForwarder = addressResolver__.getOrDeployForwarderContract(address(this), onchainContract, chainSlug_); + counterForwarder = asyncDeployer__().getOrDeployForwarderContract(onchainContract, chainSlug_); } /** From 668b88a1ed80daa9f300cad25db8b939887d3400 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:47:16 +0100 Subject: [PATCH 10/39] fix: add missing _initializeAppGateway to constructor --- src/deploy/DeploymentAppGateway.sol | 1 + src/forwarder-on-evmx/UploadAppGateway.sol | 1 + src/read/ReadAppGateway.sol | 3 ++- src/revert/RevertAppGateway.sol | 1 + src/schedule/ScheduleAppGateway.sol | 1 + src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol | 1 + src/write/WriteAppGateway.sol | 1 + 7 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 275e159..f94b3ba 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -55,6 +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); + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index c1a35a2..5db9cd3 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -32,6 +32,7 @@ contract UploadAppGateway is AppGatewayBase { * @param fees_ Fee configuration for multi-chain operations */ constructor(address addressResolver_, uint256 fees_) { + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 54bf45b..147fac8 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -43,8 +43,9 @@ contract ReadAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); - _setMaxFees(fees_); values = new uint256[](10); + _initializeAppGateway(addressResolver_); + _setMaxFees(fees_); } /** diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 309b0fa..cb71ee0 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -28,6 +28,7 @@ contract RevertAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[counter] = abi.encodePacked(type(Counter).creationCode); + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 9bba38f..e1b43e7 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -31,6 +31,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @param fees_ Fee configuration for onchain operations */ constructor(address addressResolver_, uint256 fees_) { + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index bd40a4c..b6c7693 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -50,6 +50,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[onchainToEVMx] = abi.encodePacked(type(OnchainTrigger).creationCode); + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 2aa1f32..d1ffd05 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -35,6 +35,7 @@ contract WriteAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(WriteMultichain).creationCode); + _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } From 5de2358f92e402a29e050d2c8a09b3bd2c08f385 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Mon, 2 Jun 2025 11:50:18 +0100 Subject: [PATCH 11/39] chore: add license to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5d21ddc..fe1a19d 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "license": "MIT", "type": "module", "dependencies": { "dotenv": "^16.5.0", From 1d2ab034fdbcb78b6e35a27f66f418bab406ea77 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:11:08 +0100 Subject: [PATCH 12/39] fix: numberOfEvents to wait is now dynamic --- script/tests/read_tests.ts | 11 +++++++++-- script/tests/scheduler_tests.ts | 6 +++--- script/tests/upload_tests.ts | 2 +- script/tests/write_tests.ts | 14 +++++++++++--- script/utils/helpers.ts | 6 +++--- src/read/ReadAppGateway.sol | 14 ++++++++++---- src/write/WriteAppGateway.sol | 10 ++++++++-- 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/script/tests/read_tests.ts b/script/tests/read_tests.ts index 9535894..d164f0e 100644 --- a/script/tests/read_tests.ts +++ b/script/tests/read_tests.ts @@ -13,6 +13,7 @@ export async function runReadTests( console.log(`${COLORS.CYAN}Running all read tests functions...${COLORS.NC}`); const abi = parseAbi([ + 'function numberOfRequests() external view returns (uint256)', 'function triggerParallelRead(address forwarder) external', 'function triggerAltRead(address forwarder1, address forwarder2) external' ]); @@ -21,6 +22,12 @@ export async function runReadTests( throw new Error('Required addresses not found'); } + const numberOfRequests = await evmxChain.client.readContract({ + address: addresses.appGateway, + abi, + functionName: 'numberOfRequests', + }); + // 1. Trigger Parallel Read await sendTransaction( addresses.appGateway, @@ -29,7 +36,7 @@ export async function runReadTests( evmxChain, abi ); - await awaitEvents(10, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain); + await awaitEvents(numberOfRequests, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain); // 2. Trigger Alternating Read await sendTransaction( @@ -39,7 +46,7 @@ export async function runReadTests( evmxChain, abi ); - await awaitEvents(20, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain); + await awaitEvents(numberOfRequests * 2n, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain); } export async function executeReadTests( diff --git a/script/tests/scheduler_tests.ts b/script/tests/scheduler_tests.ts index 98136ef..58bf855 100644 --- a/script/tests/scheduler_tests.ts +++ b/script/tests/scheduler_tests.ts @@ -16,8 +16,8 @@ export async function runSchedulerTests( 'function triggerSchedules() external' ]); - let maxSchedule = 0; - let numberOfSchedules = 0; + let maxSchedule = 0n; + let numberOfSchedules = 0n; while (true) { try { @@ -26,7 +26,7 @@ export async function runSchedulerTests( abi, functionName: 'schedulesInSeconds', args: [numberOfSchedules] - }) as number; + }); if (schedule === 0) break; diff --git a/script/tests/upload_tests.ts b/script/tests/upload_tests.ts index 26d2c93..002450e 100644 --- a/script/tests/upload_tests.ts +++ b/script/tests/upload_tests.ts @@ -54,7 +54,7 @@ export async function runUploadTests( uploadAbi ); - await awaitEvents(1, 'ReadOnchain(address,uint256)', appGateway, evmxChain); + await awaitEvents(1n, 'ReadOnchain(address,uint256)', appGateway, evmxChain); } export async function executeUploadTests( diff --git a/script/tests/write_tests.ts b/script/tests/write_tests.ts index a3bf380..68a5c29 100644 --- a/script/tests/write_tests.ts +++ b/script/tests/write_tests.ts @@ -13,6 +13,7 @@ export async function runWriteTests( console.log(`${COLORS.CYAN}Running all write tests functions...${COLORS.NC}`); const abi = parseAbi([ + 'function numberOfRequests() external view returns (uint256)', 'function triggerSequentialWrite(address forwarder) external', 'function triggerParallelWrite(address forwarder) external', 'function triggerAltWrite(address forwarder1, address forwarder2) external' @@ -22,6 +23,13 @@ export async function runWriteTests( throw new Error('Required addresses not found'); } + const numberOfRequests = await evmxChain.client.readContract({ + address: addresses.appGateway, + abi, + functionName: 'numberOfRequests', + }); + + // 1. Trigger Sequential Write await sendTransaction( addresses.appGateway, @@ -30,7 +38,7 @@ export async function runWriteTests( evmxChain, abi ); - await awaitEvents(10, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); + await awaitEvents(numberOfRequests, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); // 2. Trigger Parallel Write await sendTransaction( @@ -40,7 +48,7 @@ export async function runWriteTests( evmxChain, abi ); - await awaitEvents(20, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); + await awaitEvents(numberOfRequests * 2n, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); // 3. Trigger Alternating Write await sendTransaction( @@ -50,7 +58,7 @@ export async function runWriteTests( evmxChain, abi ); - await awaitEvents(30, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); + await awaitEvents(numberOfRequests * 3n, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain); } export async function executeWriteTests( diff --git a/script/utils/helpers.ts b/script/utils/helpers.ts index d4ddf6f..6440518 100644 --- a/script/utils/helpers.ts +++ b/script/utils/helpers.ts @@ -85,17 +85,17 @@ export async function fetchForwarderAndOnchainAddress( // Await events function export async function awaitEvents( - expectedNewEvents: number, + expectedNewEvents: bigint, _eventSignature: string, appGateway: Address, evmxChain: ChainConfig, - timeout: number = 180 + timeout: number = 300 ): Promise { console.log(`${COLORS.CYAN}Waiting logs for ${expectedNewEvents} new events (up to ${timeout} seconds)...${COLORS.NC}`); const interval: number = 2000; // 2 seconds let elapsed: number = 0; - let eventCount: number = 0; + let eventCount = 0n; while (elapsed <= timeout * 1000) { try { diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 147fac8..ff03331 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -14,6 +14,12 @@ import "./ReadMultichain.sol"; * Inherits from AppGatewayBase for SOCKET Protocol integration. */ contract ReadAppGateway is AppGatewayBase { + /** + * @notice Number of requests to call onchain + * @dev Used to maximize number of requests done + */ + uint256 numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; + /** * @notice Identifier for the ReadMultichain contract * @dev Used to track ReadMultichain contract instances across chains @@ -43,7 +49,7 @@ contract ReadAppGateway is AppGatewayBase { */ constructor(address addressResolver_, uint256 fees_) { creationCodeWithArgs[multichain] = abi.encodePacked(type(ReadMultichain).creationCode); - values = new uint256[](10); + values = new uint256[](numberOfRequests); _initializeAppGateway(addressResolver_); _setMaxFees(fees_); } @@ -74,9 +80,9 @@ contract ReadAppGateway is AppGatewayBase { */ function triggerParallelRead(address instance_) public async { _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { + for (uint256 i = 0; i < numberOfRequests; i++) { IReadMultichain(instance_).values(i); - IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); + then(this.handleValue.selector, abi.encode(i, instance_)); } _setOverrides(Read.OFF, Parallel.OFF); } @@ -90,7 +96,7 @@ contract ReadAppGateway is AppGatewayBase { */ function triggerAltRead(address instance1_, address instance2_) public async { _setOverrides(Read.ON, Parallel.ON); - for (uint256 i = 0; i < 10; i++) { + for (uint256 i = 0; i < numberOfRequests; i++) { if (i % 2 == 0) { IReadMultichain(instance1_).values(i); IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index d1ffd05..be37a5d 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -13,6 +13,12 @@ import "./WriteMultichain.sol"; * Inherits from AppGatewayBase for SOCKET Protocol integration. */ contract WriteAppGateway is AppGatewayBase { + /** + * @notice Number of requests to call onchain + * @dev Used to maximize number of requests done + */ + uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 2; + /** * @notice Identifier for the WriteMultichain contract * @dev Used to track WriteMultichain contract instances across chains @@ -63,7 +69,7 @@ contract WriteAppGateway is AppGatewayBase { * @param instance_ Address of the WriteMultichain instance to write to */ function triggerSequentialWrite(address instance_) public async { - for (uint256 i = 0; i < 10; i++) { + for (uint256 i = 0; i < numberOfRequests; i++) { IWriteMultichain(instance_).increase(); IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); } @@ -76,7 +82,7 @@ contract WriteAppGateway is AppGatewayBase { */ function triggerParallelWrite(address instance_) public async { _setOverrides(Parallel.ON); - for (uint256 i = 0; i < 10; i++) { + for (uint256 i = 0; i < numberOfRequests; i++) { IWriteMultichain(instance_).increase(); IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); } From b5bee6dfc5d8ff8e26fe9488be92affde586058e Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:11:40 +0100 Subject: [PATCH 13/39] chore: update deposit function name --- script/utils/fees-manager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index d0f0ddd..bf66df8 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -60,7 +60,7 @@ export async function depositFunds( ]); const feesPlugAbi = parseAbi([ - 'function depositToFeeAndNative(address token, address appGateway, uint256 amount) external' + 'function depositCreditAndNative(address token, address appGateway, uint256 amount) external' ]); const walletAddress = arbChain.walletClient.account?.address; @@ -87,7 +87,7 @@ export async function depositFunds( // Deposit funds await sendTransaction( process.env.ARBITRUM_FEES_PLUG as Address, - 'depositToFeeAndNative', + 'depositCreditAndNative', [process.env.ARBITRUM_TEST_USDC as Address, appGateway, AMOUNTS.TEST_USDC], arbChain, feesPlugAbi From 7cd2695536b00806daab35a603e1dad4600a2634 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:12:24 +0100 Subject: [PATCH 14/39] fix: contracts calling wrong then function --- src/deploy/DeploymentAppGateway.sol | 20 ++++++++++---------- src/forwarder-on-evmx/UploadAppGateway.sol | 3 +-- src/read/IReadMultichain.sol | 9 --------- src/read/ReadAppGateway.sol | 6 +++--- src/revert/RevertAppGateway.sol | 3 +-- src/write/IWriteMultichain.sol | 9 --------- src/write/WriteAppGateway.sol | 18 +++++++++++------- 7 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index f94b3ba..843bdd4 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -106,36 +106,36 @@ contract DeploymentAppGateway is AppGatewayBase { // NoPlugNoInititialize checks _setOverrides(Read.ON); IDeployOnchain(noPlugNoInititializeForwarder).variable(); - IPromise(noPlugNoInititializeForwarder).then(this.validateVariable.selector, abi.encode(0)); + then(this.validateVariable.selector, abi.encode(0)); // NoPlugInitialize checks IDeployOnchain(noPlugInitializeForwarder).variable(); - IPromise(noPlugInitializeForwarder).then(this.validateVariable.selector, abi.encode(10)); + then(this.validateVariable.selector, abi.encode(10)); // PlugNoInitialize checks IDeployOnchain(plugNoInitializeForwarder).variable(); - IPromise(plugNoInitializeForwarder).then(this.validateVariable.selector, abi.encode(0)); + then(this.validateVariable.selector, abi.encode(0)); IDeployOnchain(plugNoInitializeForwarder).socket__(); - IPromise(plugNoInitializeForwarder).then(this.validateSocket.selector, abi.encode(0)); + then(this.validateSocket.selector, abi.encode(0)); // PlugInitialize checks IDeployOnchain(plugInitializeForwarder).variable(); - IPromise(plugInitializeForwarder).then(this.validateVariable.selector, abi.encode(10)); + then(this.validateVariable.selector, abi.encode(10)); IDeployOnchain(plugInitializeForwarder).socket__(); - IPromise(plugInitializeForwarder).then(this.validateSocket.selector, abi.encode(0)); + then(this.validateSocket.selector, abi.encode(0)); // PlugInitializeTwice checks IDeployOnchain(plugInitializeTwiceForwarder).variable(); - IPromise(plugInitializeTwiceForwarder).then(this.validateVariable.selector, abi.encode(20)); + then(this.validateVariable.selector, abi.encode(20)); IDeployOnchain(plugInitializeTwiceForwarder).socket__(); - IPromise(plugInitializeTwiceForwarder).then(this.validateSocket.selector, abi.encode(0)); + then(this.validateSocket.selector, abi.encode(0)); // PlugNoInitInitialize checks _setOverrides(Read.ON); IDeployOnchain(plugNoInitInitializeForwarder).variable(); - IPromise(plugNoInitInitializeForwarder).then(this.validateVariable.selector, abi.encode(10)); + then(this.validateVariable.selector, abi.encode(10)); IDeployOnchain(plugNoInitInitializeForwarder).socket__(); - IPromise(plugNoInitInitializeForwarder).then(this.validateSocket.selector, abi.encode(0)); + then(this.validateSocket.selector, abi.encode(0)); _setOverrides(Read.OFF); } diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 5db9cd3..f9d4958 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; -import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./ICounter.sol"; /** @@ -69,7 +68,7 @@ contract UploadAppGateway is AppGatewayBase { _setOverrides(Read.ON, Parallel.ON); // TODO: Remove Parallel.ON after new contract deployment to devnet ICounter(counterForwarder).counter(); - IPromise(counterForwarder).then(this.handleRead.selector, abi.encode(counterForwarder)); + then(this.handleRead.selector, abi.encode(counterForwarder)); _setOverrides(Read.OFF, Parallel.OFF); } diff --git a/src/read/IReadMultichain.sol b/src/read/IReadMultichain.sol index 851125e..b8554d2 100644 --- a/src/read/IReadMultichain.sol +++ b/src/read/IReadMultichain.sol @@ -13,13 +13,4 @@ interface IReadMultichain { * @param index The index of the value to retrieve */ function values(uint256 index) external; - - /** - * @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; } diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index ff03331..724325d 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -3,7 +3,7 @@ pragma solidity >=0.7.0 <0.9.0; 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 "socket-protocol/contracts/utils/common/Constants.sol"; import "./IReadMultichain.sol"; import "./ReadMultichain.sol"; @@ -99,10 +99,10 @@ contract ReadAppGateway is AppGatewayBase { for (uint256 i = 0; i < numberOfRequests; i++) { if (i % 2 == 0) { IReadMultichain(instance1_).values(i); - IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); + then(this.handleValue.selector, abi.encode(i, instance1_)); } else { IReadMultichain(instance2_).values(i); - IPromise(instance2_).then(this.handleValue.selector, abi.encode(i, instance2_)); + then(this.handleValue.selector, abi.encode(i, instance2_)); } } _setOverrides(Read.OFF, Parallel.OFF); diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index cb71ee0..125e1b9 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -2,7 +2,6 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; -import "socket-protocol/contracts/evmx/interfaces/IPromise.sol"; import "./ICounter.sol"; import "./Counter.sol"; @@ -75,7 +74,7 @@ contract RevertAppGateway is AppGatewayBase { address instance = forwarderAddresses[counter][chainSlug]; ICounter(instance).counter(); // wrong function input parameters for a callback - IPromise(instance).then(this.notCorrectInputArgs.selector, abi.encode(chainSlug)); + then(this.notCorrectInputArgs.selector, abi.encode(chainSlug)); _setOverrides(Read.OFF, Parallel.OFF); } diff --git a/src/write/IWriteMultichain.sol b/src/write/IWriteMultichain.sol index 33a924e..1cc0f60 100644 --- a/src/write/IWriteMultichain.sol +++ b/src/write/IWriteMultichain.sol @@ -18,13 +18,4 @@ interface IWriteMultichain { * @dev Can only be called by authorized accounts via the SOCKET Protocol */ function increase() external; - - /** - * @notice Connects the contract to the SOCKET Protocol - * @dev Sets up the contract for EVMx communication - * @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; } diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index be37a5d..2d74c83 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -2,6 +2,7 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; +import "socket-protocol/contracts/utils/common/Constants.sol"; import "./IWriteMultichain.sol"; import "./WriteMultichain.sol"; @@ -71,7 +72,7 @@ contract WriteAppGateway is AppGatewayBase { function triggerSequentialWrite(address instance_) public async { for (uint256 i = 0; i < numberOfRequests; i++) { IWriteMultichain(instance_).increase(); - IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); + then(this.handleValue.selector, abi.encode(i, instance_)); } } @@ -84,7 +85,7 @@ contract WriteAppGateway is AppGatewayBase { _setOverrides(Parallel.ON); for (uint256 i = 0; i < numberOfRequests; i++) { IWriteMultichain(instance_).increase(); - IPromise(instance_).then(this.handleValue.selector, abi.encode(i, instance_)); + then(this.handleValue.selector, abi.encode(i, instance_)); } _setOverrides(Parallel.OFF); } @@ -96,11 +97,14 @@ contract WriteAppGateway is AppGatewayBase { * @param instance2_ Address of the second WriteMultichain instance */ function triggerAltWrite(address instance1_, address instance2_) public async { - for (uint256 i = 0; i < 5; i++) { - IWriteMultichain(instance1_).increase(); - IPromise(instance1_).then(this.handleValue.selector, abi.encode(i, instance1_)); - IWriteMultichain(instance2_).increase(); - IPromise(instance2_).then(this.handleValue.selector, abi.encode(i, instance2_)); + for (uint256 i = 0; i < numberOfRequests; i++) { + if (i % 2 == 0) { + IWriteMultichain(instance1_).increase(); + then(this.handleValue.selector, abi.encode(i, instance1_)); + } else { + IWriteMultichain(instance2_).increase(); + then(this.handleValue.selector, abi.encode(i, instance2_)); + } } } From 9e862ad1aebb644706c9d6ce4c2d017293d31eb8 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:21:39 +0100 Subject: [PATCH 15/39] fix: add missing public to read contract --- src/read/ReadAppGateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 724325d..c77ded0 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -18,7 +18,7 @@ contract ReadAppGateway is AppGatewayBase { * @notice Number of requests to call onchain * @dev Used to maximize number of requests done */ - uint256 numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; + uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; /** * @notice Identifier for the ReadMultichain contract From 59e1effc087c02462d158f968462b6c396622c44 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 10:27:07 +0100 Subject: [PATCH 16/39] fix: numberOfRequests consistent with read contract --- src/write/WriteAppGateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 2d74c83..0ebc4e3 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -18,7 +18,7 @@ contract WriteAppGateway is AppGatewayBase { * @notice Number of requests to call onchain * @dev Used to maximize number of requests done */ - uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 2; + uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; /** * @notice Identifier for the WriteMultichain contract From 672f6f4092efa2e80fc54533e094506f9f343120 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 11:01:47 +0100 Subject: [PATCH 17/39] fix: add missing async modifier --- src/schedule/ScheduleAppGateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index e1b43e7..26130c6 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -57,7 +57,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @notice Triggers multiple schedules with different delay periods * @dev Sets up scheduled calls to resolveSchedule with various delay periods defined in schedulesInSeconds */ - function triggerSchedules() public { + function triggerSchedules() public async { for (uint256 i = 0; i < schedulesInSeconds.length; i++) { _setSchedule(schedulesInSeconds[i]); then(this.resolveSchedule.selector, abi.encode(i, block.timestamp)); From 2e4cf7b665878b101459429e0dc30314e6834f05 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 11:39:10 +0100 Subject: [PATCH 18/39] fix: revert test validation --- script/tests/revert_tests.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/script/tests/revert_tests.ts b/script/tests/revert_tests.ts index 0c00f22..7537839 100644 --- a/script/tests/revert_tests.ts +++ b/script/tests/revert_tests.ts @@ -35,39 +35,36 @@ export async function runRevertTests( abi ); - console.log(`${COLORS.CYAN}Waiting for transaction finalization${COLORS.NC}`); + console.log(`${COLORS.CYAN}Waiting for transaction proof${COLORS.NC}`); let attempt = 0; let status = ''; + let execStatus; while (true) { const response = await getTxDetails(endpoint, hash1); - status = response?.response?.[0]?.writePayloads?.[0]?.finalizeDetails?.finalizeStatus; - - if (status === 'FINALIZED') { - if (attempt > 0) process.stdout.write('\r\x1b[2K'); - break; + status = response?.response?.[0]?.writePayloads?.[0]?.proofUploadDetails?.proofUploadStatus; + + if (status === 'PROOF_UPLOADED') { + execStatus = response?.response?.[0]?.writePayloads?.[0]?.executeDetails?.executeStatus; + if (execStatus === 'EXECUTION_FAILED') { + console.log(`Execution status is EXECUTION_FAILED as expected`); + if (attempt > 0) process.stdout.write('\r\x1b[2K'); + break; + } } if (attempt >= maxAttempts) { console.log(); - throw new Error(`Transaction not finalized after ${maxSeconds} seconds. Current status: ${status}`); + throw new Error(`Could not validate failed execution after ${maxSeconds} seconds. Current status: ${status}`); } const elapsed = attempt * interval / 1000; - process.stdout.write(`\r${COLORS.YELLOW}Waiting for finalization:${COLORS.NC} ${elapsed}s / ${maxSeconds}s`); + process.stdout.write(`\r${COLORS.YELLOW}Waiting for failed execution:${COLORS.NC} ${elapsed}s / ${maxSeconds}s`); await new Promise(resolve => setTimeout(resolve, interval)); attempt++; } - const execStatus = (await getTxDetails(endpoint, hash1))?.response?.[0]?.writePayloads?.[0]?.executeDetails?.executeStatus; - - if (execStatus === 'EXECUTION_FAILED') { - console.log(`Execution status is EXECUTION_FAILED as expected`); - } else { - throw new Error(`Execution status is not EXECUTION_FAILED, it is: ${execStatus}`); - } - // Send callback revert transaction console.log(`${COLORS.CYAN}Testing callback revert${COLORS.NC}`); From 94567059a2fccee22b4fe721d728978419764ed4 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 12:17:53 +0100 Subject: [PATCH 19/39] fix: remove async when not needed --- src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index b6c7693..18d866f 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -88,7 +88,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * 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 onlyWatcher { + function callFromChain(uint256 value) external onlyWatcher { valueOnGateway += value; } From 984bdc76fda88febda5ae7be6002d5e6d249a375 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 13:51:24 +0100 Subject: [PATCH 20/39] fix: change max fees to half of deploy fees --- script/utils/deployer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/utils/deployer.ts b/script/utils/deployer.ts index 30670af..e94c00d 100644 --- a/script/utils/deployer.ts +++ b/script/utils/deployer.ts @@ -107,7 +107,7 @@ export async function deployAppGateway( ): Promise
{ return deployContract( filename, - [process.env.ADDRESS_RESOLVER, deployFees], + [process.env.ADDRESS_RESOLVER, deployFees / 2n], evmxChain ); } From e50c3d2a000c7e5cb5d2c7d158d99da4e95e9d4a Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:30:14 +0100 Subject: [PATCH 21/39] chore: add transferCredits and setMaxFees to all contracts --- src/deploy/DeploymentAppGateway.sol | 19 +++++++++++++++++++ src/forwarder-on-evmx/UploadAppGateway.sol | 19 +++++++++++++++++++ src/read/ReadAppGateway.sol | 19 +++++++++++++++++++ src/revert/RevertAppGateway.sol | 19 +++++++++++++++++++ src/schedule/ScheduleAppGateway.sol | 19 +++++++++++++++++++ .../OnchainTriggerAppGateway.sol | 19 +++++++++++++++++++ src/write/WriteAppGateway.sol | 10 ++++++++++ 7 files changed, 124 insertions(+) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index 843bdd4..bd08b30 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -174,4 +174,23 @@ contract DeploymentAppGateway is AppGatewayBase { function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index f9d4958..14531dc 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -97,4 +97,23 @@ contract UploadAppGateway is AppGatewayBase { function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index c77ded0..5deafa4 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -134,6 +134,25 @@ contract ReadAppGateway is AppGatewayBase { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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_; + } + /** * @notice Increases the fee payment for a specific payload request * @dev Allows modification of fee settings for a specific payload diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 125e1b9..09df57d 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -100,4 +100,23 @@ contract RevertAppGateway is AppGatewayBase { function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 26130c6..3109d94 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -85,4 +85,23 @@ contract ScheduleAppGateway is AppGatewayBase { function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 18d866f..191ac58 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -115,4 +115,23 @@ contract OnchainTriggerAppGateway is AppGatewayBase { function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + + /** + * @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/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index 0ebc4e3..cce1288 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -132,6 +132,16 @@ contract WriteAppGateway is AppGatewayBase { _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); } + /** + * @notice Transfers fee credits from this contract to a specified address + * @dev Moves a specified amount of fee credits from the current contract to the given recipient + * @param to_ The address to transfer credits to + * @param amount_ The amount of credits to transfer + */ + function transferCredits(address to_, uint256 amount_) external { + feesManager__().transferCredits(address(this), to_, amount_); + } + /** * @notice Updates the fee max value * @dev Allows modification of fee settings for multi-chain operations From c2ae82e8fd274c94ac69a5642d02c5dfbeb1d045 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:31:54 +0100 Subject: [PATCH 22/39] fix: withdraw fees logic --- script/utils/constants.ts | 6 ++--- script/utils/fees-manager.ts | 43 +++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/script/utils/constants.ts b/script/utils/constants.ts index 8e2b11f..9fac147 100644 --- a/script/utils/constants.ts +++ b/script/utils/constants.ts @@ -13,9 +13,9 @@ export const URLS = { export const AMOUNTS = { DEPLOY_FEES: parseEther('10'), // 10 ETH - TEST_USDC: BigInt('100000000'), // 100 TEST USDC - GAS_BUFFER: BigInt('100000000'), // 0.1 Gwei - GAS_LIMIT: BigInt('50000000000'), // Gas limit estimate + TEST_USDC: 100000000n, // 100 TEST USDC + GAS_BUFFER: 100000000n, // 0.1 Gwei + GAS_LIMIT: 50000000000n, // Gas limit estimate } as const; export const COLORS = { diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index bf66df8..6c71cd2 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -1,5 +1,5 @@ // fees/manager.ts -import { parseAbi, type Address } from 'viem'; +import { parseAbi, formatEther, type Address } from 'viem'; import { ChainConfig } from './types.js'; import { COLORS, AMOUNTS, CHAIN_IDS } from './constants.js'; import { sendTransaction } from './deployer.js'; @@ -27,7 +27,7 @@ export async function checkAvailableFees( }) as bigint; if (availableFees > 0n) { - console.log(`Funds available: ${availableFees} wei`); + console.log(`Funds available: ${formatEther(availableFees)} Credits - ${availableFees} wei`); return availableFees; } } catch (error) { @@ -104,29 +104,31 @@ export async function withdrawFunds( ): Promise { console.log(`${COLORS.CYAN}Withdrawing funds${COLORS.NC}`); - const availableFees = await checkAvailableFees(appGateway, evmxChain); + let availableFees = await checkAvailableFees(appGateway, evmxChain); if (availableFees === 0n) { console.log('No available fees to withdraw.'); return; } - // Get gas price and calculate withdrawal amount - const gasPrice = await arbChain.client.getGasPrice(); - const estimatedGasCost = AMOUNTS.GAS_LIMIT * (gasPrice + AMOUNTS.GAS_BUFFER); + const abi = parseAbi([ + 'function maxFees() external returns (uint256)', + 'function withdrawCredits(uint32 chainId, address token, uint256 amount, address to) external', + 'function transferCredits(address to_, uint256 amount_) external' + ]); - let amountToWithdraw = 0n; - if (availableFees > estimatedGasCost) { - amountToWithdraw = availableFees - estimatedGasCost; - } + const maxFees = await evmxChain.client.readContract({ + address: appGateway, + abi, + functionName: 'maxFees', + }); + console.log(`Max fees ${formatEther(maxFees)} Credits - ${maxFees} wei`); - console.log(`Withdrawing ${amountToWithdraw} wei`); + let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES; - if (amountToWithdraw > 0n) { - const abi = parseAbi([ - 'function withdrawCredits(uint32 chainId, address token, uint256 amount, address to) external' - ]); + console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`); + if (amountToWithdraw > 0n) { await sendTransaction( appGateway, 'withdrawCredits', @@ -137,4 +139,15 @@ export async function withdrawFunds( } else { console.log('No funds available for withdrawal after gas cost estimation.'); } + + // transfer the rest to the EOA + availableFees = await checkAvailableFees(appGateway, evmxChain); + + await sendTransaction( + appGateway, + 'transferCredits', + [evmxChain.walletClient.account?.address, availableFees], + evmxChain, + abi + ); } From 2893da7f30c61c43d8fda6e68f1915c7bce289e6 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:32:56 +0100 Subject: [PATCH 23/39] chore: add TODO on depositFunds --- script/utils/fees-manager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index 6c71cd2..2e345ca 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -53,6 +53,9 @@ export async function depositFunds( evmxChain: ChainConfig ): Promise { console.log(`${COLORS.CYAN}Depositing funds${COLORS.NC}`); + // TODO: Check balance on FeesPlug and then EVMx + // if not 100 credits : mint missing credits + // if 100 or more transfer to new appgateway const erc20Abi = parseAbi([ 'function mint(address to, uint256 amount) external', From a94a46411ee560033dfc5a8c2b308010ffd781b1 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 17:48:27 +0100 Subject: [PATCH 24/39] chore: remove TODO as issue is solved --- src/forwarder-on-evmx/UploadAppGateway.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 14531dc..2cd24f6 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -65,11 +65,10 @@ contract UploadAppGateway is AppGatewayBase { * Sets up a promise to handle the read result via the handleRead function */ function read() public async { - _setOverrides(Read.ON, Parallel.ON); - // TODO: Remove Parallel.ON after new contract deployment to devnet + _setOverrides(Read.ON); ICounter(counterForwarder).counter(); then(this.handleRead.selector, abi.encode(counterForwarder)); - _setOverrides(Read.OFF, Parallel.OFF); + _setOverrides(Read.OFF); } /** From a93fe134f6f374e2987eef9a456dfbd4e5450499 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 20:04:48 +0100 Subject: [PATCH 25/39] Update socket-protocol submodule to latest staging --- .gitmodules | 2 +- lib/socket-protocol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index c6035df..5847cbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,4 @@ [submodule "lib/socket-protocol"] path = lib/socket-protocol url = https://github.com/SocketDotTech/socket-protocol.git - branch = dev + branch = staging diff --git a/lib/socket-protocol b/lib/socket-protocol index e33312e..10054ef 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit e33312e550e726bad472a2ade011f35d6ba3315e +Subproject commit 10054efbd2f1aa5daf40370570cae9a39ad023a5 From 4e056269f7de4a4cb6dc316286e815086336b519 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 20:06:25 +0100 Subject: [PATCH 26/39] Update socket-protocol submodule to latest dev --- .gitmodules | 2 +- lib/socket-protocol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 5847cbd..c6035df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,4 @@ [submodule "lib/socket-protocol"] path = lib/socket-protocol url = https://github.com/SocketDotTech/socket-protocol.git - branch = staging + branch = dev diff --git a/lib/socket-protocol b/lib/socket-protocol index 10054ef..dc173ae 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit 10054efbd2f1aa5daf40370570cae9a39ad023a5 +Subproject commit dc173aea1bfcec23d39c16b9e1ec43333f7fba72 From 1a1bcdd20596a88eaad2b665a67e01aff7a69cef Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:28:57 +0100 Subject: [PATCH 27/39] chore: change transfer amount to 10 USDC --- script/utils/constants.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script/utils/constants.ts b/script/utils/constants.ts index 9fac147..3260e47 100644 --- a/script/utils/constants.ts +++ b/script/utils/constants.ts @@ -13,7 +13,7 @@ export const URLS = { export const AMOUNTS = { DEPLOY_FEES: parseEther('10'), // 10 ETH - TEST_USDC: 100000000n, // 100 TEST USDC + TEST_USDC: 10000000n, // 10 TEST USDC GAS_BUFFER: 100000000n, // 0.1 Gwei GAS_LIMIT: 50000000000n, // Gas limit estimate } as const; @@ -25,4 +25,3 @@ export const COLORS = { RED: '\x1b[0;31m', NC: '\x1b[0m', // No Color } as const; - From 35eeac6341db513a11f062e154936001ef9ac0ac Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:29:34 +0100 Subject: [PATCH 28/39] chore: update withdrawCredits --- src/deploy/DeploymentAppGateway.sol | 2 +- src/forwarder-on-evmx/UploadAppGateway.sol | 2 +- src/read/ReadAppGateway.sol | 5 ++--- src/revert/RevertAppGateway.sol | 2 +- src/schedule/ScheduleAppGateway.sol | 2 +- src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol | 2 +- src/write/WriteAppGateway.sol | 5 ++--- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/deploy/DeploymentAppGateway.sol b/src/deploy/DeploymentAppGateway.sol index bd08b30..40c5ce9 100644 --- a/src/deploy/DeploymentAppGateway.sol +++ b/src/deploy/DeploymentAppGateway.sol @@ -172,7 +172,7 @@ contract DeploymentAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/forwarder-on-evmx/UploadAppGateway.sol b/src/forwarder-on-evmx/UploadAppGateway.sol index 2cd24f6..65cfdc7 100644 --- a/src/forwarder-on-evmx/UploadAppGateway.sol +++ b/src/forwarder-on-evmx/UploadAppGateway.sol @@ -94,7 +94,7 @@ contract UploadAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/read/ReadAppGateway.sol b/src/read/ReadAppGateway.sol index 5deafa4..b65ebce 100644 --- a/src/read/ReadAppGateway.sol +++ b/src/read/ReadAppGateway.sol @@ -3,7 +3,6 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; import "socket-protocol/contracts/evmx/interfaces/IForwarder.sol"; -import "socket-protocol/contracts/utils/common/Constants.sol"; import "./IReadMultichain.sol"; import "./ReadMultichain.sol"; @@ -18,7 +17,7 @@ contract ReadAppGateway is AppGatewayBase { * @notice Number of requests to call onchain * @dev Used to maximize number of requests done */ - uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; + uint256 public numberOfRequests = 10; /** * @notice Identifier for the ReadMultichain contract @@ -131,7 +130,7 @@ contract ReadAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/revert/RevertAppGateway.sol b/src/revert/RevertAppGateway.sol index 09df57d..5aae3ab 100644 --- a/src/revert/RevertAppGateway.sol +++ b/src/revert/RevertAppGateway.sol @@ -98,7 +98,7 @@ contract RevertAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/schedule/ScheduleAppGateway.sol b/src/schedule/ScheduleAppGateway.sol index 3109d94..3476b0a 100644 --- a/src/schedule/ScheduleAppGateway.sol +++ b/src/schedule/ScheduleAppGateway.sol @@ -83,7 +83,7 @@ contract ScheduleAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol index 191ac58..4054550 100644 --- a/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol +++ b/src/trigger-appgateway-onchain/OnchainTriggerAppGateway.sol @@ -113,7 +113,7 @@ contract OnchainTriggerAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** diff --git a/src/write/WriteAppGateway.sol b/src/write/WriteAppGateway.sol index cce1288..1e89635 100644 --- a/src/write/WriteAppGateway.sol +++ b/src/write/WriteAppGateway.sol @@ -2,7 +2,6 @@ pragma solidity >=0.7.0 <0.9.0; import "socket-protocol/contracts/evmx/base/AppGatewayBase.sol"; -import "socket-protocol/contracts/utils/common/Constants.sol"; import "./IWriteMultichain.sol"; import "./WriteMultichain.sol"; @@ -18,7 +17,7 @@ contract WriteAppGateway is AppGatewayBase { * @notice Number of requests to call onchain * @dev Used to maximize number of requests done */ - uint256 public numberOfRequests = REQUEST_PAYLOAD_COUNT_LIMIT - 1; + uint256 public numberOfRequests = 10; /** * @notice Identifier for the WriteMultichain contract @@ -129,7 +128,7 @@ contract WriteAppGateway is AppGatewayBase { * @param receiver_ The address that will receive the withdrawn fees */ function withdrawCredits(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { - _withdrawCredits(chainSlug_, token_, amount_, maxFees, receiver_); + _withdrawCredits(chainSlug_, token_, amount_, receiver_); } /** From ba7843d2330efef3a7588025d5291eb9e58aca68 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:30:23 +0100 Subject: [PATCH 29/39] feat: sendTransaction now supports value --- script/utils/deployer.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script/utils/deployer.ts b/script/utils/deployer.ts index e94c00d..a1c43e8 100644 --- a/script/utils/deployer.ts +++ b/script/utils/deployer.ts @@ -74,7 +74,8 @@ export async function sendTransaction( functionName: string, args: any[] = [], chainConfig: ChainConfig, - abi: Abi + abi: Abi, + value: bigint = 0n ): Promise { console.log(`${COLORS.CYAN}Sending transaction to ${functionName} on ${to}${COLORS.NC}`); @@ -86,7 +87,8 @@ export async function sendTransaction( args, account: chainConfig.walletClient.account!, chain: chainConfig.walletClient.chain, - gasPrice: chainConfig.chainId === CHAIN_IDS.EVMX ? 0n : undefined + gasPrice: chainConfig.chainId === CHAIN_IDS.EVMX ? 0n : undefined, + value: value }); await new Promise(resolve => setTimeout(resolve, 2000)); From f158351221d5a55c41c4e8659732a83402ea6e24 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Tue, 3 Jun 2025 21:31:03 +0100 Subject: [PATCH 30/39] fix: add 1sec delay after confirming funds --- script/utils/fees-manager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index 2e345ca..3f27960 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -1,5 +1,5 @@ // fees/manager.ts -import { parseAbi, formatEther, type Address } from 'viem'; +import { parseAbi, formatEther, type Address, parseEther } from 'viem'; import { ChainConfig } from './types.js'; import { COLORS, AMOUNTS, CHAIN_IDS } from './constants.js'; import { sendTransaction } from './deployer.js'; @@ -28,6 +28,7 @@ export async function checkAvailableFees( if (availableFees > 0n) { console.log(`Funds available: ${formatEther(availableFees)} Credits - ${availableFees} wei`); + await new Promise(resolve => setTimeout(resolve, 1000)); return availableFees; } } catch (error) { From 6c0ac9b026a13c2360939d17c0fd7a93f3189c75 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 09:44:22 +0100 Subject: [PATCH 31/39] cheeky commit. needs to be reverted --- script/utils/fees-manager.ts | 115 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index 3f27960..6bf8df7 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -54,48 +54,51 @@ export async function depositFunds( evmxChain: ChainConfig ): Promise { console.log(`${COLORS.CYAN}Depositing funds${COLORS.NC}`); - // TODO: Check balance on FeesPlug and then EVMx - // if not 100 credits : mint missing credits - // if 100 or more transfer to new appgateway - const erc20Abi = parseAbi([ - 'function mint(address to, uint256 amount) external', - 'function approve(address spender, uint256 amount) external returns (bool)' - ]); + const balance = await evmxChain.client.getBalance({ + address: evmxChain.walletClient.account?.address as Address, + }) as bigint; - const feesPlugAbi = parseAbi([ - 'function depositCreditAndNative(address token, address appGateway, uint256 amount) external' + const feesAbi = parseAbi([ + 'function depositCreditAndNative(address token, address appGateway, uint256 amount) external', + 'function wrap(address appGateway)' ]); - const walletAddress = arbChain.walletClient.account?.address; - if (!walletAddress) throw new Error('Wallet address not found'); - - // Mint test USDC - await sendTransaction( - process.env.ARBITRUM_TEST_USDC as Address, - 'mint', - [walletAddress, AMOUNTS.TEST_USDC], - arbChain, - erc20Abi - ); - - // Approve USDC for FeesPlug - await sendTransaction( - process.env.ARBITRUM_TEST_USDC as Address, - 'approve', - [process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC], - arbChain, - erc20Abi - ); + if (balance > 0n) { + sendTransaction( + process.env.FEES_MANAGER as Address, + 'wrap', + [appGateway], + evmxChain, + feesAbi, + parseEther('10') + ); + } - // Deposit funds - await sendTransaction( - process.env.ARBITRUM_FEES_PLUG as Address, - 'depositCreditAndNative', - [process.env.ARBITRUM_TEST_USDC as Address, appGateway, AMOUNTS.TEST_USDC], - arbChain, - feesPlugAbi - ); + //const erc20Abi = parseAbi([ + // 'function approve(address spender, uint256 amount) external returns (bool)' + //]); + + //const walletAddress = arbChain.walletClient.account?.address; + //if (!walletAddress) throw new Error('Wallet address not found'); + + //// Approve USDC for FeesPlug + //await sendTransaction( + // process.env.ARBITRUM_USDC as Address, + // 'approve', + // [process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC], + // arbChain, + // erc20Abi + //); + + //// Deposit funds + //await sendTransaction( + // process.env.ARBITRUM_FEES_PLUG as Address, + // 'depositCreditAndNative', + // [process.env.ARBITRUM_USDC as Address, appGateway, AMOUNTS.TEST_USDC], + // arbChain, + // feesPlugAbi + //); await checkAvailableFees(appGateway, evmxChain); } @@ -116,36 +119,28 @@ export async function withdrawFunds( } const abi = parseAbi([ - 'function maxFees() external returns (uint256)', 'function withdrawCredits(uint32 chainId, address token, uint256 amount, address to) external', 'function transferCredits(address to_, uint256 amount_) external' ]); - const maxFees = await evmxChain.client.readContract({ - address: appGateway, - abi, - functionName: 'maxFees', - }); - console.log(`Max fees ${formatEther(maxFees)} Credits - ${maxFees} wei`); + //let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES; - let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES; + //console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`); - console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`); - - if (amountToWithdraw > 0n) { - await sendTransaction( - appGateway, - 'withdrawCredits', - [CHAIN_IDS.ARB_SEP, process.env.ARBITRUM_TEST_USDC, amountToWithdraw, arbChain.walletClient.account?.address], - evmxChain, - abi - ); - } else { - console.log('No funds available for withdrawal after gas cost estimation.'); - } + //if (amountToWithdraw > 0n) { + // await sendTransaction( + // appGateway, + // 'withdrawCredits', + // [CHAIN_IDS.ARB_SEP, process.env.ARBITRUM_USDC, amountToWithdraw, arbChain.walletClient.account?.address], + // evmxChain, + // abi + // ); + //} else { + // console.log('No funds available for withdrawal after gas cost estimation.'); + //} - // transfer the rest to the EOA - availableFees = await checkAvailableFees(appGateway, evmxChain); + //// transfer the rest to the EOA + //availableFees = await checkAvailableFees(appGateway, evmxChain); await sendTransaction( appGateway, From 3c2d04676212c562120937a2cbf892e4649401f9 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:37:22 +0100 Subject: [PATCH 32/39] feat: add support for mainnet chains --- script/runIntegrationTests.ts | 41 ++------ script/utils/client-setup.ts | 171 ++++++++++++++++++++++++++-------- script/utils/constants.ts | 5 + 3 files changed, 145 insertions(+), 72 deletions(-) diff --git a/script/runIntegrationTests.ts b/script/runIntegrationTests.ts index ae73688..3fe86e0 100644 --- a/script/runIntegrationTests.ts +++ b/script/runIntegrationTests.ts @@ -1,6 +1,6 @@ -import { setupClients } from './utils/client-setup.js'; +import { getAvailableChains } from './utils/client-setup.js'; import { buildContracts } from './utils/deployer.js'; -import { ChainConfig, TestFlags } from './utils/types.js'; +import { TestFlags } from './utils/types.js'; import { COLORS } from './utils/constants.js'; // Import test modules @@ -12,19 +12,6 @@ import { executeSchedulerTests } from './tests/scheduler_tests.js'; import { executeInsufficientFeesTests } from './tests/insufficient_tests.js'; import { executeRevertTests } from './tests/revert_tests.js'; -// Global chain configurations -let evmxChain: ChainConfig; -let arbChain: ChainConfig; -let opChain: ChainConfig; - -// Initialize chains -function initializeChains(): void { - const chains = setupClients(); - evmxChain = chains.evmxChain; - arbChain = chains.arbChain; - opChain = chains.opChain; -} - // Help function function showHelp(): void { console.log('Usage: npx tsx tests.ts [OPTIONS]'); @@ -59,7 +46,7 @@ function parseFlags(args: string[]): TestFlags { async function main(): Promise { try { await buildContracts(); - initializeChains(); + const chains = getAvailableChains(); // Parse command line arguments const args = process.argv.slice(2); @@ -72,31 +59,31 @@ async function main(): Promise { // Execute tests based on flags if (flags.write) { - await executeWriteTests(evmxChain, arbChain); + await executeWriteTests(chains.evmxChain, chains.arbChain); } if (flags.read) { - await executeReadTests(evmxChain, arbChain); + await executeReadTests(chains.evmxChain, chains.arbChain); } if (flags.trigger) { - await executeTriggerTests(evmxChain, arbChain, opChain); + await executeTriggerTests(chains.evmxChain, chains.arbChain, chains.opChain); } if (flags.upload) { - await executeUploadTests(evmxChain, arbChain); + await executeUploadTests(chains.evmxChain, chains.arbChain); } if (flags.scheduler) { - await executeSchedulerTests(evmxChain, arbChain); + await executeSchedulerTests(chains.evmxChain, chains.arbChain); } if (flags.insufficient) { - await executeInsufficientFeesTests(evmxChain, arbChain); + await executeInsufficientFeesTests(chains.evmxChain, chains.arbChain); } if (flags.revert) { - await executeRevertTests(evmxChain, arbChain); + await executeRevertTests(chains.evmxChain, chains.arbChain); } console.log(`${COLORS.GREEN}All selected tests completed successfully!${COLORS.NC}`); @@ -107,14 +94,6 @@ async function main(): Promise { } } -// Export the setup for external use -export { - initializeChains, - evmxChain, - arbChain, - opChain -}; - // Run main if this is the main module if (import.meta.url === `file://${process.argv[1]}`) { main().catch((error) => { diff --git a/script/utils/client-setup.ts b/script/utils/client-setup.ts index 6c460bd..c321cb4 100644 --- a/script/utils/client-setup.ts +++ b/script/utils/client-setup.ts @@ -1,4 +1,3 @@ -// clients/setup.ts import { createPublicClient, createWalletClient, @@ -6,7 +5,7 @@ import { type Hash, } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; -import { arbitrumSepolia, optimismSepolia } from 'viem/chains'; +import { arbitrumSepolia, optimismSepolia, optimism, arbitrum, base } from 'viem/chains'; import dotenv from 'dotenv'; import { ChainConfig } from './types.js'; import { CHAIN_IDS } from './constants.js'; @@ -14,15 +13,17 @@ import { CHAIN_IDS } from './constants.js'; // Load environment variables dotenv.config(); -// Environment validation +// Environment validation - only check required chains export function validateEnvironment(): void { const required = [ - 'EVMX_RPC', 'PRIVATE_KEY', + // EVMx + 'EVMX_RPC', 'ADDRESS_RESOLVER', 'FEES_MANAGER', + // Testnets (always required) 'ARBITRUM_SEPOLIA_RPC', - 'OPTIMISM_SEPOLIA_RPC' + 'OPTIMISM_SEPOLIA_RPC', ]; for (const env of required) { @@ -32,68 +33,156 @@ export function validateEnvironment(): void { } } -// Setup all blockchain clients +// Helper function to create chain config +function createChainConfig( + chainInfo: any, + rpcUrl: string, + account: any, + chainId: number, + explorerUrl: string +): ChainConfig { + const client = createPublicClient({ + chain: chainInfo, + transport: http(rpcUrl) + }); + + const walletClient = createWalletClient({ + account, + chain: chainInfo, + transport: http(rpcUrl) + }); + + return { + client, + walletClient, + chainId, + explorerUrl + }; +} + +// Check if mainnet environment variables are available +export function getAvailableMainnets(): { + hasArbitrum: boolean; + hasOptimism: boolean; + hasBase: boolean; +} { + return { + hasArbitrum: !!process.env.ARBITRUM_RPC, + hasOptimism: !!process.env.OPTIMISM_RPC, + hasBase: !!process.env.BASE_RPC, + }; +} + +// Setup all blockchain clients with optional mainnets export function setupClients(): { evmxChain: ChainConfig; arbChain: ChainConfig; opChain: ChainConfig; + arbMainnetChain?: ChainConfig; + opMainnetChain?: ChainConfig; + baseMainnetChain?: ChainConfig; } { validateEnvironment(); const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hash); + const availableMainnets = getAvailableMainnets(); - // EVMx Chain + // EVMx Chain (always required) const evmxClient = createPublicClient({ transport: http(process.env.EVMX_RPC) }); - const evmxWallet = createWalletClient({ account, transport: http(process.env.EVMX_RPC) }); - // Arbitrum Sepolia Chain - const arbClient = createPublicClient({ - chain: arbitrumSepolia, - transport: http(process.env.ARBITRUM_SEPOLIA_RPC) - }); - - const arbWallet = createWalletClient({ + // Testnet chains (always required) + const arbChain = createChainConfig( + arbitrumSepolia, + process.env.ARBITRUM_SEPOLIA_RPC!, account, - chain: arbitrumSepolia, - transport: http(process.env.ARBITRUM_SEPOLIA_RPC) - }); + CHAIN_IDS.ARB_SEP, + 'arbitrum-sepolia.blockscout.com' + ); - // Optimism Sepolia Chain - const opClient = createPublicClient({ - chain: optimismSepolia, - transport: http(process.env.OPTIMISM_SEPOLIA_RPC) - }); - - const opWallet = createWalletClient({ + const opChain = createChainConfig( + optimismSepolia, + process.env.OPTIMISM_SEPOLIA_RPC!, account, - chain: optimismSepolia, - transport: http(process.env.OPTIMISM_SEPOLIA_RPC) - }); + CHAIN_IDS.OP_SEP, + 'optimism-sepolia.blockscout.com' + ); - return { + const result: { + evmxChain: ChainConfig; + arbChain: ChainConfig; + opChain: ChainConfig; + arbMainnetChain?: ChainConfig; + opMainnetChain?: ChainConfig; + baseMainnetChain?: ChainConfig; + } = { evmxChain: { client: evmxClient, walletClient: evmxWallet, chainId: CHAIN_IDS.EVMX, explorerUrl: 'evmx.cloud.blockscout.com' }, - arbChain: { - client: arbClient, - walletClient: arbWallet, - chainId: CHAIN_IDS.ARB_SEP, - explorerUrl: 'arbitrum-sepolia.blockscout.com' - }, - opChain: { - client: opClient, - walletClient: opWallet, - chainId: CHAIN_IDS.OP_SEP, - explorerUrl: 'optimism-sepolia.blockscout.com' - } + arbChain, + opChain, }; + + // Optional mainnet chains + if (availableMainnets.hasArbitrum) { + result.arbMainnetChain = createChainConfig( + arbitrum, + process.env.ARBITRUM_RPC!, + account, + CHAIN_IDS.ARB, + 'arbitrum.blockscout.com' + ); + } + + if (availableMainnets.hasOptimism) { + result.opMainnetChain = createChainConfig( + optimism, + process.env.OPTIMISM_RPC!, + account, + CHAIN_IDS.OP, // Fixed: was using OP_SEP instead of OP + 'optimism.blockscout.com' + ); + } + + if (availableMainnets.hasBase) { + result.baseMainnetChain = createChainConfig( + base, + process.env.BASE_RPC!, + account, + CHAIN_IDS.BASE, + 'base.blockscout.com' + ); + } + + return result; +} + +// Helper function to get only available chains +export function getAvailableChains() { + const clients = setupClients(); + const availableMainnets = getAvailableMainnets(); + + console.log('Available chains:'); + console.log('- EVMx: ✓'); + console.log('- Arbitrum Sepolia: ✓'); + console.log('- Optimism Sepolia: ✓'); + if (availableMainnets.hasArbitrum) { + console.log(`- Arbitrum Mainnet: ✓`); + } + if (availableMainnets.hasOptimism) { + console.log(`- Optimism Mainnet: ✓`); + } + if (availableMainnets.hasBase) { + console.log(`- Base Mainnet: ✓`); + } + + return clients; } diff --git a/script/utils/constants.ts b/script/utils/constants.ts index 3260e47..c4bc8a5 100644 --- a/script/utils/constants.ts +++ b/script/utils/constants.ts @@ -3,8 +3,13 @@ import { parseEther } from 'viem'; export const CHAIN_IDS = { EVMX: 43, + // Testnets ARB_SEP: 421614, OP_SEP: 11155420, + // Mainnets + OP: 10, + ARB: 42161, + BASE: 8453, } as const; export const URLS = { From f34c31f44c005847524d0a1093b1d1ca4cc3b138 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:39:46 +0100 Subject: [PATCH 33/39] fix: delay 1sec after fetching addresses --- script/utils/helpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/script/utils/helpers.ts b/script/utils/helpers.ts index 6440518..fa5b1a3 100644 --- a/script/utils/helpers.ts +++ b/script/utils/helpers.ts @@ -80,6 +80,7 @@ export async function fetchForwarderAndOnchainAddress( console.log(`Forwarder: ${forwarder}`); console.log(`Onchain: ${onchain}`); + await new Promise(resolve => setTimeout(resolve, 1000)); return { forwarder, onchain }; } From b0f341d2a0aa05c7ef2528dde2c4d83dc0347346 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 11:06:17 +0100 Subject: [PATCH 34/39] chore: update .env.sample --- .env.sample | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.env.sample b/.env.sample index 251c116..a487656 100644 --- a/.env.sample +++ b/.env.sample @@ -1,17 +1,22 @@ # RPCs EVMX_RPC="https://rpc-evmx-devnet.socket.tech/" + SEPOLIA_RPC="https://ethereum-sepolia-rpc.publicnode.com" ARBITRUM_SEPOLIA_RPC="https://sepolia-rollup.arbitrum.io/rpc" OPTIMISM_SEPOLIA_RPC="https://sepolia.optimism.io" BASE_SEPOLIA_RPC="https://sepolia.base.org" +ARBITRUM_RPC="https://arbitrum.drpc.org" +OPTIMISM_RPC="https://optimism.drpc.org" +BASE_RPC="https://base.drpc.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="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e" -FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C" -ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b" -ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3" +ADDRESS_RESOLVER="0x935b06902cA5C8bb4C76e18738561c294D377A93" +FEES_MANAGER="0xA07208F9e7aE243F922317ab6604DC9F86822406" +ARBITRUM_FEES_PLUG="0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d" +ARBITRUM_USDC="0xaf88d065e77c8cC2239327C5EDb3A432268e5831" # Add your deployer private key here # or remove it from this file if it is already an env var From 6af15756d9080ea2df7a0f21f95f099d830567c0 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 19:03:23 +0100 Subject: [PATCH 35/39] chore: update fee plug address --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index a487656..50c563a 100644 --- a/.env.sample +++ b/.env.sample @@ -15,7 +15,7 @@ BASE_RPC="https://base.drpc.org" # https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json ADDRESS_RESOLVER="0x935b06902cA5C8bb4C76e18738561c294D377A93" FEES_MANAGER="0xA07208F9e7aE243F922317ab6604DC9F86822406" -ARBITRUM_FEES_PLUG="0xee1Aef0b06f63Aa1c881838794Dd0876462c2B0d" +ARBITRUM_FEES_PLUG="0xfA768B7E490524475B5B96521d4C61D5b976c3C9" ARBITRUM_USDC="0xaf88d065e77c8cC2239327C5EDb3A432268e5831" # Add your deployer private key here From 5def436a34d04b30382fbf911f520faf244d14f2 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:02:47 +0100 Subject: [PATCH 36/39] chore: update fee plug address --- .env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index 50c563a..66b17b6 100644 --- a/.env.sample +++ b/.env.sample @@ -15,7 +15,7 @@ BASE_RPC="https://base.drpc.org" # https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json ADDRESS_RESOLVER="0x935b06902cA5C8bb4C76e18738561c294D377A93" FEES_MANAGER="0xA07208F9e7aE243F922317ab6604DC9F86822406" -ARBITRUM_FEES_PLUG="0xfA768B7E490524475B5B96521d4C61D5b976c3C9" +ARBITRUM_FEES_PLUG="0x501bdF8C7163ddD32172575C2836c5A7F556cbE7" ARBITRUM_USDC="0xaf88d065e77c8cC2239327C5EDb3A432268e5831" # Add your deployer private key here From 71ac547e38938a0c06210903625678ffb6089bf8 Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:13:34 +0100 Subject: [PATCH 37/39] Update socket-protocol submodule to latest master --- .gitmodules | 2 +- lib/socket-protocol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index c6035df..b41225c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,4 @@ [submodule "lib/socket-protocol"] path = lib/socket-protocol url = https://github.com/SocketDotTech/socket-protocol.git - branch = dev + branch = master diff --git a/lib/socket-protocol b/lib/socket-protocol index dc173ae..b5b5c7f 160000 --- a/lib/socket-protocol +++ b/lib/socket-protocol @@ -1 +1 @@ -Subproject commit dc173aea1bfcec23d39c16b9e1ec43333f7fba72 +Subproject commit b5b5c7f86430b984f91892ee7097ba5355ba231a From df0fe79730b9deb92d528c5eaf428ad1214c5cff Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:36:31 +0100 Subject: [PATCH 38/39] chore: update constants --- script/utils/constants.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/utils/constants.ts b/script/utils/constants.ts index c4bc8a5..0fd091e 100644 --- a/script/utils/constants.ts +++ b/script/utils/constants.ts @@ -17,8 +17,8 @@ export const URLS = { } as const; export const AMOUNTS = { - DEPLOY_FEES: parseEther('10'), // 10 ETH - TEST_USDC: 10000000n, // 10 TEST USDC + DEPLOY_FEES: parseEther('1'), // 1 ETH + TEST_USDC: 1000000n, // 1 USDC for testing GAS_BUFFER: 100000000n, // 0.1 Gwei GAS_LIMIT: 50000000000n, // Gas limit estimate } as const; From a2ec883f9ed9ba9e24f89739b0b1e3a261707e8b Mon Sep 17 00:00:00 2001 From: Rookmate <14072042+rookmate@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:37:20 +0100 Subject: [PATCH 39/39] fix: deposit funds function --- script/utils/fees-manager.ts | 77 ++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/script/utils/fees-manager.ts b/script/utils/fees-manager.ts index 6bf8df7..cc9d336 100644 --- a/script/utils/fees-manager.ts +++ b/script/utils/fees-manager.ts @@ -64,41 +64,42 @@ export async function depositFunds( 'function wrap(address appGateway)' ]); - if (balance > 0n) { + if (balance > AMOUNTS.DEPLOY_FEES) { sendTransaction( process.env.FEES_MANAGER as Address, 'wrap', [appGateway], evmxChain, feesAbi, - parseEther('10') + AMOUNTS.DEPLOY_FEES + ); + } else { + console.log(`Not enough EVMx balance. Depositing ${AMOUNTS.TEST_USDC} Arbitrum USDC in wei.`); + const erc20Abi = parseAbi([ + 'function approve(address spender, uint256 amount) external returns (bool)' + ]); + + const walletAddress = arbChain.walletClient.account?.address; + if (!walletAddress) throw new Error('Wallet address not found'); + + // Approve USDC for FeesPlug + await sendTransaction( + process.env.ARBITRUM_USDC as Address, + 'approve', + [process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC], + arbChain, + erc20Abi ); - } - //const erc20Abi = parseAbi([ - // 'function approve(address spender, uint256 amount) external returns (bool)' - //]); - - //const walletAddress = arbChain.walletClient.account?.address; - //if (!walletAddress) throw new Error('Wallet address not found'); - - //// Approve USDC for FeesPlug - //await sendTransaction( - // process.env.ARBITRUM_USDC as Address, - // 'approve', - // [process.env.ARBITRUM_FEES_PLUG as Address, AMOUNTS.TEST_USDC], - // arbChain, - // erc20Abi - //); - - //// Deposit funds - //await sendTransaction( - // process.env.ARBITRUM_FEES_PLUG as Address, - // 'depositCreditAndNative', - // [process.env.ARBITRUM_USDC as Address, appGateway, AMOUNTS.TEST_USDC], - // arbChain, - // feesPlugAbi - //); + // Deposit funds + await sendTransaction( + process.env.ARBITRUM_FEES_PLUG as Address, + 'depositCreditAndNative', + [process.env.ARBITRUM_USDC as Address, evmxChain.walletClient.account?.address, AMOUNTS.TEST_USDC], + arbChain, + feesAbi + ); + } await checkAvailableFees(appGateway, evmxChain); } @@ -123,6 +124,20 @@ export async function withdrawFunds( 'function transferCredits(address to_, uint256 amount_) external' ]); + await sendTransaction( + appGateway, + 'transferCredits', + [evmxChain.walletClient.account?.address, availableFees], + evmxChain, + abi + ); + + // TODO: Move the code below to a withdraw example as separate test that shows: + // - transfering credits + // - wraping credits + // - wraping natives + // - withdrawing to mainnet + //let amountToWithdraw = availableFees - AMOUNTS.DEPLOY_FEES; //console.log(`Withdrawing ${formatEther(amountToWithdraw)} Credits - ${amountToWithdraw} wei`); @@ -141,12 +156,4 @@ export async function withdrawFunds( //// transfer the rest to the EOA //availableFees = await checkAvailableFees(appGateway, evmxChain); - - await sendTransaction( - appGateway, - 'transferCredits', - [evmxChain.walletClient.account?.address, availableFees], - evmxChain, - abi - ); }