Skip to content

Commit

Permalink
chore: move contract logic to contracts folder
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Dec 23, 2024
1 parent c321d0e commit 96fe704
Show file tree
Hide file tree
Showing 37 changed files with 269 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: "nightly-ac81a53d1d5823919ffbadd3c65f081927aa11f2"
- run: dev/contracts/deploy-local
- run: contracts/dev/deploy-local
- name: Run Tests
run: |
export GOPATH="${HOME}/go/"
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
]
},
"solidity.compileUsingRemoteVersion": "v0.8.28",
"solidity.formatter": "forge"
"solidity.formatter": "forge",
"wake.compiler.solc.remappings": []
}
8 changes: 4 additions & 4 deletions contracts/config/anvil_localnet/GroupMessages.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"addresses": {
"groupMessagesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"groupMessagesImpl": "0x0a17FabeA4633ce714F1Fa4a2dcA62C3bAc4758d",
"groupMessagesProxy": "0x3C1Cb427D20F15563aDa8C249E71db76d7183B6c",
"groupMessagesImpl": "0x5f246ADDCF057E0f778CD422e20e413be70f9a0c",
"groupMessagesProxy": "0xaD82Ecf79e232B0391C5479C7f632aA1EA701Ed1",
"groupMessagesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 65,
"latestUpgradeBlock": 71
"deploymentBlock": 160,
"latestUpgradeBlock": 160
}
8 changes: 4 additions & 4 deletions contracts/config/anvil_localnet/IdentityUpdates.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"addresses": {
"identityUpdatesDeployer": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"identityUpdatesImpl": "0x1343248Cbd4e291C6979e70a138f4c774e902561",
"identityUpdatesProxy": "0x22a9B82A6c3D2BFB68F324B2e8367f346Dd6f32a",
"identityUpdatesImpl": "0x4Dd5336F3C0D70893A7a86c6aEBe9B953E87c891",
"identityUpdatesProxy": "0x91A1EeE63f300B8f41AE6AF67eDEa2e2ed8c3f79",
"identityUpdatesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 67,
"latestUpgradeBlock": 67
"deploymentBlock": 162,
"latestUpgradeBlock": 162
}
15 changes: 8 additions & 7 deletions dev/contracts/deploy-local → contracts/dev/deploy-local
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/bin/bash
# Deploy the smart contracts to the local anvil node
set -euo pipefail
source dev/contracts/.env
source dev/contracts/common

# Make sure the build directory exists
mkdir -p ./build

# Move to working directory
cd ./contracts
# Always work from the contracts directory
script_dir=$(dirname "$(realpath "$0")")
repo_root=$(realpath "${script_dir}/../")
cd "${repo_root}"

source dev/lib/env
source dev/lib/common

# Update depencencies
forge soldeer update &> /dev/null
Expand All @@ -19,6 +22,4 @@ fi

forge_deploy_script group_messages
forge_deploy_script identity_updates

# TODO: This should be a function in the forge CLI
deploy_contract src/Nodes.sol Nodes
forge_deploy_script nodes src/Nodes.sol Nodes
File renamed without changes.
70 changes: 70 additions & 0 deletions contracts/dev/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -euo pipefail

# Default directories (can be overridden with environment variables)
source_dir="${SOURCE_DIR:-src}"
build_dir="${BUILD_DIR:-build}"
output_dir="${OUTPUT_DIR:-pkg}"

# Ensure required directories exist and clean up old artifacts
function setup_directories() {
mkdir -p "${build_dir}" "${output_dir}"
}

