Skip to content

Commit

Permalink
generate config in human readable names
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Dec 23, 2024
1 parent 08ce2ec commit c321d0e
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions contracts/config/anvil_localnet/GroupMessages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"addresses": {
"groupMessagesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"groupMessagesImpl": "0x0a17FabeA4633ce714F1Fa4a2dcA62C3bAc4758d",
"groupMessagesProxy": "0x3C1Cb427D20F15563aDa8C249E71db76d7183B6c",
"groupMessagesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 65,
"latestUpgradeBlock": 71
}
10 changes: 10 additions & 0 deletions contracts/config/anvil_localnet/IdentityUpdates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"addresses": {
"identityUpdatesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"identityUpdatesImpl": "0x1343248Cbd4e291C6979e70a138f4c774e902561",
"identityUpdatesProxy": "0x22a9B82A6c3D2BFB68F324B2e8367f346Dd6f32a",
"identityUpdatesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 67,
"latestUpgradeBlock": 67
}
6 changes: 3 additions & 3 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 0 additions & 10 deletions contracts/script/output/31337/GroupMessages.json

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/script/output/31337/IdentityUpdates.json

This file was deleted.

26 changes: 22 additions & 4 deletions contracts/script/utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions dev/baked/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions dev/contracts/common
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;

Expand All @@ -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"
;;

Expand Down
2 changes: 1 addition & 1 deletion dev/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pkg/testutils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c321d0e

Please sign in to comment.