diff --git a/contracts/README.md b/contracts/README.md index 75271f03..6594d2ce 100644 --- a/contracts/README.md +++ b/contracts/README.md @@ -76,7 +76,7 @@ The project includes deployer and upgrade scripts. ### Messages contracts -- Configure the environment by providing an `.env` file, with this content: +- Configure the environment by creating an `.env` file, with this content: ```shell ### Main configuration diff --git a/contracts/config/anvil_localnet/GroupMessages.json b/contracts/config/anvil_localnet/GroupMessages.json new file mode 100644 index 00000000..7ade0abb --- /dev/null +++ b/contracts/config/anvil_localnet/GroupMessages.json @@ -0,0 +1,10 @@ +{ + "addresses": { + "groupMessagesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "groupMessagesImpl": "0x0a17FabeA4633ce714F1Fa4a2dcA62C3bAc4758d", + "groupMessagesProxy": "0x3C1Cb427D20F15563aDa8C249E71db76d7183B6c", + "groupMessagesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + }, + "deploymentBlock": 65, + "latestUpgradeBlock": 71 +} \ No newline at end of file diff --git a/contracts/config/anvil_localnet/IdentityUpdates.json b/contracts/config/anvil_localnet/IdentityUpdates.json new file mode 100644 index 00000000..bcdaf689 --- /dev/null +++ b/contracts/config/anvil_localnet/IdentityUpdates.json @@ -0,0 +1,10 @@ +{ + "addresses": { + "identityUpdatesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "identityUpdatesImpl": "0x1343248Cbd4e291C6979e70a138f4c774e902561", + "identityUpdatesProxy": "0x22a9B82A6c3D2BFB68F324B2e8367f346Dd6f32a", + "identityUpdatesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + }, + "deploymentBlock": 67, + "latestUpgradeBlock": 67 +} \ No newline at end of file diff --git a/contracts/foundry.toml b/contracts/foundry.toml index 773ba6cd..f0d83ec0 100644 --- a/contracts/foundry.toml +++ b/contracts/foundry.toml @@ -13,9 +13,9 @@ remappings = [ "forge-std/=dependencies/forge-std-1.9.4/", ] fs_permissions = [ - { access = "read-write", path = "script/output/31337"}, - { access = "read-write", path = "script/output/11155111"}, - { access = "read-write", path = "script/output/241320161"} + { access = "read-write", path = "config/anvil_localnet"}, + { access = "read-write", path = "config/xmtp_testnet"}, + { access = "read-write", path = "config/unknown"} ] [soldeer] diff --git a/contracts/script/output/31337/GroupMessages.json b/contracts/script/output/31337/GroupMessages.json deleted file mode 100644 index d20f6cc2..00000000 --- a/contracts/script/output/31337/GroupMessages.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "addresses": { - "groupMessagesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "groupMessagesImpl": "0xB0f05d25e41FbC2b52013099ED9616f1206Ae21B", - "groupMessagesProxy": "0x5FeaeBfB4439F3516c74939A9D04e95AFE82C4ae", - "groupMessagesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - }, - "deploymentBlock": 43, - "latestUpgradeBlock": 43 -} \ No newline at end of file diff --git a/contracts/script/output/31337/IdentityUpdates.json b/contracts/script/output/31337/IdentityUpdates.json deleted file mode 100644 index cd8f4b2a..00000000 --- a/contracts/script/output/31337/IdentityUpdates.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "addresses": { - "identityUpdatesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "identityUpdatesImpl": "0x976fcd02f7C4773dd89C309fBF55D5923B4c98a1", - "identityUpdatesProxy": "0x19cEcCd6942ad38562Ee10bAfd44776ceB67e923", - "identityUpdatesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" - }, - "deploymentBlock": 45, - "latestUpgradeBlock": 45 -} \ No newline at end of file diff --git a/contracts/script/utils/Utils.sol b/contracts/script/utils/Utils.sol index deac7579..12a48c8e 100644 --- a/contracts/script/utils/Utils.sol +++ b/contracts/script/utils/Utils.sol @@ -5,14 +5,21 @@ import "forge-std/src/Script.sol"; import "forge-std/src/StdJson.sol"; contract Utils is Script { + uint256 constant CHAIN_ID_ANVIL_LOCALNET = 31337; + uint256 constant CHAIN_ID_XMTP_TESTNET = 241320161; + + string constant OUTPUT_ANVIL_LOCALNET = "anvil_localnet"; + string constant OUTPUT_XMTP_TESTNET = "xmtp_testnet"; + string constant OUTPUT_UNKNOWN = "unknown"; + function readInput(string memory inputFileName) internal view returns (string memory) { string memory file = getInputPath(inputFileName); return vm.readFile(file); } function getInputPath(string memory inputFileName) internal view returns (string memory) { - string memory inputDir = string.concat(vm.projectRoot(), "/script/input/"); - string memory chainDir = string.concat(vm.toString(block.chainid), "/"); + string memory inputDir = string.concat(vm.projectRoot(), "/config/"); + string memory chainDir = string.concat(_resolveChainID(), "/"); string memory file = string.concat(inputFileName, ".json"); return string.concat(inputDir, chainDir, file); } @@ -28,9 +35,20 @@ contract Utils is Script { } function getOutputPath(string memory outputFileName) internal view returns (string memory) { - string memory outputDir = string.concat(vm.projectRoot(), "/script/output/"); - string memory chainDir = string.concat(vm.toString(block.chainid), "/"); + string memory outputDir = string.concat(vm.projectRoot(), "/config/"); + string memory chainDir = string.concat(_resolveChainID(), "/"); string memory outputFilePath = string.concat(outputDir, chainDir, outputFileName, ".json"); return outputFilePath; } + + function _resolveChainID() internal view returns (string memory) { + uint256 chainID = block.chainid; + if (chainID == CHAIN_ID_ANVIL_LOCALNET) { + return OUTPUT_ANVIL_LOCALNET; + } else if (chainID == CHAIN_ID_XMTP_TESTNET) { + return OUTPUT_XMTP_TESTNET; + } else { + return OUTPUT_UNKNOWN; + } + } } diff --git a/dev/baked/Dockerfile b/dev/baked/Dockerfile index 06e75b9a..dd09529c 100644 --- a/dev/baked/Dockerfile +++ b/dev/baked/Dockerfile @@ -29,8 +29,8 @@ RUN dev/docker/anvil-background && \ sleep 5 RUN echo "export XMTPD_CONTRACTS_NODES_ADDRESS="$(jq -r '.deployedTo' build/Nodes.json)"" >> contracts.env && \ - echo "export XMTPD_CONTRACTS_MESSAGES_ADDRESS="$(jq -r '.addresses.groupMessagesProxy' contracts/script/output/31337/GroupMessages.json)"" >> contracts.env && \ - echo "export XMTPD_CONTRACTS_IDENTITY_UPDATES_ADDRESS="$(jq -r '.addresses.identityUpdatesProxy' contracts/script/output/31337/IdentityUpdates.json)"" >> contracts.env + echo "export XMTPD_CONTRACTS_MESSAGES_ADDRESS="$(jq -r '.addresses.groupMessagesProxy' contracts/config/anvil_localnet/GroupMessages.json)"" >> contracts.env && \ + echo "export XMTPD_CONTRACTS_IDENTITY_UPDATES_ADDRESS="$(jq -r '.addresses.identityUpdatesProxy' contracts/config/anvil_localnet/IdentityUpdates.json)"" >> contracts.env # ACTUAL IMAGE ------------------------------------------------------- diff --git a/dev/contracts/common b/dev/contracts/common index a8035b21..4ab899ea 100644 --- a/dev/contracts/common +++ b/dev/contracts/common @@ -11,7 +11,7 @@ function forge_deploy_script() { fi echo -e "✅ GroupMessages contract deployed.\n" - cat script/output/31337/GroupMessages.json + cat config/anvil_localnet/GroupMessages.json echo -e "\n" ;; @@ -23,7 +23,7 @@ function forge_deploy_script() { fi echo -e "✅ IdentityUpdates contract deployed.\n" - cat script/output/31337/IdentityUpdates.json + cat config/anvil_localnet/IdentityUpdates.json echo -e "\n" ;; diff --git a/dev/local.env b/dev/local.env index b934bddc..f07ecaf4 100755 --- a/dev/local.env +++ b/dev/local.env @@ -3,7 +3,7 @@ source dev/contracts/.env # Anvil scripts output folder -ANVIL_SCRIPTS_OUTPUT=contracts/script/output/31337 +ANVIL_SCRIPTS_OUTPUT=contracts/config/anvil_localnet # DB Options export XMTPD_DB_WRITER_CONNECTION_STRING="postgres://postgres:xmtp@localhost:8765/postgres?sslmode=disable" diff --git a/pkg/testutils/config.go b/pkg/testutils/config.go index 42eccff8..af586c58 100644 --- a/pkg/testutils/config.go +++ b/pkg/testutils/config.go @@ -96,12 +96,12 @@ func GetContractsOptions(t *testing.T) config.ContractsOptions { RpcUrl: BLOCKCHAIN_RPC_URL, MessagesContractAddress: getProxyAddress( t, - path.Join(rootDir, "./contracts/script/output/31337/GroupMessages.json"), + path.Join(rootDir, "./contracts/config/anvil_localnet/GroupMessages.json"), ), NodesContractAddress: getDeployedTo(t, path.Join(rootDir, "./build/Nodes.json")), IdentityUpdatesContractAddress: getProxyAddress( t, - path.Join(rootDir, "./contracts/script/output/31337/IdentityUpdates.json"), + path.Join(rootDir, "./contracts/config/anvil_localnet/IdentityUpdates.json"), ), RefreshInterval: 100 * time.Millisecond, ChainID: 31337,