diff --git a/README.md b/README.md index 460aef7..fe856d7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Follow these steps to deploy and run the EVMx Read tests. ### 1. **Deploy the EVMx Read Tests Script** Run the following command to deploy the EVMx Read tests script: ```bash -forge script script/read/DeployEVMxReadTests.sol --broadcast --legacy --with-gas-price 0 +forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployAppGateway()" ``` ### 1a. **Verify the EVMx Contract** @@ -41,6 +41,67 @@ Finally, run the EVMx Read script: forge script script/read/RunEVMxRead.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy ``` +### 6. Withdraw funds +```bash +forge script script/inbox/RunEVMxRead.s.sol --broadcast --sig "withdrawAppFees()" --legacy --with-gas-price 0 +``` + +# Deployment Steps for EVMx Inbox Tests + +Follow these steps to deploy and run the EVMx Inbox tests. + +### 1. **Deploy the EVMx Inbox Tests Script** +Run the following command to deploy the EVMx Inbox tests script: +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployAppGateway()" +``` + +### 1a. **Verify the EVMx Contract** +Verify the `InboxAppGateway` contract on Blockscout: +```bash +forge verify-contract --rpc-url https://rpc-evmx-devnet.socket.tech/ --verifier blockscout --verifier-url https://evmx.cloud.blockscout.com/api src/inbox/InboxAppGateway.sol:InboxAppGateway +``` + +### 2. **Update the `APP_GATEWAY` in `.env`** +Make sure to update the `APP_GATEWAY` address in your `.env` file. + +### 3. **Pay Fees in Arbitrum ETH** +Run the script to pay fees in Arbitrum ETH: +```bash +forge script lib/socket-protocol/script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +``` + +### 4. **Deploy Onchain Contracts** +Deploy the onchain contracts using the following script: +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployOnchainContracts()" +``` + +### 4a. **Verify the Onchain Contract** +Verify the `InboxMultichain` contract on Arbitrum Sepolia Blockscout: +```bash +forge verify-contract --rpc-url https://rpc.ankr.com/arbitrum_sepolia --verifier-url https://arbitrum-sepolia.blockscout.com/api --verifier blockscout src/inbox/Inbox.sol:Inbox +``` + +### 5. **Run EVMx Inbox Script** +Finally, run the EVMx Inbox script: +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --sig "onchainToEVMx()" +``` + +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --legacy --with-gas-price 0 --sig "eVMxToOnchain()" +``` + +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --sig "onchainToOnchain()" +``` + +### 6. Withdraw funds +```bash +forge script script/inbox/RunEVMxInbox.s.sol --broadcast --sig "withdrawAppFees()" --legacy --with-gas-price 0 +``` + # Deployment Steps for EVMx Write Tests Follow these steps to deploy and run the EVMx Write tests. @@ -48,7 +109,7 @@ Follow these steps to deploy and run the EVMx Write tests. ### 1. **Deploy the EVMx Write Tests Script** Run the following command to deploy the EVMx Write tests script: ```bash -forge script script/write/DeployEVMxWriteTests.sol --broadcast --legacy --with-gas-price 0 +forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy --sig "deployAppGateway()" ``` ### 1a. **Verify the Contract** @@ -83,3 +144,8 @@ Finally, run the EVMx Write script: ```bash forge script script/write/RunEVMxWrite.s.sol --broadcast --skip-simulation --with-gas-price 0 --legacy ``` + +### 6. Withdraw funds +```bash +forge script script/inbox/RunEVMxWrite.s.sol --broadcast --sig "withdrawAppFees()" --legacy --with-gas-price 0 +``` diff --git a/script/SetupScript.sol b/script/SetupScript.sol index 656705e..40657e4 100644 --- a/script/SetupScript.sol +++ b/script/SetupScript.sol @@ -18,6 +18,7 @@ abstract contract SetupScript is Script { // ----- ENVIRONMENT VARIABLES ----- string rpcEVMx = vm.envString("EVMX_RPC"); string rpcArbSepolia = vm.envString("ARBITRUM_SEPOLIA_RPC"); + string rpcOPSepolia = vm.envString("OPTIMISM_SEPOLIA_RPC"); address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); address feesPlugArbSepolia = vm.envAddress("ARBITRUM_FEES_PLUG"); address feesManagerAddress = vm.envAddress("FEES_MANAGER"); @@ -30,6 +31,7 @@ abstract contract SetupScript is Script { uint32[2] chainIds = [opSepChainId, arbSepChainId]; Fees fees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.001 ether}); + Fees deployFees = Fees({feePoolChain: arbSepChainId, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); FeesManager feesManager = FeesManager(payable(feesManagerAddress)); FeesPlug feesPlug = FeesPlug(payable(feesPlugArbSepolia)); @@ -46,7 +48,7 @@ abstract contract SetupScript is Script { console.log("Available fees:", availableFees); } - function withdrawAppFees(uint32 chainId) internal { + function _withdrawAppFees(uint32 chainId) internal { // EVMX Check available fees vm.createSelectFork(rpcEVMx); @@ -59,7 +61,7 @@ abstract contract SetupScript is Script { // Gas price from Arbitrum uint256 arbitrumGasPrice = block.basefee + 0.1 gwei; // With buffer - uint256 gasLimit = 5_000_000; // Estimate + uint256 gasLimit = 4_000_000; // Estimate uint256 estimatedGasCost = gasLimit * arbitrumGasPrice; console.log("Arbitrum gas price (wei):", arbitrumGasPrice); @@ -99,9 +101,28 @@ abstract contract SetupScript is Script { console.log("Contracts deployed"); } + // Deploy new AppGateway on EVMx + function _deployAppGateway() internal virtual returns (address newAppGateway) { + vm.createSelectFork(rpcEVMx); + vm.startBroadcast(privateKey); + + newAppGateway = deployAppGatewayContract(); + + vm.stopBroadcast(); + + console.log("New AppGateway deployed at:", newAppGateway); + console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", newAppGateway); + console.log("Set APP_GATEWAY environment variable to:", newAppGateway); + + return newAppGateway; + } + // Abstract functions to be implemented by child contracts function appGateway() internal view virtual returns (address); + // Function to be overridden by child contracts to deploy specific AppGateway implementation + function deployAppGatewayContract() internal virtual returns (address); + // Standard flow // Each implementation script will call these functions function _run(uint32 chainId) internal { @@ -109,7 +130,6 @@ abstract contract SetupScript is Script { if (availableFees > 0) { executeScriptSpecificLogic(); - withdrawAppFees(chainId); } else { console.log("NO AVAILABLE FEES - Please deposit fees before running this script"); } diff --git a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol b/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol deleted file mode 100644 index 309abed..0000000 --- a/script/deployment-mistakes/DeployEVMxDeploymentMistakesApp.s.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; - -import {DeploymentMistakesAppGateway} from "../../src/deployment-mistakes/DeploymentMistakesAppGateway.sol"; - -contract DeployEVMxContracts is Script { - function run() external { - address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - string memory rpc = vm.envString("EVMX_RPC"); - vm.createSelectFork(rpc); - - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(deployerPrivateKey); - - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - - DeploymentMistakesAppGateway appGateway = new DeploymentMistakesAppGateway(addressResolver, fees); - - console.log("Contracts deployed:"); - console.log("DeploymentMistakesAppGateway:", address(appGateway)); - console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); - } -} diff --git a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol index 12e8584..17d79bd 100644 --- a/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol +++ b/script/deployment-mistakes/RunEVMxDeploymentMistakes.s.sol @@ -26,6 +26,12 @@ contract RunEVMxDeploymentMistakes is SetupScript { return address(mistakesAppGateway); } + function deployAppGatewayContract() internal override returns (address) { + // Deploy DeploymentMistakesAppGateway + DeploymentMistakesAppGateway newGateway = new DeploymentMistakesAppGateway(addressResolver, deployFees); + return address(newGateway); + } + function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); @@ -111,12 +117,27 @@ contract RunEVMxDeploymentMistakes is SetupScript { validateMistakes(); } - function run() external { - _run(arbSepChainId); + function run() external pure { + console.log( + "Please call one of these external functions: deployAppGateway(), deployOnchainContracts(), or runTests()" + ); + } + + function deployAppGateway() external { + _deployAppGateway(); + } + + function withdrawAppFees() external { + init(); + _withdrawAppFees(arbSepChainId); } function deployOnchainContracts() external { init(); _deployOnchainContracts(); } + + function runTests() external { + _run(arbSepChainId); + } } diff --git a/script/inbox/DeployEVMxInbox.s.sol b/script/inbox/DeployEVMxInbox.s.sol deleted file mode 100644 index 88c7a4b..0000000 --- a/script/inbox/DeployEVMxInbox.s.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; - -import {InboxAppGateway} from "../../src/inbox/InboxAppGateway.sol"; - -contract DeployEVMxContracts is Script { - function run() external { - address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - string memory rpc = vm.envString("EVMX_RPC"); - vm.createSelectFork(rpc); - - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(deployerPrivateKey); - - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - - InboxAppGateway appGateway = new InboxAppGateway(addressResolver, fees); - - console.log("Contracts deployed:"); - console.log("AppGateway:", address(appGateway)); - console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); - } -} diff --git a/script/inbox/RunEVMxInbox.s.sol b/script/inbox/RunEVMxInbox.s.sol index c86c94a..7262376 100644 --- a/script/inbox/RunEVMxInbox.s.sol +++ b/script/inbox/RunEVMxInbox.s.sol @@ -3,17 +3,27 @@ pragma solidity ^0.8.0; import {console} from "forge-std/console.sol"; import {SetupScript} from "../SetupScript.sol"; -import {InboxAppGateway, IInbox} from "../../src/inbox/InboxAppGateway.sol"; +import {InboxAppGateway} from "../../src/inbox/InboxAppGateway.sol"; +import {IInbox} from "../../src/inbox/IInbox.sol"; contract RunEVMxInbox is SetupScript { InboxAppGateway inboxAppGateway; address opSepForwarder; address arbSepForwarder; + address opSepInboxAddress; + address arbSepInboxAddress; + uint8 step; function appGateway() internal view override returns (address) { return address(inboxAppGateway); } + function deployAppGatewayContract() internal override returns (address) { + // Deploy InboxAppGateway + InboxAppGateway newGateway = new InboxAppGateway(addressResolver, deployFees); + return address(newGateway); + } + function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); opSepForwarder = inboxAppGateway.forwarderAddresses(inboxAppGateway.inbox(), opSepChainId); @@ -24,21 +34,34 @@ contract RunEVMxInbox is SetupScript { } function inboxTransactions() internal { - address opSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), opSepChainId); - address arbSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), arbSepChainId); + // TODO: Emit event on each update to easily track and update + if (step == 1) { + vm.createSelectFork(rpcArbSepolia); + vm.startBroadcast(privateKey); - vm.createSelectFork(rpcEVMx); - vm.startBroadcast(privateKey); + IInbox(arbSepInboxAddress).increaseOnGateway(5); + + vm.stopBroadcast(); + console.log("Increase on AppGateway executed successfully"); + } else if (step == 2) { + // TODO: Emit event on each update to easily track and update + vm.createSelectFork(rpcEVMx); + vm.startBroadcast(privateKey); + + inboxAppGateway.updateOnchain(opSepChainId); + + vm.stopBroadcast(); + console.log("Update on Optimism Sepolia from AppGateway executed successfully"); + } else if (step == 3) { + // TODO: Emit event on each update to easily track and update + vm.createSelectFork(rpcOPSepolia); + vm.startBroadcast(privateKey); - IInbox(opSepInboxAddress).increaseOnGateway(5); - require(inboxAppGateway.valueOnGateway() != 5, "Expected the same value"); - inboxAppGateway.updateOnchain(opSepChainId); - require(IInbox(opSepInboxAddress).value() != 5, "Expected the same value"); - IInbox(opSepInboxAddress).propagateToAnother(arbSepChainId); - require(IInbox(arbSepInboxAddress).value() != 5, "Expected the same value"); + IInbox(opSepInboxAddress).propagateToAnother(arbSepChainId); - vm.stopBroadcast(); - console.log("All inbox transactions executed successfully"); + vm.stopBroadcast(); + console.log("Update on Arbitrum Sepolia from AppGateway executed successfully"); + } } // Initialize contract references @@ -49,15 +72,43 @@ contract RunEVMxInbox is SetupScript { function executeScriptSpecificLogic() internal override { init(); getForwarderAddresses(); + opSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), opSepChainId); + arbSepInboxAddress = inboxAppGateway.getOnChainAddress(inboxAppGateway.inbox(), arbSepChainId); inboxTransactions(); } - function run() external { - _run(arbSepChainId); + function run() external pure { + console.log( + "Please call one of these external functions: deployAppGateway(), deployOnchainContracts(), onchainToEVMx(), eVMxToOnchain(), or onchainToOnchain()" + ); + } + + function deployAppGateway() external { + _deployAppGateway(); + } + + function withdrawAppFees() external { + init(); + _withdrawAppFees(arbSepChainId); } function deployOnchainContracts() external { init(); _deployOnchainContracts(); } + + function onchainToEVMx() external { + step = 1; + _run(arbSepChainId); + } + + function eVMxToOnchain() external { + step = 2; + _run(arbSepChainId); + } + + function onchainToOnchain() external { + step = 3; + _run(arbSepChainId); + } } diff --git a/script/read/DeployEVMxReadTests.sol b/script/read/DeployEVMxReadTests.sol deleted file mode 100644 index 763c6be..0000000 --- a/script/read/DeployEVMxReadTests.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; - -import {ReadAppGateway} from "../../src/read/ReadAppGateway.sol"; - -contract DeployEVMxContracts is Script { - function run() external { - address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - string memory rpc = vm.envString("EVMX_RPC"); - vm.createSelectFork(rpc); - - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(deployerPrivateKey); - - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - - ReadAppGateway appGateway = new ReadAppGateway(addressResolver, fees); - - console.log("Contracts deployed:"); - console.log("AppGateway:", address(appGateway)); - console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); - } -} diff --git a/script/read/RunEVMxRead.s.sol b/script/read/RunEVMxRead.s.sol index b5aa387..8ce6889 100644 --- a/script/read/RunEVMxRead.s.sol +++ b/script/read/RunEVMxRead.s.sol @@ -14,6 +14,12 @@ contract RunEVMxRead is SetupScript { return address(readAppGateway); } + function deployAppGatewayContract() internal override returns (address) { + // Deploy ReadAppGateway + ReadAppGateway newGateway = new ReadAppGateway(addressResolver, deployFees); + return address(newGateway); + } + function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); opSepForwarder = readAppGateway.forwarderAddresses(readAppGateway.multichain(), opSepChainId); @@ -68,12 +74,27 @@ contract RunEVMxRead is SetupScript { runAllTriggers(); } - function run() external { - _run(arbSepChainId); + function run() external pure { + console.log( + "Please call one of these external functions: deployAppGateway(), deployOnchainContracts(), or runTriggers()" + ); + } + + function deployAppGateway() external { + _deployAppGateway(); + } + + function withdrawAppFees() external { + init(); + _withdrawAppFees(arbSepChainId); } function deployOnchainContracts() external { init(); _deployOnchainContracts(); } + + function runTriggers() external { + _run(arbSepChainId); + } } diff --git a/script/write/DeployEVMxWriteTests.sol b/script/write/DeployEVMxWriteTests.sol deleted file mode 100644 index 44f65fe..0000000 --- a/script/write/DeployEVMxWriteTests.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import {Script} from "forge-std/Script.sol"; -import {console} from "forge-std/console.sol"; -import {Fees} from "socket-protocol/contracts/protocol/utils/common/Structs.sol"; -import {ETH_ADDRESS} from "socket-protocol/contracts/protocol/utils/common/Constants.sol"; - -import {WriteAppGateway} from "../../src/write/WriteAppGateway.sol"; - -contract DeployEVMxContracts is Script { - function run() external { - address addressResolver = vm.envAddress("ADDRESS_RESOLVER"); - string memory rpc = vm.envString("EVMX_RPC"); - vm.createSelectFork(rpc); - - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(deployerPrivateKey); - - Fees memory fees = Fees({feePoolChain: 421614, feePoolToken: ETH_ADDRESS, amount: 0.0005 ether}); - - WriteAppGateway appGateway = new WriteAppGateway(addressResolver, fees); - - console.log("Contracts deployed:"); - console.log("AppGateway:", address(appGateway)); - console.log("See AppGateway on EVMx: https://evmx.cloud.blockscout.com/address/%s", address(appGateway)); - } -} diff --git a/script/write/RunEVMxWrite.s.sol b/script/write/RunEVMxWrite.s.sol index 5bc82fd..2f2c848 100644 --- a/script/write/RunEVMxWrite.s.sol +++ b/script/write/RunEVMxWrite.s.sol @@ -14,6 +14,12 @@ contract RunEVMxWrite is SetupScript { return address(writeAppGateway); } + function deployAppGatewayContract() internal override returns (address) { + // Deploy WriteAppGateway + WriteAppGateway newGateway = new WriteAppGateway(addressResolver, deployFees); + return address(newGateway); + } + function getForwarderAddresses() internal { vm.createSelectFork(rpcEVMx); opSepForwarder = writeAppGateway.forwarderAddresses(writeAppGateway.multichain(), opSepChainId); @@ -62,12 +68,27 @@ contract RunEVMxWrite is SetupScript { checkResults(); } - function run() external { - _run(arbSepChainId); + function run() external pure { + console.log( + "Please call one of these external functions: deployAppGateway(), deployOnchainContracts(), or runTriggers()" + ); + } + + function deployAppGateway() external { + _deployAppGateway(); + } + + function withdrawAppFees() external { + init(); + _withdrawAppFees(arbSepChainId); } function deployOnchainContracts() external { init(); _deployOnchainContracts(); } + + function runTriggers() external { + _run(arbSepChainId); + } } diff --git a/src/inbox/IInbox.sol b/src/inbox/IInbox.sol new file mode 100644 index 0000000..90044f6 --- /dev/null +++ b/src/inbox/IInbox.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +interface IInbox { + function value() external returns (uint256); + function increaseOnGateway(uint256 value_) external returns (bytes32); + function propagateToAnother(uint32 targetChain) external returns (bytes32); + function updateFromGateway(uint256 value) external; +} diff --git a/src/inbox/InboxAppGateway.sol b/src/inbox/InboxAppGateway.sol index 62c5627..0865461 100644 --- a/src/inbox/InboxAppGateway.sol +++ b/src/inbox/InboxAppGateway.sol @@ -3,22 +3,7 @@ pragma solidity ^0.8.0; import "socket-protocol/contracts/base/AppGatewayBase.sol"; import "./Inbox.sol"; - -interface IInboxDeployer { - function inbox() external pure returns (bytes32 bytecode); - - function forwarderAddresses(bytes32 contractId_, uint32 chainSlug_) - external - view - returns (address forwarderAddress); -} - -interface IInbox { - function value() external returns (uint256); - function increaseOnGateway(uint256 value_) external returns (bytes32); - function propagateToAnother(uint32 targetChain) external returns (bytes32); - function updateFromGateway(uint256 value) external; -} +import "./IInbox.sol"; contract InboxAppGateway is AppGatewayBase { bytes32 public inbox = _createContractId("inbox"); @@ -38,25 +23,28 @@ contract InboxAppGateway is AppGatewayBase { _deploy(inbox, chainSlug_, IsPlug.YES); } - function initialize(uint32) public pure override { - return; + function initialize(uint32 chainSlug_) public override { + setValidPlug(chainSlug_, inbox, true); } - function updateOnchain(uint32 targetChain) public { - address inboxForwarderAddress = - IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + function updateOnchain(uint32 targetChain) public async { + address inboxForwarderAddress = forwarderAddresses[inbox][targetChain]; IInbox(inboxForwarderAddress).updateFromGateway(valueOnGateway); } - function callFromChain(uint32, address, bytes calldata payload_, bytes32) external override onlyWatcherPrecompile { + function callFromChain(uint32, address, bytes calldata payload_, bytes32) + external + override + async + onlyWatcherPrecompile + { (uint32 msgType, bytes memory payload) = abi.decode(payload_, (uint32, bytes)); if (msgType == INCREASE_ON_GATEWAY) { uint256 valueOnchain = abi.decode(payload, (uint256)); valueOnGateway += valueOnchain; } else if (msgType == PROPAGATE_TO_ANOTHER) { (uint256 valueOnchain, uint32 targetChain) = abi.decode(payload, (uint256, uint32)); - address inboxForwarderAddress = - IInboxDeployer(deployerAddress).forwarderAddresses(IInboxDeployer(deployerAddress).inbox(), targetChain); + address inboxForwarderAddress = forwarderAddresses[inbox][targetChain]; IInbox(inboxForwarderAddress).updateFromGateway(valueOnchain); } else { revert("InboxGateway: invalid message type"); @@ -67,6 +55,16 @@ contract InboxAppGateway is AppGatewayBase { fees = fees_; } + /// @notice Sets the validity of an on-chain contract (plug) to authorize it to send information to a specific AppGateway + /// @param chainSlug_ The unique identifier of the chain where the contract resides + /// @param contractId The bytes32 identifier of the contract to be validated + /// @param isValid Boolean flag indicating whether the contract is authorized (true) or not (false) + /// @dev This function retrieves the onchain address using the contractId and chainSlug, then calls the watcher precompile to update the plug's validity status + function setValidPlug(uint32 chainSlug_, bytes32 contractId, bool isValid) public { + address onchainAddress = getOnChainAddress(contractId, chainSlug_); + watcherPrecompile__().setIsValidPlug(chainSlug_, onchainAddress, isValid); + } + function withdrawFeeTokens(uint32 chainSlug_, address token_, uint256 amount_, address receiver_) external { _withdrawFeeTokens(chainSlug_, token_, amount_, receiver_); }