diff --git a/EventTopics.md b/EventTopics.md index be6695ea..c94cd569 100644 --- a/EventTopics.md +++ b/EventTopics.md @@ -214,8 +214,6 @@ | Event | Arguments | Topic | | ---------------------------- | ---------------------------------------- | -------------------------------------------------------------------- | -| `AppGatewayCallFailed` | `(triggerId: bytes32)` | `0xcaf8475fdade8465ea31672463949e6cf1797fdcdd11eeddbbaf857e1e5907b7` | -| `CalledAppGateway` | `(triggerId: bytes32)` | `0xf659ffb3875368f54fb4ab8f5412ac4518af79701a48076f7a58d4448e4bdd0b` | | `Initialized` | `(version: uint64)` | `0xc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2` | | `OwnershipHandoverCanceled` | `(pendingOwner: address)` | `0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92` | | `OwnershipHandoverRequested` | `(pendingOwner: address)` | `0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d` | diff --git a/contracts/evmx/interfaces/IWatcher.sol b/contracts/evmx/interfaces/IWatcher.sol index 9aea4486..d601d8d7 100644 --- a/contracts/evmx/interfaces/IWatcher.sol +++ b/contracts/evmx/interfaces/IWatcher.sol @@ -11,13 +11,6 @@ import "./IPromiseResolver.sol"; /// @notice Interface for the Watcher Precompile system that handles payload verification and execution /// @dev Defines core functionality for payload processing and promise resolution interface IWatcher { - /// @notice Emitted when a new call is made to an app gateway - /// @param triggerId The unique identifier for the trigger - event CalledAppGateway(bytes32 triggerId); - - /// @notice Emitted when a call to an app gateway fails - /// @param triggerId The unique identifier for the trigger - event AppGatewayCallFailed(bytes32 triggerId); function requestHandler__() external view returns (IRequestHandler); diff --git a/foundry.toml b/foundry.toml index 6c926318..6d1a2709 100644 --- a/foundry.toml +++ b/foundry.toml @@ -8,3 +8,29 @@ optimizer = true optimizer_runs = 200 evm_version = 'paris' via_ir = false + +[labels] +0x67790E222c41b0E787C278e757b7c40f03Fa5709 = "AddressResolver" +0x89C928379fED43B7117b852931e2968ce39C8380 = "AddressResolverImpl" +0x1C70bc3043667e884222B8835E0Ae554eb512810 = "AsyncDeployer" +0x09a762309c63a4e19cd3d822aA340Fe964Ba9C92 = "AsyncDeployerImpl" +0xC12aDF88dfc116CAF88816d150FE498843dABEEe = "AuctionManager" +0x55b76897b3BF6ED04188cbaa7DC21ae14b35D3eE = "AuctionManagerImpl" +0x377431bD1A3321C401542C8B1EC6E0c23E125042 = "Configurations" +0xDe5DedAe6e17f906D1269D5e84BEfB06F3926310 = "ConfigurationsImpl" +0xd48218b2DafF9063177b0c6Bae229ec6C5f086a9 = "DeployForwarder" +0x8e178161BB3B36a28C15DFBe3142afF8757B8993 = "DeployForwarderImpl" +0x870fCA8803bEFd119B1317AFB6794F97af7e515e = "ERC1967Factory" +0x761A9024D267006061ec943d02e3949678906f3E = "FeesManager" +0x29C583B64FD2d7b70f8F6253C2a28D60af364Cb5 = "FeesManagerImpl" +0x9De353dD1131aB4e502590D3a1832652FA316268 = "FeesPool" +0x73b1B3dF6C71e0aa912f9d6933920D4461ae9718 = "PromiseResolver" +0x58f49313816c1876417EE53De8F5de047359fB2C = "ReadPrecompile" +0x63a6D7096b5a2F5c9Ce7D8632A7A2034A85b7F01 = "RequestHandler" +0x593f4844ceEA828bC6d9D78A0ef7Ce64F42190dC = "RequestHandlerImpl" +0xF77d2059a66026Efac11334D30372429553CAaC3 = "SchedulePrecompile" +0xe4D1B4B8c0eEE90ac1f5314e758446CBa201BBA8 = "Watcher" +0x7726e559A5129A9174f89F7E2029f7212B66dD13 = "WatcherImpl" +0xd8be408E271EEe9d3D0f28305bB9b6003589E1A9 = "WritePrecompile" +0xE24c4b0f67f566Fa558b3FE85f1780CD330f1F4D = "WritePrecompileImpl" +0x4Faa9C39f4E1C5be5f9c2e3F5AC8774da3b7B1C2 = "APP_GATEWAY" diff --git a/hardhat-scripts/constants/feeConstants.ts b/hardhat-scripts/constants/feeConstants.ts index 0c610e3e..78710f38 100644 --- a/hardhat-scripts/constants/feeConstants.ts +++ b/hardhat-scripts/constants/feeConstants.ts @@ -2,6 +2,10 @@ import { DeploymentMode } from "../../src"; import { TokenMap } from "./types"; const tokens: TokenMap = { + [DeploymentMode.LOCAL]: { + 421614: ["0x5e732b6f5DC56dDAe4dBDbf844348F87C3B0b957"], + 11155420: ["0xb669f76f781dC75E06183DcdB7fd8bcD8Ef700E6"], + }, [DeploymentMode.DEV]: { 421614: ["0x2321BF7AdFaf49b1338F1Cd474859dBc0D8dfA96"], 11155420: ["0x15dbE4B96306Cc9Eba15D834d6c1a895cF4e1697"], @@ -14,6 +18,7 @@ const tokens: TokenMap = { }; const feePools: { [key: string]: string } = { + [DeploymentMode.LOCAL]: "0x9De353dD1131aB4e502590D3a1832652FA316268", [DeploymentMode.DEV]: "0xc20Be67ef742202dc93A78aa741E7C3715eA1DFd", [DeploymentMode.STAGE]: "0xe2054B575664dfDBD7a7FbAf2B12420ae88DE0FF", }; diff --git a/hardhat-scripts/deploy/1.deploy.ts b/hardhat-scripts/deploy/1.deploy.ts index 60581ec7..f5e19534 100644 --- a/hardhat-scripts/deploy/1.deploy.ts +++ b/hardhat-scripts/deploy/1.deploy.ts @@ -106,7 +106,7 @@ const deployEVMxContracts = async () => { deployUtils.addresses[contractName] = proxyFactory.address; const feePool = getFeePool(mode); - if (feePool.length == 0) { + if (feePool?.length == 0) { const feesPool = await getOrDeploy( Contracts.FeesPool, Contracts.FeesPool, diff --git a/hardhat-scripts/deploy/7.upload.ts b/hardhat-scripts/deploy/7.upload.ts index 4eaccb8f..f5f83811 100644 --- a/hardhat-scripts/deploy/7.upload.ts +++ b/hardhat-scripts/deploy/7.upload.ts @@ -24,7 +24,7 @@ const getBucketName = () => { const getFileName = () => { switch (mode) { case DeploymentMode.LOCAL: - return "pocConfig.json"; + return process.env.CONFIG_FILE_NAME || "pocConfig.json"; case DeploymentMode.DEV: return "devConfig.json"; case DeploymentMode.STAGE: diff --git a/hardhat-scripts/deploy/8.setupEnv.ts b/hardhat-scripts/deploy/8.setupEnv.ts index d8bc7ead..89551488 100644 --- a/hardhat-scripts/deploy/8.setupEnv.ts +++ b/hardhat-scripts/deploy/8.setupEnv.ts @@ -1,8 +1,13 @@ -import { ChainSlug, Contracts } from "../../src"; +import { + ChainAddressesObj, + ChainSlug, + Contracts, + EVMxAddressesObj, +} from "../../src"; import fs from "fs"; import path from "path"; import { EVMX_CHAIN_ID, mode } from "../config/config"; -import { getAddresses } from "../utils"; +import { getAddresses } from "../utils/address"; import { getFeeTokens } from "../constants"; const envFilePath = path.join(__dirname, "../../.env"); @@ -16,8 +21,10 @@ const lines = envContent.split("\n"); // Get the latest addresses const latestAddresses = getAddresses(mode); -const latestEVMxAddresses = latestAddresses[EVMX_CHAIN_ID]; - +const latestEVMxAddresses = latestAddresses[EVMX_CHAIN_ID] as EVMxAddressesObj; +const arbSepoliaAddresses = latestAddresses[ + ChainSlug.ARBITRUM_SEPOLIA +] as ChainAddressesObj; // Create a new array to hold the updated lines const updatedLines = lines.map((line) => { if (line.startsWith("ADDRESS_RESOLVER=")) { @@ -29,23 +36,23 @@ const updatedLines = lines.map((line) => { } else if (line.startsWith("FEES_MANAGER=")) { return `FEES_MANAGER=${latestEVMxAddresses[Contracts.FeesManager]}`; } else if (line.startsWith("ARBITRUM_SOCKET=")) { - return `ARBITRUM_SOCKET=${ - latestAddresses[ChainSlug.ARBITRUM_SEPOLIA][Contracts.Socket] - }`; + return `ARBITRUM_SOCKET=${arbSepoliaAddresses[Contracts.Socket]}`; } else if (line.startsWith("ARBITRUM_SWITCHBOARD=")) { return `ARBITRUM_SWITCHBOARD=${ - latestAddresses[ChainSlug.ARBITRUM_SEPOLIA][Contracts.FastSwitchboard] + arbSepoliaAddresses[Contracts.FastSwitchboard] }`; } else if (line.startsWith("ARBITRUM_FEES_PLUG=")) { - const feesPlug = - latestAddresses[ChainSlug.ARBITRUM_SEPOLIA][Contracts.FeesPlug]; + const feesPlug = arbSepoliaAddresses[Contracts.FeesPlug]; if (feesPlug) { return `ARBITRUM_FEES_PLUG=${feesPlug}`; } else { return line; } } else if (line.startsWith("ARBITRUM_TEST_USDC=")) { - const testUSDC = getFeeTokens(mode, ChainSlug.ARBITRUM_SEPOLIA)[0]; + const testUSDC = getFeeTokens( + mode, + ChainSlug.ARBITRUM_SEPOLIA + )[0] as string; if (testUSDC) { return `ARBITRUM_TEST_USDC=${testUSDC}`; } else { diff --git a/hardhat-scripts/misc-scripts/createLabels.ts b/hardhat-scripts/misc-scripts/createLabels.ts new file mode 100644 index 00000000..29097ee7 --- /dev/null +++ b/hardhat-scripts/misc-scripts/createLabels.ts @@ -0,0 +1,64 @@ +// scripts/generate-labels.ts +import fs from "fs"; +import path from "path"; +import { getAddresses } from "../utils/address"; +import { EVMX_CHAIN_ID, mode } from "../config"; + +function generateFoundryLabels(chainSlug?: string) { + // Read deployed addresses + const deployedAddresses = getAddresses(mode); + + // Read existing foundry.toml + const foundryPath = path.join(__dirname, "../../foundry.toml"); + let foundryContent = fs.existsSync(foundryPath) + ? fs.readFileSync(foundryPath, "utf8") + : ""; + + // Remove existing [labels] section + foundryContent = foundryContent.replace(/\[labels\][\s\S]*?(?=\[|$)/g, ""); + + // Generate new labels section + let labelsSection = "[labels]\n"; + const chainIds = [EVMX_CHAIN_ID]; + if (chainSlug) { + const additionalChainId = parseInt(chainSlug, 10); + if (isNaN(additionalChainId)) { + console.error(`❌ Invalid chain ID: ${chainSlug}`); + process.exit(1); + } + if (additionalChainId !== EVMX_CHAIN_ID) chainIds.push(additionalChainId); + } + + for (const chainId of chainIds) { + const chainAddresses = deployedAddresses[chainId]; + + if (!chainAddresses) { + console.error(`❌ No addresses found for chain ${chainId}`); + continue; + } + + // Add all addresses to the labels section + for (const [contractName, address] of Object.entries(chainAddresses)) { + if (typeof address === "string") { + labelsSection += `${address} = "${contractName}"\n`; + } + } + console.log(`✅ Added labels for chain ${chainId}`); + } + + // Add APP_GATEWAY label if environment variable exists + if (process.env.APP_GATEWAY) { + labelsSection += `${process.env.APP_GATEWAY} = "APP_GATEWAY"\n`; + } + + // Append labels section + foundryContent += labelsSection; + + // Write back to foundry.toml + fs.writeFileSync(foundryPath, foundryContent); + console.log("✅ Updated foundry.toml with contract labels"); +} + +// Get chainSlug from command line arguments +const chainSlug = process.argv[2]; +generateFoundryLabels(chainSlug); diff --git a/hardhat-scripts/utils/accounts.ts b/hardhat-scripts/utils/accounts.ts deleted file mode 100644 index b1f579d6..00000000 --- a/hardhat-scripts/utils/accounts.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { HardhatRuntimeEnvironment } from "hardhat/types/runtime"; - -export default async function accounts( - params: any, - hre: HardhatRuntimeEnvironment -): Promise { - const [account] = await hre.ethers.getSigners(); - - console.log( - `Balance for 1st account ${await account.getAddress()}: ${await account.getBalance()}` - ); -} diff --git a/hardhat-scripts/utils/address.ts b/hardhat-scripts/utils/address.ts index f1476c41..4ac48774 100644 --- a/hardhat-scripts/utils/address.ts +++ b/hardhat-scripts/utils/address.ts @@ -1,7 +1,8 @@ import dev_addresses from "../../deployments/dev_addresses.json"; import stage_addresses from "../../deployments/stage_addresses.json"; import local_addresses from "../../deployments/local_addresses.json"; -import { ChainAddressesObj, DeploymentMode, EVMxAddressesObj } from "../../src"; +import { ChainAddressesObj, EVMxAddressesObj } from "../../src/types"; +import { DeploymentMode } from "../../src/enums"; export const getAddresses = ( mode: DeploymentMode diff --git a/hardhat-scripts/utils/index.ts b/hardhat-scripts/utils/index.ts index e0b53879..f046cdd2 100644 --- a/hardhat-scripts/utils/index.ts +++ b/hardhat-scripts/utils/index.ts @@ -2,7 +2,6 @@ export * from "./address"; export * from "./appConfig"; export * from "./networks"; export * from "./overrides"; -export * from "./accounts"; export * from "./deployUtils"; export * from "./sign"; export * from "./gatewayId"; diff --git a/hardhat.config.ts b/hardhat.config.ts index 74627321..f9745fe6 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -16,7 +16,6 @@ import type { import { resolve } from "path"; import fs from "fs"; -import "./hardhat-scripts/utils/accounts"; import { getJsonRpcUrl } from "./hardhat-scripts/utils/networks"; import { ChainId, diff --git a/package.json b/package.json index a30b0517..b61572d5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "publishConfig": { "access": "public" }, - "version": "1.1.21", + "version": "1.1.22", "description": "socket protocol", "scripts": { "build": "yarn abi && tsc --project lib.tsconfig.json", @@ -19,7 +19,8 @@ "lintContracts": "prettier \"./**\" --write --plugin=prettier-plugin-solidity", "compile": "forge build", "deploy": "bash setupInfraContracts.sh", - "publish-core": "yarn build && yarn publish --patch --no-git-tag-version" + "publish-core": "yarn build && yarn publish --patch --no-git-tag-version", + "trace":"bash trace.sh" }, "pre-commit": [], "author": "", diff --git a/script/counter/DeployEVMxCounterApp.s.sol b/script/counter/DeployEVMxCounterApp.s.sol index 96111337..50a81c25 100644 --- a/script/counter/DeployEVMxCounterApp.s.sol +++ b/script/counter/DeployEVMxCounterApp.s.sol @@ -16,7 +16,7 @@ contract CounterDeploy is Script { vm.startBroadcast(deployerPrivateKey); // Setting fee payment on Arbitrum Sepolia - uint256 fees = 10 ether; + uint256 fees = 1 ether; CounterAppGateway gateway = new CounterAppGateway(addressResolver, fees); diff --git a/script/helpers/DepositCredit.s.sol b/script/helpers/DepositCredit.s.sol index 767d5aac..b8d432f8 100644 --- a/script/helpers/DepositCredit.s.sol +++ b/script/helpers/DepositCredit.s.sol @@ -9,7 +9,7 @@ import {TestUSDC} from "../../contracts/evmx/mocks/TestUSDC.sol"; // source .env && forge script script/helpers/DepositCreditAndNative.s.sol --broadcast --skip-simulation contract DepositCredit is Script { function run() external { - uint256 feesAmount = 100000000; // 100 USDC + uint256 feesAmount = 2000000; // 2 USDC vm.createSelectFork(vm.envString("ARBITRUM_SEPOLIA_RPC")); uint256 privateKey = vm.envUint("PRIVATE_KEY"); diff --git a/script/helpers/DepositCreditMainnet.s.sol b/script/helpers/DepositCreditMainnet.s.sol new file mode 100644 index 00000000..4e1a8e33 --- /dev/null +++ b/script/helpers/DepositCreditMainnet.s.sol @@ -0,0 +1,36 @@ +// 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/evmx/plugs/FeesPlug.sol"; +import {TestUSDC} from "../../contracts/evmx/mocks/TestUSDC.sol"; +import "solady/tokens/ERC20.sol"; +// source .env && forge script script/helpers/DepositCreditAndNative.s.sol --broadcast --skip-simulation +contract DepositCredit is Script { + function run() external { + uint256 feesAmount = 1000000; // 1 USDC + vm.createSelectFork(vm.envString("ARBITRUM_RPC")); + + uint256 privateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(privateKey); + FeesPlug feesPlug = FeesPlug(payable(vm.envAddress("ARBITRUM_FEES_PLUG"))); + address appGateway = vm.envAddress("APP_GATEWAY"); + ERC20 USDCContract = ERC20(vm.envAddress("ARBITRUM_USDC")); + + // approve fees plug to spend test USDC + USDCContract.approve(address(feesPlug), feesAmount); + + address sender = vm.addr(privateKey); + console.log("Sender address:", sender); + uint256 balance = USDCContract.balanceOf(sender); + console.log("Sender USDC balance:", balance); + if (balance < feesAmount) { + revert("Sender does not have enough USDC"); + } + console.log("App Gateway:", appGateway); + console.log("Fees Plug:", address(feesPlug)); + console.log("Fees Amount:", feesAmount); + feesPlug.depositCredit(address(USDCContract), appGateway, feesAmount); + } +} diff --git a/setupInfraContracts.sh b/setupInfraContracts.sh index 989eabaa..c08fed42 100644 --- a/setupInfraContracts.sh +++ b/setupInfraContracts.sh @@ -8,11 +8,12 @@ time npx hardhat run hardhat-scripts/deploy/3.configureChains.ts --no-compile time npx hardhat run hardhat-scripts/deploy/4.configureEVMx.ts --no-compile time npx hardhat run hardhat-scripts/deploy/5.fundTransfers.ts --no-compile time npx hardhat run hardhat-scripts/deploy/6.connect.ts --no-compile -time npx hardhat run hardhat-scripts/deploy/7.upload.ts --no-compile -time npx hardhat run hardhat-scripts/deploy/8.setupEnv.ts --no-compile +time npx ts-node hardhat-scripts/deploy/7.upload.ts +time npx ts-node hardhat-scripts/deploy/8.setupEnv.ts time npx hardhat run hardhat-scripts/deploy/9.setupTransmitter.ts --no-compile 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 ts-node hardhat-scripts/misc-scripts/createLabels.ts time npx hardhat run hardhat-scripts/verify/verify.ts --no-compile yarn lint \ No newline at end of file diff --git a/src/enums.ts b/src/enums.ts index cb7af5e4..f54d3ba8 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -16,8 +16,8 @@ export enum Events { FeesDeposited = "FeesDeposited", // Watcher - CalledAppGateway = "CalledAppGateway", - AppGatewayCallFailed = "AppGatewayCallFailed", + TriggerFailed = "TriggerFailed", + TriggerSucceeded = "TriggerSucceeded", // PromiseResolver PromiseResolved = "PromiseResolved", diff --git a/src/events.ts b/src/events.ts index c115e6bf..1d57f1aa 100644 --- a/src/events.ts +++ b/src/events.ts @@ -9,10 +9,7 @@ export const socketEvents = [ export const feesPlugEvents = [Events.FeesDeposited]; -export const watcherEvents = [ - Events.CalledAppGateway, - Events.AppGatewayCallFailed, -]; +export const watcherEvents = [Events.TriggerFailed, Events.TriggerSucceeded]; export const promiseResolverEvents = [ Events.PromiseResolved, diff --git a/trace.sh b/trace.sh new file mode 100644 index 00000000..3e185bc6 --- /dev/null +++ b/trace.sh @@ -0,0 +1,62 @@ +#!/bin/bash +source .env + +# Usage function +show_usage() { + echo "Usage: yarn trace " + echo "Example: yarn trace 42161 0x129f0f8dc131d59b88aa05d1bb136665480eb9e98ab11796f1f60fc7d4179b8d \$ARBITRUM_RPC" +} + +# Check if we have 3 arguments +if [ "$#" -ne 3 ]; then + echo "Error: 3 arguments required" + show_usage + exit 0 +fi + +# Validate required arguments +if [ -z "$1" ]; then + echo "Error: chainSlug argument is required" + show_usage + exit 0 +fi + +if [ -z "$2" ]; then + echo "Error: txHash argument is required" + show_usage + exit 0 +fi + +# Validate chainSlug is a number +if ! [[ "$1" =~ ^[0-9]+$ ]]; then + echo "Error: chainSlug must be a number" + show_usage + exit 0 +fi + +# Validate txHash format (0x followed by 64 hex chars) +if ! [[ "$2" =~ ^0x[a-fA-F0-9]{64}$ ]]; then + echo "Error: Invalid transaction hash format" + show_usage + exit 0 +fi + +# Validate RPC URL +RPC_URL=${3:-$ETH_RPC_URL} +if [ -z "$RPC_URL" ]; then + echo "Error: No RPC URL provided and ETH_RPC_URL not set in .env" + show_usage + exit 0 +fi + +echo "chainSlug: $1" +echo "txHash: $2" +echo "rpcUrl: $RPC_URL" + +npx ts-node hardhat-scripts/misc-scripts/createLabels.ts $1 +cast run --la $2 --rpc-url $RPC_URL + +# usage : +# yarn trace +# Example : +# yarn trace 42161 0x129f0f8dc131d59b88aa05d1bb136665480eb9e98ab11796f1f60fc7d4179b8d $ARBITRUM_RPC \ No newline at end of file