From 6de98d40979b6235c0cc4dd1a9ed2a5ad469947b Mon Sep 17 00:00:00 2001 From: Akash Date: Fri, 2 May 2025 17:39:56 +0530 Subject: [PATCH 1/4] fix : deployment --- EventTopics.md | 24 ++++---- .../protocol/payload-delivery/FeesPlug.sol | 19 ++++--- deployments/dev_addresses.json | 4 +- deployments/dev_verification.json | 57 ++++++++++++++++--- hardhat-scripts/deploy/1.deploy.ts | 3 +- hardhat-scripts/deploy/4.connect.ts | 25 ++++++-- hardhat-scripts/deploy/6.setupEnv.ts | 4 ++ package.json | 2 +- script/counter/DeployEVMxCounterApp.s.sol | 2 +- .../helpers/PayFeesInArbitrumTestUSDC.s.sol | 35 ++++++++++++ 10 files changed, 137 insertions(+), 38 deletions(-) create mode 100644 script/helpers/PayFeesInArbitrumTestUSDC.s.sol diff --git a/EventTopics.md b/EventTopics.md index ada88250..cb976877 100644 --- a/EventTopics.md +++ b/EventTopics.md @@ -94,18 +94,18 @@ ## FeesPlug -| Event | Arguments | Topic | -| ---------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------- | -| `ConnectorPlugDisconnected` | `()` | `0xc2af098c82dba3c4b00be8bda596d62d13b98a87b42626fefa67e0bb0e198fdd` | -| `FeesDeposited` | `(token: address, receiver: address, feeAmount: uint256, nativeAmount: uint256)` | `0xeb4e1b24b7fe377de69f80f7380bda5ba4b43176c6a4d300a3be9009c49f4228` | -| `FeesWithdrawn` | `(token: address, receiver: address, amount: uint256)` | `0x5e110f8bc8a20b65dcc87f224bdf1cc039346e267118bae2739847f07321ffa8` | -| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | -| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | -| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | -| `RoleGranted` | `(role: bytes32, grantee: address)` | `0x2ae6a113c0ed5b78a53413ffbb7679881f11145ccfba4fb92e863dfcd5a1d2f3` | -| `RoleRevoked` | `(role: bytes32, revokee: address)` | `0x155aaafb6329a2098580462df33ec4b7441b19729b9601c5fc17ae1cf99a8a52` | -| `TokenRemovedFromWhitelist` | `(token: address)` | `0xdd2e6d9f52cbe8f695939d018b7d4a216dc613a669876163ac548b916489d917` | -| `TokenWhitelisted` | `(token: address)` | `0x6a65f90b1a644d2faac467a21e07e50e3f8fa5846e26231d30ae79a417d3d262` | +| Event | Arguments | Topic | +| ---------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------- | +| `ConnectorPlugDisconnected` | `()` | `0xc2af098c82dba3c4b00be8bda596d62d13b98a87b42626fefa67e0bb0e198fdd` | +| `FeesDeposited` | `(token: address, receiver: address, creditAmount: uint256, nativeAmount: uint256)` | `0xeb4e1b24b7fe377de69f80f7380bda5ba4b43176c6a4d300a3be9009c49f4228` | +| `FeesWithdrawn` | `(token: address, receiver: address, amount: uint256)` | `0x5e110f8bc8a20b65dcc87f224bdf1cc039346e267118bae2739847f07321ffa8` | +| `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | +| `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | +| `OwnershipTransferred` | `(oldOwner: address, newOwner: address)` | `0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0` | +| `RoleGranted` | `(role: bytes32, grantee: address)` | `0x2ae6a113c0ed5b78a53413ffbb7679881f11145ccfba4fb92e863dfcd5a1d2f3` | +| `RoleRevoked` | `(role: bytes32, revokee: address)` | `0x155aaafb6329a2098580462df33ec4b7441b19729b9601c5fc17ae1cf99a8a52` | +| `TokenRemovedFromWhitelist` | `(token: address)` | `0xdd2e6d9f52cbe8f695939d018b7d4a216dc613a669876163ac548b916489d917` | +| `TokenWhitelisted` | `(token: address)` | `0x6a65f90b1a644d2faac467a21e07e50e3f8fa5846e26231d30ae79a417d3d262` | ## Socket diff --git a/contracts/protocol/payload-delivery/FeesPlug.sol b/contracts/protocol/payload-delivery/FeesPlug.sol index 98ae9a46..4935afa9 100644 --- a/contracts/protocol/payload-delivery/FeesPlug.sol +++ b/contracts/protocol/payload-delivery/FeesPlug.sol @@ -27,7 +27,12 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl { error TokenNotWhitelisted(address token_); /// @notice Event emitted when fees are deposited - event FeesDeposited(address token, address receiver, uint256 feeAmount, uint256 nativeAmount); + event FeesDeposited( + address token, + address receiver, + uint256 creditAmount, + uint256 nativeAmount + ); /// @notice Event emitted when fees are withdrawn event FeesWithdrawn(address token, address receiver, uint256 amount); /// @notice Event emitted when a token is whitelisted @@ -73,8 +78,8 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl { uint256 amount_ ) external override { uint256 nativeAmount_ = amount_ / 10; - uint256 feeAmount_ = amount_ - nativeAmount_; - _deposit(token_, receiver_, feeAmount_, nativeAmount_); + uint256 creditAmount_ = amount_ - nativeAmount_; + _deposit(token_, receiver_, creditAmount_, nativeAmount_); } function depositToNative(address token_, address receiver_, uint256 amount_) external override { @@ -83,19 +88,19 @@ contract FeesPlug is IFeesPlug, PlugBase, AccessControl { /// @notice Deposits funds /// @param token_ The token address - /// @param feeAmount_ The amount of fees + /// @param creditAmount_ The amount of fees /// @param nativeAmount_ The amount of native tokens /// @param receiver_ The receiver address function _deposit( address token_, address receiver_, - uint256 feeAmount_, + uint256 creditAmount_, uint256 nativeAmount_ ) internal { - uint256 totalAmount_ = feeAmount_ + nativeAmount_; + uint256 totalAmount_ = creditAmount_ + nativeAmount_; if (!whitelistedTokens[token_]) revert TokenNotWhitelisted(token_); SafeTransferLib.safeTransferFrom(token_, msg.sender, address(this), totalAmount_); - emit FeesDeposited(receiver_, token_, feeAmount_, nativeAmount_); + emit FeesDeposited(token_, receiver_, creditAmount_, nativeAmount_); } /// @notice Adds a token to the whitelist diff --git a/deployments/dev_addresses.json b/deployments/dev_addresses.json index 326f1ff2..ee2e60eb 100644 --- a/deployments/dev_addresses.json +++ b/deployments/dev_addresses.json @@ -2,7 +2,7 @@ "421614": { "ContractFactoryPlug": "0x9dEa956E863a44a24c1CE068460E6190EA438602", "FastSwitchboard": "0xb4C5A231614639801F421Ca386388f65576F3c81", - "FeesPlug": "0xFF3639fD99515b40d8f6bC02AC1Fead65CAd93fD", + "FeesPlug": "0x2fc70A464588b3f692D5C500Bfe3A2F2165911aD", "Socket": "0xBd0436A6E0dee11e9359767142Ed6bD7B48ba258", "SocketBatcher": "0x1683c3AB4954852f71f400AbDeF98112a066ee44", "startBlock": 148461456, @@ -29,7 +29,7 @@ "11155420": { "ContractFactoryPlug": "0x95Be4D8500e3e5C970802c64b0755027d4Fc5C9F", "FastSwitchboard": "0xe7858f1dc202f5E9C9B3ee6db052F45164a88534", - "FeesPlug": "0x01bDCAB43c423D08BaCe87ED716280536dAB3eF3", + "FeesPlug": "0x29b77ecEf2D163528d1F4A235c0795daDD2DA1Bf", "Socket": "0xE09CC429e77EE5DBeF68f3796b2A33BBDF39C03C", "SocketBatcher": "0x9175d90706a2b17f0aE025ce5A6C76e64850c2f5", "startBlock": 27158986, diff --git a/deployments/dev_verification.json b/deployments/dev_verification.json index 1bd53705..3f734147 100644 --- a/deployments/dev_verification.json +++ b/deployments/dev_verification.json @@ -41,14 +41,29 @@ "0x89e66357C5F101C56b4F9F97cf378Cc32A21438a", "Socket", "contracts/protocol/socket/Socket.sol", + [84532, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"] + ] + ], + "421614": [ + [ + "0x092194e4Cd90d950ED91bD216472A18cCA7cd8F7", + "FeesPlug", + "contracts/protocol/payload-delivery/FeesPlug.sol", [ - 84532, - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", - "EVMX" + "0xBd0436A6E0dee11e9359767142Ed6bD7B48ba258", + "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" + ] + ], + [ + "0x44f182553Ccdd82f95b592a935Bd7Dd90FF7F292", + "FeesPlug", + "contracts/protocol/payload-delivery/FeesPlug.sol", + [ + "0xBd0436A6E0dee11e9359767142Ed6bD7B48ba258", + "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" ] ] ], - "421614": [], "7625382": [ [ "0x23364acdd298EBB3Dfd3c1835C5ACd7f77E3E2bD", @@ -207,12 +222,36 @@ "0xF86B89B5c689c170BfD2734254228D6d2db5a672", "Socket", "contracts/protocol/socket/Socket.sol", + [11155111, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"] + ] + ], + "11155420": [ + [ + "0x29b77ecEf2D163528d1F4A235c0795daDD2DA1Bf", + "FeesPlug", + "contracts/protocol/payload-delivery/FeesPlug.sol", [ - 11155111, - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", - "EVMX" + "0xE09CC429e77EE5DBeF68f3796b2A33BBDF39C03C", + "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" + ] + ], + [ + "0x78775DCd56fBdb903e4d83AE51924797a74AD49d", + "FeesPlug", + "contracts/protocol/payload-delivery/FeesPlug.sol", + [ + "0xE09CC429e77EE5DBeF68f3796b2A33BBDF39C03C", + "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" + ] + ], + [ + "0x8eD0cebe57236Bf85b0a74951CeE74357B1d381D", + "FeesPlug", + "contracts/protocol/payload-delivery/FeesPlug.sol", + [ + "0xE09CC429e77EE5DBeF68f3796b2A33BBDF39C03C", + "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" ] ] - ], - "11155420": [] + ] } diff --git a/hardhat-scripts/deploy/1.deploy.ts b/hardhat-scripts/deploy/1.deploy.ts index 892ac0a9..3063c4e8 100644 --- a/hardhat-scripts/deploy/1.deploy.ts +++ b/hardhat-scripts/deploy/1.deploy.ts @@ -424,7 +424,8 @@ async function updateContractSettings( if ( (typeof currentValue === "string" && currentValue.toLowerCase() !== String(requiredValue).toLowerCase()) || - (BigNumber.isBigNumber(currentValue) && currentValue !== requiredValue) + (BigNumber.isBigNumber(currentValue) && + currentValue.toString() !== requiredValue.toString()) ) { console.log({ setterMethod, diff --git a/hardhat-scripts/deploy/4.connect.ts b/hardhat-scripts/deploy/4.connect.ts index dd51974e..71223808 100644 --- a/hardhat-scripts/deploy/4.connect.ts +++ b/hardhat-scripts/deploy/4.connect.ts @@ -1,4 +1,4 @@ -import { Contract, ethers, Wallet } from "ethers"; +import { constants, Contract, ethers, Wallet } from "ethers"; import { ChainAddressesObj, ChainSlug } from "../../src"; import { chains, EVMX_CHAIN_ID, mode } from "../config"; import { @@ -47,10 +47,24 @@ export const checkIfAddressExists = (address: string, name: string) => { address == "0x" || address.length != 42 ) { - throw Error(`${name} not found`); + throw Error(`${name} not found : ${address}`); } return address; }; +export const checkIfAppGatewayIdExists = ( + appGatewayId: string, + name: string +) => { + if ( + appGatewayId == constants.HashZero || + !appGatewayId || + appGatewayId == "0x" || + appGatewayId.length != 66 + ) { + throw Error(`${name} not found : ${appGatewayId}`); + } + return appGatewayId; +}; export const isConfigSetOnSocket = async ( plug: Contract, @@ -88,6 +102,7 @@ async function connectPlug( const switchboard = addr[CORE_CONTRACTS.FastSwitchboard]; checkIfAddressExists(switchboard, "Switchboard"); const appGatewayId = getAppGatewayId(plugContract, addresses); + checkIfAppGatewayIdExists(appGatewayId, "AppGatewayId"); // Check if config is already set if (await isConfigSetOnSocket(plug, socket, appGatewayId, switchboard)) { console.log(`${plugContract} Socket Config on ${chain} already set!`); @@ -128,12 +143,12 @@ export const isConfigSetOnEVMx = async ( watcher: Contract, chain: number, plug: string, - appGateway: string, + appGatewayId: string, switchboard: string ) => { const plugConfigRegistered = await watcher.getPlugConfigs(chain, plug); return ( - plugConfigRegistered[0].toLowerCase() === appGateway?.toLowerCase() && + plugConfigRegistered[0].toLowerCase() === appGatewayId?.toLowerCase() && plugConfigRegistered[1].toLowerCase() === switchboard.toLowerCase() ); }; @@ -165,7 +180,7 @@ export const updateConfigEVMx = async () => { const appGatewayId = getAppGatewayId(plugContract, addresses); const switchboard = addr[CORE_CONTRACTS.FastSwitchboard]; checkIfAddressExists(switchboard, "Switchboard"); - checkIfAddressExists(appGatewayId, "AppGateway"); + checkIfAppGatewayIdExists(appGatewayId, "AppGatewayId"); if ( await isConfigSetOnEVMx( diff --git a/hardhat-scripts/deploy/6.setupEnv.ts b/hardhat-scripts/deploy/6.setupEnv.ts index 6f9a7f83..1fe5cc72 100644 --- a/hardhat-scripts/deploy/6.setupEnv.ts +++ b/hardhat-scripts/deploy/6.setupEnv.ts @@ -39,6 +39,10 @@ const updatedLines = lines.map((line) => { return `ARBITRUM_FEES_PLUG=${ latestAddresses[ChainSlug.ARBITRUM_SEPOLIA]["FeesPlug"] }`; + } else if (line.startsWith("ARBITRUM_TEST_USDC=")) { + return `ARBITRUM_TEST_USDC=${ + latestAddresses[ChainSlug.ARBITRUM_SEPOLIA]["TestUSDC"] + }`; } return line; // Return the line unchanged if it doesn't match any of the above }); diff --git a/package.json b/package.json index 3ed39c3b..4600ccf9 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "publishConfig": { "access": "public" }, - "version": "1.1.12", + "version": "1.1.14", "description": "socket protocol", "scripts": { "build": "yarn abi && tsc --project lib.tsconfig.json", diff --git a/script/counter/DeployEVMxCounterApp.s.sol b/script/counter/DeployEVMxCounterApp.s.sol index 85755639..42c09af7 100644 --- a/script/counter/DeployEVMxCounterApp.s.sol +++ b/script/counter/DeployEVMxCounterApp.s.sol @@ -17,7 +17,7 @@ contract CounterDeploy is Script { vm.startBroadcast(deployerPrivateKey); // Setting fee payment on Arbitrum Sepolia - uint256 fees = 0.00001 ether; + uint256 fees = 10 ether; CounterAppGateway gateway = new CounterAppGateway(addressResolver, fees); diff --git a/script/helpers/PayFeesInArbitrumTestUSDC.s.sol b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol new file mode 100644 index 00000000..5b280f39 --- /dev/null +++ b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity ^0.8.21; + +import {Script} from "forge-std/Script.sol"; +import {console} from "forge-std/console.sol"; +import {FeesPlug} from "../../contracts/protocol/payload-delivery/FeesPlug.sol"; +import {ETH_ADDRESS} from "../../contracts/protocol/utils/common/Constants.sol"; +import {TestUSDC} from "../../contracts/helpers/TestUSDC.sol"; +// source .env && forge script script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation +contract DepositFees is Script { + function run() external { + uint256 amount = 100000000; + vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); + + uint256 privateKey = vm.envUint("SPONSOR_KEY"); + vm.startBroadcast(privateKey); + FeesPlug feesPlug = FeesPlug(payable(vm.envAddress("ARBITRUM_FEES_PLUG"))); + address appGateway = vm.envAddress("APP_GATEWAY"); + TestUSDC testUSDCContract = TestUSDC(vm.envAddress("ARBITRUM_TEST_USDC")); + + // mint test USDC to sender + testUSDCContract.mint(vm.addr(privateKey), amount); + // approve fees plug to spend test USDC + testUSDCContract.approve(address(feesPlug), amount); + + address sender = vm.addr(privateKey); + console.log("Sender address:", sender); + uint256 balance = testUSDCContract.balanceOf(sender); + console.log("Sender balance in wei:", balance); + console.log("App Gateway:", appGateway); + console.log("Fees Plug:", address(feesPlug)); + uint feesAmount = 0.001 ether; + feesPlug.depositToFeeAndNative(address(testUSDCContract), appGateway, feesAmount); + } +} From 504d48a92082d146545106eb471df9b559aa1839 Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Fri, 2 May 2025 17:41:39 +0530 Subject: [PATCH 2/4] fix: override type --- contracts/protocol/utils/common/Structs.sol | 2 +- test/Inbox.t.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/protocol/utils/common/Structs.sol b/contracts/protocol/utils/common/Structs.sol index 74e7f50c..2f93bf17 100644 --- a/contracts/protocol/utils/common/Structs.sol +++ b/contracts/protocol/utils/common/Structs.sol @@ -95,10 +95,10 @@ struct PlugConfig { //trigger: struct TriggerParams { bytes32 triggerId; - bytes32 overrides; address plug; bytes32 appGatewayId; uint32 chainSlug; + bytes overrides; bytes payload; } // timeout: diff --git a/test/Inbox.t.sol b/test/Inbox.t.sol index f680f6de..c9306913 100644 --- a/test/Inbox.t.sol +++ b/test/Inbox.t.sol @@ -94,7 +94,7 @@ contract TriggerTest is DeliveryHelperTest { appGatewayId: _encodeAppGatewayId(address(gateway)), plug: address(counter), payload: payload, - overrides: bytes32(0) + overrides: bytes("") }); bytes memory watcherSignature = _createWatcherSignature( From cfe15e348282f71e56399ed275e167f0260c1d69 Mon Sep 17 00:00:00 2001 From: Akash Date: Fri, 2 May 2025 21:31:36 +0530 Subject: [PATCH 3/4] fix: removed finalize --- FunctionSignatures.md | 3 +-- contracts/interfaces/IWatcherPrecompile.sol | 5 ----- .../watcherPrecompile/core/WatcherPrecompile.sol | 14 -------------- deployments/dev_addresses.json | 4 ++-- deployments/dev_verification.json | 15 ++++++--------- package.json | 2 +- 6 files changed, 10 insertions(+), 33 deletions(-) diff --git a/FunctionSignatures.md b/FunctionSignatures.md index 17183218..e3ef596c 100644 --- a/FunctionSignatures.md +++ b/FunctionSignatures.md @@ -441,14 +441,13 @@ | `appGatewayCalled` | `0xc6767cf1` | | `appGatewayCaller` | `0x712b193a` | | `batchPayloadIds` | `0x02b74f98` | -| `callAppGateways` | `0xaef0b33d` | +| `callAppGateways` | `0x5c38ded5` | | `cancelOwnershipHandover` | `0x54d1f13d` | | `cancelRequest` | `0x50ad0779` | | `completeOwnershipHandover` | `0xf04e283e` | | `deliveryHelper__` | `0xc031dfb4` | | `evmxSlug` | `0x8bae77c2` | | `expiryTime` | `0x99bc0aea` | -| `finalize` | `0x7ffecf2e` | | `finalized` | `0x81c051de` | | `getBatchPayloadIds` | `0xfd83cd1f` | | `getBatches` | `0xcb95b7b3` | diff --git a/contracts/interfaces/IWatcherPrecompile.sol b/contracts/interfaces/IWatcherPrecompile.sol index 1265f677..0262a220 100644 --- a/contracts/interfaces/IWatcherPrecompile.sol +++ b/contracts/interfaces/IWatcherPrecompile.sol @@ -132,11 +132,6 @@ interface IWatcherPrecompile { bytes calldata signature_ ) external; - function finalize( - PayloadParams memory params_, - address transmitter_ - ) external returns (bytes32 digest); - function query(PayloadParams memory params_) external; function finalized( diff --git a/contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol b/contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol index 2898354c..878ef213 100644 --- a/contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol +++ b/contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol @@ -99,20 +99,6 @@ contract WatcherPrecompile is RequestHandler { ); } - // ================== Finalize functions ================== - - /// @notice Finalizes a payload request, requests the watcher to release the proofs to execute on chain - /// @param params_ The payload parameters - /// @param transmitter_ The address of the transmitter - /// @return The digest hash of the finalized payload - /// @dev This function finalizes a payload request and requests the watcher to release the proofs - function finalize( - PayloadParams memory params_, - address transmitter_ - ) external returns (bytes32) { - return _finalize(params_, transmitter_); - } - // ================== Query functions ================== /// @notice Creates a new query request diff --git a/deployments/dev_addresses.json b/deployments/dev_addresses.json index ee2e60eb..72af1b71 100644 --- a/deployments/dev_addresses.json +++ b/deployments/dev_addresses.json @@ -19,10 +19,10 @@ "FeesManager": "0xBf9529b5aA4a6a047Ff65CfAE9613A274C479143", "FeesManagerImpl": "0xB577c29F7Cbb1bBB314dD8E74059Aa5BF72838b0", "startBlock": 5537530, - "WatcherPrecompile": "0x68430a7f22125dd8b566f774AED05e868CA70fEA", + "WatcherPrecompile": "0xB0CC4C4a6706E265306daCa279Ce60D1052b2782", "WatcherPrecompileConfig": "0xD0F77272a5F0208f20c836bB4eeddbCE1e4aef9d", "WatcherPrecompileConfigImpl": "0x060b4a50EcCC9Cf329005c94406dd2886676F759", - "WatcherPrecompileImpl": "0x1BCe40d84499Db8E7Bc65277A32f0abd56588CC7", + "WatcherPrecompileImpl": "0xe1CA4da421C52161B4EecCE6F5Cb2937554e2958", "WatcherPrecompileLimits": "0x4A645F050166FaBdA7ce44BE90B0A61073C19696", "WatcherPrecompileLimitsImpl": "0x4Fd04B0D4903e630F169BB228be52750E6B5331a" }, diff --git a/deployments/dev_verification.json b/deployments/dev_verification.json index 3f734147..cb1975f3 100644 --- a/deployments/dev_verification.json +++ b/deployments/dev_verification.json @@ -65,6 +65,12 @@ ] ], "7625382": [ + [ + "0xe1CA4da421C52161B4EecCE6F5Cb2937554e2958", + "WatcherPrecompile", + "contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol", + [] + ], [ "0x23364acdd298EBB3Dfd3c1835C5ACd7f77E3E2bD", "AuctionManager", @@ -226,15 +232,6 @@ ] ], "11155420": [ - [ - "0x29b77ecEf2D163528d1F4A235c0795daDD2DA1Bf", - "FeesPlug", - "contracts/protocol/payload-delivery/FeesPlug.sol", - [ - "0xE09CC429e77EE5DBeF68f3796b2A33BBDF39C03C", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], [ "0x78775DCd56fBdb903e4d83AE51924797a74AD49d", "FeesPlug", diff --git a/package.json b/package.json index 4600ccf9..86bf9215 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "publishConfig": { "access": "public" }, - "version": "1.1.14", + "version": "1.1.15", "description": "socket protocol", "scripts": { "build": "yarn abi && tsc --project lib.tsconfig.json", From 9c1be2368e90c8122c04db28408cc3c588b4305a Mon Sep 17 00:00:00 2001 From: Akash Date: Fri, 2 May 2025 23:37:20 +0530 Subject: [PATCH 4/4] fix: stage deploy --- deployments/stage_addresses.json | 82 +++++------ deployments/stage_verification.json | 128 ++---------------- hardhat-scripts/config/config.ts | 33 ++++- hardhat-scripts/constants/roles.ts | 1 + hardhat-scripts/deploy/1.deploy.ts | 62 +++++++++ hardhat-scripts/deploy/2.roles.ts | 6 +- script/admin/RescueFunds.s.sol | 70 ++++++++++ .../helpers/PayFeesInArbitrumTestUSDC.s.sol | 8 +- setupInfraContracts.sh | 1 + 9 files changed, 222 insertions(+), 169 deletions(-) create mode 100644 script/admin/RescueFunds.s.sol diff --git a/deployments/stage_addresses.json b/deployments/stage_addresses.json index 61a298c8..d950e823 100644 --- a/deployments/stage_addresses.json +++ b/deployments/stage_addresses.json @@ -1,52 +1,54 @@ { "43": { - "AddressResolver": "0x4846430BB142385e581C894AE92a4CF0722aEC21", - "AddressResolverImpl": "0x0F13F50f7dED1da9A4845366C2AB5120a1A17549", - "AuctionManager": "0x222574Dab9bb404Cb49a9445CD4d9555e8B52Cf5", - "AuctionManagerImpl": "0xbe1b573aa1B6ddD1A7a27aE0Aa6A38FA5d26fc67", - "DeliveryHelper": "0x436Ea32C3198500d113B006dBdc6fF1Bebd10769", - "DeliveryHelperImpl": "0x40f7fdE05bFa9F7c9B55a582B0783352856BCd03", - "ERC1967Factory": "0xF362fdCAbbd1f58AAd998d4c7Aef4020365092C8", - "FeesManager": "0x9745623Aaa299500F93d2B1B4Efb7b3EC5e60FFc", - "FeesManagerImpl": "0x71956F006Ec5434581D3Fd5E7224BB3bae231907", - "startBlock": 2368668, - "WatcherPrecompile": "0xEbdA834fAc9ca4B86AdD442083c1650f8497EdCb", - "WatcherPrecompileConfig": "0x4D38091442c78B4cb2bB22AFF61552bc72d4BF8e", - "WatcherPrecompileConfigImpl": "0xDf9d7b339Db52Fc58f2c72ffAd3a87201FB16b30", - "WatcherPrecompileImpl": "0xbAeF84edEae864Ff22Bd9c9912AdfF84aD490d82", - "WatcherPrecompileLimits": "0x0CF9B01E7d1ef769D160F53289244f74197B4149", - "WatcherPrecompileLimitsImpl": "0x0bA474851A0703eC69964FB8264304AF357cd16D" + "AddressResolver": "0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e", + "AddressResolverImpl": "0x794b92C2Ade7D33Fb34d138B13014C63aB27CBC0", + "AuctionManager": "0x87E15a6f9Cbe482f67683Ec3f7294f12d221C8bA", + "AuctionManagerImpl": "0xfddb38811a0774E66ABD5F3Ae960bFB7E7415029", + "DeliveryHelper": "0xb399b60C22A32512a24F01C4401f43BfF979A49F", + "DeliveryHelperImpl": "0xa07e38cAB46eAA358C3653C63219f1009e8F7789", + "ERC1967Factory": "0x98ea7A5601f203DE56d86BDCA69fC3019377D6B1", + "FeesManager": "0x30e07016eB24570629Bc8765CA307394Af90B27C", + "FeesManagerImpl": "0x9F10A0c71178dbD4d049f2C04fD0e34966134b9e", + "startBlock": 5480301, + "WatcherPrecompile": "0x426509517074E0fBf15F8aAB2472711FB456C58C", + "WatcherPrecompileConfig": "0x49094ECAF26d8295BcBD73b0Ff17215348E7b253", + "WatcherPrecompileConfigImpl": "0xd69E17Ce715f49Cd2B16C64cf75201A56Ce0E90d", + "WatcherPrecompileImpl": "0xB423eE3bffc3604F96B59cF419C48AE05b8E9d0b", + "WatcherPrecompileLimits": "0x54B315eC6c7059b19164BC0e5335643d5bBAad4f", + "WatcherPrecompileLimitsImpl": "0x0e26C8CFCABC04c642696A625664553e2C183bbe" }, "84532": { - "ContractFactoryPlug": "0x5AF9cA0Ce2Bc991FcE955f8c993fb0A5464B289F", - "FastSwitchboard": "0x0594497C89ECF66bC67204EE89770C4e799De3f9", - "FeesPlug": "0x0EBC6E395503eF135b7a45FfC7d42C2A2bc56D54", - "Socket": "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693", - "SocketBatcher": "0xE4036898F51842E7DdFD36Dc8eAa7D4B207c5DEe", - "startBlock": 23664081 + "ContractFactoryPlug": "0x8e51D99Bf353Ebba50080D0452546fd2EBAd86A4", + "FastSwitchboard": "0x4C114115755c39dB81a06fBfEb4b08302Abe7beE", + "FeesPlug": "0x9161a99deD597fe519E03D319053CA1669118dDA", + "Socket": "0x36Ae239a92faee6aFF4df9749d592dA7c00717Be", + "SocketBatcher": "0x8fa361816874a11a66D02EC84b28E1A931B4035e", + "startBlock": 25218634, + "TestUSDC": "0xfD51918C0572512901fFA79F822c99A475d22BB4" }, "421614": { - "ContractFactoryPlug": "0x5F710Ac554DD22819F9411fa554265EEf827247d", - "FastSwitchboard": "0xBD0158415Eb99B5e1dBA1e4E534f916ba82380f9", - "FeesPlug": "0x9E263f6c7C199d9c147E30764A8cae1175184CB8", - "Socket": "0x22c1275677E600e2b049B69D929E2ccAAf4B880E", - "SocketBatcher": "0x92f85fe2CbB2D9ab577E4D167E629095497325b9", - "startBlock": 136470235 + "ContractFactoryPlug": "0x65C066BE05CB4622393fADc1Bf3dE8eEdEcB3817", + "FastSwitchboard": "0xF121f4B97F7C902eeD4b188B08052Da9A1FD5aBe", + "FeesPlug": "0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b", + "Socket": "0xDAB25fB82cc1b1611Fb9016FB50222dBFcD1BCf5", + "SocketBatcher": "0x4e7163Ce9F7F335138fB32827d6f99f174060897", + "startBlock": 148801970, + "TestUSDC": "0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3" }, "11155111": { - "ContractFactoryPlug": "0xd36C1Dcb65CB09b7fCFABf153D7cdd42312C782E", - "FastSwitchboard": "0x36AC527afA283c95EA7dD11c8E93225d9F139028", - "FeesPlug": "0xc4008CCB59413cC2745d33549e5BE16A2d1DD061", - "Socket": "0x899AE7770eFb9714aF717d03c0d577e41d78ed48", - "SocketBatcher": "0xE90649F3BA488D91c7e8E3025F639F435Fa85243", - "startBlock": 23664095 + "FastSwitchboard": "0x1eFD3AF2317B9E6E7492718878f69De747C9e7c3", + "FeesPlug": "0xfE555AD869ac24305471F0755976c556425E8D23", + "Socket": "0xae59BA0Bd0D92232B3B6304185448C9Fe5445f4d", + "SocketBatcher": "0xdaE4538FbbEf41B2Feb5c79DD2fFC9720AF13d7b", + "TestUSDC": "0xbcaDE56f86a819994d0F66b98e921C484bE6FE4e" }, "11155420": { - "ContractFactoryPlug": "0x6320Ff773a4E01Cb8EB849EA906F17Cf6c48Ff9c", - "FastSwitchboard": "0xd94741a4654953817faEe228739a6d10C0683839", - "FeesPlug": "0x89634ecFea933aFaD5d3D6557b13cb8D466313d2", - "Socket": "0x2420B85D7e126d1948a4602f0c78a685655292Bd", - "SocketBatcher": "0xBD6770182fB47DD77924aDf3F200246Ab851f9c2", - "startBlock": 25646940 + "ContractFactoryPlug": "0x469B536c5Df15948c8759FEEE5DB1c17790d4152", + "FastSwitchboard": "0xd8bCd4b4Bc4b0f5cb279B6FAdCEd733614f34F51", + "FeesPlug": "0x6734a30B8f2d210faefa5aeD4E11b674C59641F1", + "Socket": "0x11fbd3a7031b28607973fc44d4d24B26DEfac886", + "SocketBatcher": "0x2c2060f5586751676fC2Af96cc8bE9BF0c7A8770", + "startBlock": 27201458, + "TestUSDC": "0xa0E1738a9Fc0698789866e09d7A335d30128C5C5" } } diff --git a/deployments/stage_verification.json b/deployments/stage_verification.json index 61c8987d..88f93e4b 100644 --- a/deployments/stage_verification.json +++ b/deployments/stage_verification.json @@ -1,162 +1,56 @@ { "43": [ [ - "0x71956F006Ec5434581D3Fd5E7224BB3bae231907", - "FeesManager", - "contracts/protocol/payload-delivery/FeesManager.sol", - [] - ], - [ - "0xbAeF84edEae864Ff22Bd9c9912AdfF84aD490d82", - "WatcherPrecompile", - "contracts/protocol/watcherPrecompile/WatcherPrecompile.sol", - [] - ], - [ - "0x02Bd15aa48BAE9A92E23a3F30Be0c1bD253970Cf", - "WatcherPrecompile", - "contracts/protocol/watcherPrecompile/WatcherPrecompile.sol", - [] - ], - [ - "0xbe1b573aa1B6ddD1A7a27aE0Aa6A38FA5d26fc67", + "0xfddb38811a0774E66ABD5F3Ae960bFB7E7415029", "AuctionManager", "contracts/protocol/payload-delivery/AuctionManager.sol", [] ], [ - "0x40f7fdE05bFa9F7c9B55a582B0783352856BCd03", + "0xa07e38cAB46eAA358C3653C63219f1009e8F7789", "DeliveryHelper", "contracts/protocol/payload-delivery/app-gateway/DeliveryHelper.sol", [] ], [ - "0xd151bD217704F72f717C2111207e6Bb33B609f61", + "0x9F10A0c71178dbD4d049f2C04fD0e34966134b9e", "FeesManager", "contracts/protocol/payload-delivery/FeesManager.sol", [] ], [ - "0x2916aC09Be088427E1a25968DA332F1F1eFa62d2", + "0xB423eE3bffc3604F96B59cF419C48AE05b8E9d0b", "WatcherPrecompile", - "contracts/protocol/watcherPrecompile/WatcherPrecompile.sol", + "contracts/protocol/watcherPrecompile/core/WatcherPrecompile.sol", [] ], [ - "0xDf9d7b339Db52Fc58f2c72ffAd3a87201FB16b30", + "0xd69E17Ce715f49Cd2B16C64cf75201A56Ce0E90d", "WatcherPrecompileConfig", "contracts/protocol/watcherPrecompile/WatcherPrecompileConfig.sol", [] ], [ - "0x0bA474851A0703eC69964FB8264304AF357cd16D", + "0x0e26C8CFCABC04c642696A625664553e2C183bbe", "WatcherPrecompileLimits", "contracts/protocol/watcherPrecompile/WatcherPrecompileLimits.sol", [] ], [ - "0x0F13F50f7dED1da9A4845366C2AB5120a1A17549", + "0x794b92C2Ade7D33Fb34d138B13014C63aB27CBC0", "AddressResolver", "contracts/protocol/AddressResolver.sol", [] ], [ - "0xF362fdCAbbd1f58AAd998d4c7Aef4020365092C8", + "0x98ea7A5601f203DE56d86BDCA69fC3019377D6B1", "ERC1967Factory", "lib/solady/src/utils/ERC1967Factory.sol", [] ] ], - "84532": [ - [ - "0x5AF9cA0Ce2Bc991FcE955f8c993fb0A5464B289F", - "ContractFactoryPlug", - "contracts/protocol/payload-delivery/ContractFactoryPlug.sol", - [ - "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0x0EBC6E395503eF135b7a45FfC7d42C2A2bc56D54", - "FeesPlug", - "contracts/protocol/payload-delivery/FeesPlug.sol", - [ - "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0x0594497C89ECF66bC67204EE89770C4e799De3f9", - "FastSwitchboard", - "contracts/protocol/socket/switchboard/FastSwitchboard.sol", - [ - 84532, - "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0xE4036898F51842E7DdFD36Dc8eAa7D4B207c5DEe", - "SocketBatcher", - "contracts/protocol/socket/SocketBatcher.sol", - [ - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", - "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693" - ] - ], - [ - "0x92562Ae6526aB8B4fFF9Fa8ECAb6db67f0753693", - "Socket", - "contracts/protocol/socket/Socket.sol", - [84532, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"] - ] - ], + "84532": [], "421614": [], - "11155111": [ - [ - "0xd36C1Dcb65CB09b7fCFABf153D7cdd42312C782E", - "ContractFactoryPlug", - "contracts/protocol/payload-delivery/ContractFactoryPlug.sol", - [ - "0x899AE7770eFb9714aF717d03c0d577e41d78ed48", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0xc4008CCB59413cC2745d33549e5BE16A2d1DD061", - "FeesPlug", - "contracts/protocol/payload-delivery/FeesPlug.sol", - [ - "0x899AE7770eFb9714aF717d03c0d577e41d78ed48", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0x36AC527afA283c95EA7dD11c8E93225d9F139028", - "FastSwitchboard", - "contracts/protocol/socket/switchboard/FastSwitchboard.sol", - [ - 11155111, - "0x899AE7770eFb9714aF717d03c0d577e41d78ed48", - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18" - ] - ], - [ - "0xE90649F3BA488D91c7e8E3025F639F435Fa85243", - "SocketBatcher", - "contracts/protocol/socket/SocketBatcher.sol", - [ - "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", - "0x899AE7770eFb9714aF717d03c0d577e41d78ed48" - ] - ], - [ - "0x899AE7770eFb9714aF717d03c0d577e41d78ed48", - "Socket", - "contracts/protocol/socket/Socket.sol", - [11155111, "0x3339Cf48f1F9cf31b6F8c2664d144c7444eBBB18", "EVMX"] - ] - ], + "11155111": [], "11155420": [] } diff --git a/hardhat-scripts/config/config.ts b/hardhat-scripts/config/config.ts index cdd6ad33..e0964075 100644 --- a/hardhat-scripts/config/config.ts +++ b/hardhat-scripts/config/config.ts @@ -23,12 +23,31 @@ export const logConfig = () => { ); }; -export const chains: Array = [ - ChainSlug.ARBITRUM_SEPOLIA, - ChainSlug.OPTIMISM_SEPOLIA, - // ChainSlug.BASE_SEPOLIA, - // ChainSlug.SEPOLIA, -]; +export const getChains = () => { + switch (mode) { + case DeploymentMode.LOCAL: + return [ChainSlug.ARBITRUM_SEPOLIA, ChainSlug.OPTIMISM_SEPOLIA]; + case DeploymentMode.DEV: + return [ChainSlug.ARBITRUM_SEPOLIA, ChainSlug.OPTIMISM_SEPOLIA]; + case DeploymentMode.STAGE: + return [ + ChainSlug.OPTIMISM_SEPOLIA, + ChainSlug.ARBITRUM_SEPOLIA, + ChainSlug.BASE_SEPOLIA, + ]; + case DeploymentMode.PROD: + return [ + ChainSlug.OPTIMISM_SEPOLIA, + ChainSlug.ARBITRUM_SEPOLIA, + ChainSlug.BASE_SEPOLIA, + ChainSlug.SEPOLIA, + ]; + default: + throw new Error(`Invalid deployment mode: ${mode}`); + } +}; + +export const chains: Array = getChains(); export const EVM_CHAIN_ID_MAP: Record = { [DeploymentMode.LOCAL]: 7625382, [DeploymentMode.DEV]: 7625382, @@ -48,7 +67,7 @@ export const auctionEndDelaySeconds = 0; export const BID_TIMEOUT = 600; // 10 minutes export const EXPIRY_TIME = 300; // 5 minutes export const MAX_RE_AUCTION_COUNT = 5; - +export const AUCTION_MANAGER_FUNDING_AMOUNT = ethers.utils.parseEther("100"); // TestUSDC export const TEST_USDC_NAME = "testUSDC"; export const TEST_USDC_SYMBOL = "testUSDC"; diff --git a/hardhat-scripts/constants/roles.ts b/hardhat-scripts/constants/roles.ts index 99ff3d91..ec875446 100644 --- a/hardhat-scripts/constants/roles.ts +++ b/hardhat-scripts/constants/roles.ts @@ -4,4 +4,5 @@ export enum ROLES { GOVERNANCE_ROLE = "GOVERNANCE_ROLE", WATCHER_ROLE = "WATCHER_ROLE", TRANSMITTER_ROLE = "TRANSMITTER_ROLE", + SWITCHBOARD_DISABLER_ROLE = "SWITCHBOARD_DISABLER_ROLE", } diff --git a/hardhat-scripts/deploy/1.deploy.ts b/hardhat-scripts/deploy/1.deploy.ts index 3063c4e8..fdb51e5a 100644 --- a/hardhat-scripts/deploy/1.deploy.ts +++ b/hardhat-scripts/deploy/1.deploy.ts @@ -6,6 +6,7 @@ import { ethers } from "hardhat"; import { CORE_CONTRACTS, DeploymentAddresses, + ETH_ADDRESS, EVMxCoreContracts, FAST_SWITCHBOARD_TYPE, IMPLEMENTATION_SLOT, @@ -36,6 +37,7 @@ import { FINALIZE_FEES, TIMEOUT_FEES, CALLBACK_FEES, + AUCTION_MANAGER_FUNDING_AMOUNT, } from "../config/config"; config(); @@ -262,6 +264,16 @@ const deployEVMxContracts = async () => { CALLBACK_FEES, deployUtils.signer ); + + const feesManager = await getInstance( + EVMxCoreContracts.FeesManager, + deployUtils.addresses[EVMxCoreContracts.FeesManager] + ); + await fundAuctionManager( + feesManager.connect(deployUtils.signer), + deployUtils.addresses[EVMxCoreContracts.AuctionManager], + deployUtils.signer + ); deployUtils.addresses.startBlock = (deployUtils.addresses.startBlock ? deployUtils.addresses.startBlock @@ -277,6 +289,56 @@ const deployEVMxContracts = async () => { } }; +export const fundAuctionManager = async ( + feesManager: Contract, + auctionManagerAddress: string, + watcherSigner: Signer +) => { + const currentCredits = await feesManager.getAvailableCredits( + auctionManagerAddress + ); + console.log("Current credits:", currentCredits.toString()); + if (currentCredits.gte(BigNumber.from(AUCTION_MANAGER_FUNDING_AMOUNT))) { + console.log( + `Auction manager ${auctionManagerAddress} already has credits, skipping funding` + ); + return; + } + const signatureNonce = Date.now(); + const digest = ethers.utils.keccak256( + ethers.utils.defaultAbiCoder.encode( + ["address", "uint32", "address", "uint256", "address", "uint32"], + [ + auctionManagerAddress, + EVMX_CHAIN_ID, + ETH_ADDRESS, + AUCTION_MANAGER_FUNDING_AMOUNT, + feesManager.address, + EVMX_CHAIN_ID, + ] + ) + ); + const signature = await watcherSigner.signMessage( + ethers.utils.arrayify(digest) + ); + const tx = await feesManager + .connect(watcherSigner) + .depositCredits( + auctionManagerAddress, + EVMX_CHAIN_ID, + ETH_ADDRESS, + signatureNonce, + signature, + { + value: AUCTION_MANAGER_FUNDING_AMOUNT, + } + ); + console.log( + `Funding auction manager ${auctionManagerAddress} with ${AUCTION_MANAGER_FUNDING_AMOUNT} ETH, txHash: `, + tx.hash + ); + await tx.wait(); +}; const deploySocketContracts = async () => { try { let addresses: DeploymentAddresses; diff --git a/hardhat-scripts/deploy/2.roles.ts b/hardhat-scripts/deploy/2.roles.ts index ae578b73..8ef83acc 100644 --- a/hardhat-scripts/deploy/2.roles.ts +++ b/hardhat-scripts/deploy/2.roles.ts @@ -20,7 +20,11 @@ import { ROLES } from "../constants/roles"; import { getWatcherSigner, getSocketSigner } from "../utils/sign"; export const REQUIRED_ROLES = { FastSwitchboard: [ROLES.WATCHER_ROLE, ROLES.RESCUE_ROLE], - Socket: [ROLES.GOVERNANCE_ROLE, ROLES.RESCUE_ROLE], + Socket: [ + ROLES.GOVERNANCE_ROLE, + ROLES.RESCUE_ROLE, + ROLES.SWITCHBOARD_DISABLER_ROLE, + ], FeesPlug: [ROLES.RESCUE_ROLE], ContractFactoryPlug: [ROLES.RESCUE_ROLE], }; diff --git a/script/admin/RescueFunds.s.sol b/script/admin/RescueFunds.s.sol new file mode 100644 index 00000000..dbd5a3dd --- /dev/null +++ b/script/admin/RescueFunds.s.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.19; + +import {Script} from "forge-std/Script.sol"; +import {console} from "forge-std/console.sol"; +import {FeesPlug} from "../../contracts/protocol/payload-delivery/FeesPlug.sol"; + +contract RescueFundsScript is Script { + address constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + + struct ChainConfig { + address feesPlug; + string rpc; + string name; + } + + function rescueFromChain( + ChainConfig memory config, + address sender, + uint256 deployerKey + ) internal { + uint256 fork = vm.createFork(config.rpc); + vm.selectFork(fork); + uint256 balance = address(config.feesPlug).balance; + + if (balance > 0) { + console.log("%s Fees Plug Balance:", config.name); + console.log(balance); + + vm.startBroadcast(deployerKey); + FeesPlug(config.feesPlug).rescueFunds(NATIVE_TOKEN, sender, balance); + vm.stopBroadcast(); + } + } + + function run() external { + uint256 deployerPrivateKey = vm.envUint("SPONSOR_KEY"); + address sender = vm.envAddress("SENDER_ADDRESS"); + + ChainConfig[] memory chains = new ChainConfig[](4); + + chains[0] = ChainConfig({ + feesPlug: vm.envAddress("ARBITRUM_FEES_PLUG"), + rpc: vm.envString("ARBITRUM_SEPOLIA_RPC"), + name: "Arbitrum" + }); + + chains[1] = ChainConfig({ + feesPlug: vm.envAddress("BASE_FEES_PLUG"), + rpc: vm.envString("BASE_SEPOLIA_RPC"), + name: "Base" + }); + + chains[2] = ChainConfig({ + feesPlug: vm.envAddress("OPTIMISM_FEES_PLUG"), + rpc: vm.envString("OPTIMISM_SEPOLIA_RPC"), + name: "Optimism" + }); + + chains[3] = ChainConfig({ + feesPlug: vm.envAddress("SEPOLIA_FEES_PLUG"), + rpc: vm.envString("SEPOLIA_RPC"), + name: "Sepolia" + }); + + for (uint i = 0; i < chains.length; i++) { + rescueFromChain(chains[i], sender, deployerPrivateKey); + } + } +} diff --git a/script/helpers/PayFeesInArbitrumTestUSDC.s.sol b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol index 5b280f39..c7fe8111 100644 --- a/script/helpers/PayFeesInArbitrumTestUSDC.s.sol +++ b/script/helpers/PayFeesInArbitrumTestUSDC.s.sol @@ -9,7 +9,7 @@ import {TestUSDC} from "../../contracts/helpers/TestUSDC.sol"; // source .env && forge script script/helpers/PayFeesInArbitrumETH.s.sol --broadcast --skip-simulation contract DepositFees is Script { function run() external { - uint256 amount = 100000000; + uint256 feesAmount = 100000000; vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); uint256 privateKey = vm.envUint("SPONSOR_KEY"); @@ -19,9 +19,9 @@ contract DepositFees is Script { TestUSDC testUSDCContract = TestUSDC(vm.envAddress("ARBITRUM_TEST_USDC")); // mint test USDC to sender - testUSDCContract.mint(vm.addr(privateKey), amount); + testUSDCContract.mint(vm.addr(privateKey), feesAmount); // approve fees plug to spend test USDC - testUSDCContract.approve(address(feesPlug), amount); + testUSDCContract.approve(address(feesPlug), feesAmount); address sender = vm.addr(privateKey); console.log("Sender address:", sender); @@ -29,7 +29,7 @@ contract DepositFees is Script { console.log("Sender balance in wei:", balance); console.log("App Gateway:", appGateway); console.log("Fees Plug:", address(feesPlug)); - uint feesAmount = 0.001 ether; + console.log("Fees Amount:", feesAmount); feesPlug.depositToFeeAndNative(address(testUSDCContract), appGateway, feesAmount); } } diff --git a/setupInfraContracts.sh b/setupInfraContracts.sh index dee0dde8..9d916681 100644 --- a/setupInfraContracts.sh +++ b/setupInfraContracts.sh @@ -12,3 +12,4 @@ time npx hardhat run hardhat-scripts/misc-scripts/errorCodes.ts --no-compile time npx hardhat run hardhat-scripts/misc-scripts/eventTopics.ts --no-compile time npx hardhat run hardhat-scripts/misc-scripts/functionSigs.ts --no-compile time npx hardhat run hardhat-scripts/verify/verify.ts --no-compile +yarn lint \ No newline at end of file