# Generate bindings for a given contract
function generate_bindings() {
local filename="$1"
local package="$(echo "${filename}" | tr '[:upper:]' '[:lower:]')"
local source_artifact="${source_dir}/${filename}.sol"
local build_artifact="${build_dir}/${filename}"
local output_artifact="${output_dir}/${package}/${filename}.go"

rm -f "${build_artifact}".*.json
mkdir -p "${output_dir}/${package}"
rm -f "${output_dir}/${package}"/*.go

# Generate ABI and bytecode
if ! forge inspect "${source_artifact}:${filename}" abi > "${build_artifact}.abi.json"; then
echo "ERROR: Failed to generate ABI for ${filename}" >&2
exit 1
fi

if ! forge inspect "${source_artifact}:${filename}" bytecode > "${build_artifact}.bin.json"; then
echo "ERROR: Failed to generate bytecode for ${filename}" >&2
exit 1
fi

# Generate Go bindings
if ! abigen --abi "${build_artifact}.abi.json" \
--bin "${build_artifact}.bin.json" \
--pkg "${package}" \
--type "${filename}" \
--out "${output_artifact}" > /dev/null 2>&1; then
echo "ERROR: Failed to generate bindings for ${filename}" >&2
exit 1
fi
}

function main() {
# Always work from the contracts directory
script_dir=$(dirname "$(realpath "$0")")
repo_root=$(realpath "${script_dir}/../")
cd "${repo_root}"

setup_directories

# Define contracts (pass as arguments or use a default list)
local contracts=("$@")
if [ "${#contracts[@]}" -eq 0 ]; then
contracts=("Nodes" "GroupMessages" "IdentityUpdates")
fi

# Generate bindings for each contract
for contract in "${contracts[@]}"; do
echo "Processing contract: ${contract}"
generate_bindings "${contract}"
done
}

main "$@"
14 changes: 8 additions & 6 deletions dev/contracts/common → contracts/dev/lib/common
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ function forge_deploy_script() {
echo -e "\n"
;;

nodes)
# TODO: Migrate to forge script
forge create --broadcast --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$2:$3" > ../build/$3.json
echo -e "✅ Nodes contract deployed.\n"
cat ../build/$3.json
echo -e "\n"
;;

*)
echo "Invalid option. Use 'group_messages' or 'identity_updates'."
exit 1
;;
esac
}

# Deploy a contract and save the output (which includes the contract address) to a JSON file to be used in tests
# TODO: This should be a function in the forge CLI
function deploy_contract() {
forge create --broadcast --legacy --json --rpc-url $DOCKER_RPC_URL --private-key $PRIVATE_KEY "$1:$2" > ../build/$2.json
}
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/abis/nodes.go → contracts/pkg/nodes/Nodes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/slither.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"detectors_to_exclude": "",
"detectors_to_exclude": "unused-state,naming-convention,constable-states",
"filter_paths": "dependencies"
}
2 changes: 1 addition & 1 deletion dev/baked/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ COPY . .
# It seems that anvil flushes the file to disk on shutdown and it takes a few ms to be persisted
# That gives us the pkill+sleep requirement
RUN dev/docker/anvil-background && \
dev/contracts/deploy-local && \
contracts/dev/deploy-local && \
dev/register-local-node && \
dev/register-local-node-2 && \
pkill -f anvil && \
Expand Down
11 changes: 0 additions & 11 deletions dev/contracts/deploy-ephemeral

This file was deleted.

25 changes: 0 additions & 25 deletions dev/contracts/generate

This file was deleted.

2 changes: 1 addition & 1 deletion dev/generate
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set -euo pipefail
sqlc generate
go generate ./...
rm -rf pkg/mocks/*
./dev/contracts/generate
./contracts/dev/generate
mockery
2 changes: 1 addition & 1 deletion dev/local.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

source dev/contracts/.env
source contracts/dev/lib/env

# Anvil scripts output folder
ANVIL_SCRIPTS_OUTPUT=contracts/config/anvil_localnet
Expand Down
4 changes: 2 additions & 2 deletions dev/up
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fi
dev/docker/up

# Make sure the abis are updated
dev/contracts/generate
dev/contracts/deploy-local
contracts/dev/generate
contracts/dev/deploy-local

echo "Registering local node-1"
dev/register-local-node
Expand Down
52 changes: 27 additions & 25 deletions doc/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
## Deploy a new Contract

The current environment lives in [Conduit Testnet Staging](https://explorer-testnet-staging-88dqtxdinc.t.conduit.xyz/).
To deploy a new contract you need to run `./dev/contracts/deploy-testnet`
To deploy a new contract you need to run `./contracts/dev/deploy-testnet`
You will need:

- $PRIVATE_KEY which is accessible to all members of @ephemerahq/backend
- $VERIFIER_URL: https://explorer-testnet-staging-88dqtxdinc.t.conduit.xyz/api
- $RPC_URL: https://rpc-testnet-staging-88dqtxdinc.t.conduit.xyz/
Expand All @@ -18,6 +19,7 @@ We definitely need the node contract address (for example `0x7c9A7c92e21E9aC25Ce

Before nodes can start or peer, they need to be registered with the contract.
To do so, run:

```shell
export XMTPD_CONTRACTS_RPC_URL="https://rpc-testnet-staging-88dqtxdinc.t.conduit.xyz/"
export XMTPD_CONTRACTS_CHAIN_ID=34498
Expand All @@ -36,6 +38,7 @@ You need to register all (both) nodes with their correct DNS entries and public
### Verify Registration

To verify registration, use:

```shell
export XMTPD_CONTRACTS_RPC_URL="https://rpc-testnet-staging-88dqtxdinc.t.conduit.xyz/"
export XMTPD_CONTRACTS_CHAIN_ID=34498
Expand All @@ -47,29 +50,29 @@ dev/cli get-all-nodes \
```

And you should get something along these lines:

```json
{
"size": 2,
"nodes": [
{
"NodeId": 100,
"Node": {
"SigningKeyPub": "BOVELF0f4vAra5oaOGODp3ZoYLQKYHmgIjmU/6LOEFEsToqIY97q2FnD1lQKsgJsgvi4k8HFvvbGP0fZ3zOiB9s=",
"HttpAddress": "https://grpc.testnet.xmtp.network",
"IsHealthy": true
}
},
{
"NodeId": 200,
"Node": {
"SigningKeyPub": "BPwmHUOgFTU5pMZMKXY8sOfjd8DqwpEMPUvtsiNaxwNxz+fKU3SsqOdYJQDVjLfRL5XsA5XVZIge2WDZ7S0zpx4=",
"HttpAddress": "https://grpc2.testnet.xmtp.network",
"IsHealthy": true
}
}
]
"size": 2,
"nodes": [
{
"NodeId": 100,
"Node": {
"SigningKeyPub": "BOVELF0f4vAra5oaOGODp3ZoYLQKYHmgIjmU/6LOEFEsToqIY97q2FnD1lQKsgJsgvi4k8HFvvbGP0fZ3zOiB9s=",
"HttpAddress": "https://grpc.testnet.xmtp.network",
"IsHealthy": true
}
},
{
"NodeId": 200,
"Node": {
"SigningKeyPub": "BPwmHUOgFTU5pMZMKXY8sOfjd8DqwpEMPUvtsiNaxwNxz+fKU3SsqOdYJQDVjLfRL5XsA5XVZIge2WDZ7S0zpx4=",
"HttpAddress": "https://grpc2.testnet.xmtp.network",
"IsHealthy": true
}
}
]
}

```

## Deploy XMTPD nodes
Expand All @@ -78,9 +81,9 @@ Node deployment is currently fully handled by [Ephemera](https://github.com/ephe

There are currently two nodes running:

| DNS Name | Location | Public Key |
| --- | ---| -- |
| https://grpc.testnet.xmtp.network | US-EAST-2 | 0x03e5442c5d1fe2f02b6b9a1a386383a7766860b40a6079a0223994ffa2ce10512c |
| DNS Name | Location | Public Key |
| ---------------------------------- | ---------- | -------------------------------------------------------------------- |
| https://grpc.testnet.xmtp.network | US-EAST-2 | 0x03e5442c5d1fe2f02b6b9a1a386383a7766860b40a6079a0223994ffa2ce10512c |
| https://grpc2.testnet.xmtp.network | EU-NORTH-1 | 0x02fc261d43a0153539a4c64c29763cb0e7e377c0eac2910c3d4bedb2235ac70371 |

For more info, refer to the infrastructure README.
Expand All @@ -89,7 +92,6 @@ For more info, refer to the infrastructure README.

The easiest way is to use [GRPC Health Probe](https://github.com/grpc-ecosystem/grpc-health-probe)


```shell
grpc-health-probe -tls -addr grpc.testnet.xmtp.network:443
status: SERVING
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/payer/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/xmtp/xmtpd/pkg/abis"
"github.com/xmtp/xmtpd/contracts/pkg/identityupdates"
"github.com/xmtp/xmtpd/pkg/api/payer"
"github.com/xmtp/xmtpd/pkg/envelopes"
blockchainMocks "github.com/xmtp/xmtpd/pkg/mocks/blockchain"
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestPublishIdentityUpdate(t *testing.T) {

mockMessagePublisher.EXPECT().
PublishIdentityUpdate(mock.Anything, mock.Anything, mock.Anything).
Return(&abis.IdentityUpdatesIdentityUpdateCreated{
Return(&identityupdates.IdentityUpdatesIdentityUpdateCreated{
Raw: types.Log{
TxHash: txnHash,
},
Expand Down
Loading

0 comments on commit 96fe704

Please sign in to comment.