Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move all contract related logic to contracts folder #355

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/solidity.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Solidity
name: Solidity

on:
push:
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
run: forge build

- name: Cache data
uses: actions/cache@v4
uses: actions/cache/save@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}
Expand All @@ -56,7 +56,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}
Expand All @@ -77,7 +77,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}
Expand All @@ -98,7 +98,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Restore cache
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: contracts
key: ci-solidity-${{ github.ref }}
Expand Down
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": "0xc5a5C42992dECbae36851359345FE25997F5C42d",
"groupMessagesProxy": "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
"groupMessagesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 65,
"latestUpgradeBlock": 71
"deploymentBlock": 28,
"latestUpgradeBlock": 28
}
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": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
"identityUpdatesProxy": "0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690",
"identityUpdatesProxyAdmin": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},
"deploymentBlock": 67,
"latestUpgradeBlock": 67
"deploymentBlock": 30,
"latestUpgradeBlock": 30
}
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"
;;
Comment on lines +30 to +36
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Standardize the deployment approach for nodes contract

The deployment approach for the nodes contract differs from other cases in several ways:

  1. Uses forge create instead of forge script like other cases
  2. Writes output to ../build/ instead of config/anvil_localnet/
  3. Takes additional parameters ($2, $3) that aren't documented
  4. Has different error handling (no explicit failure check)

Consider standardizing this by:

  1. Implementing the TODO to migrate to forge script
  2. Using consistent output paths
  3. Adding proper error handling
        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
+           forge script --rpc-url "${DOCKER_RPC_URL}" --broadcast script/DeployNodes.s.sol &> /dev/null
+           if [ $? -ne 0 ]; then
+               echo "Failed to deploy nodes contract"
+               exit 1
+           fi
+           
+           echo -e "✅ Nodes contract deployed.\n"
+           cat config/anvil_localnet/Nodes.json
            echo -e "\n"
            ;;

Committable suggestion skipped: line range outside the PR's diff.


*)
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.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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: 2 additions & 0 deletions contracts/src/GroupMessages.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ contract GroupMessages is Initializable, AccessControlUpgradeable, UUPSUpgradeab
uint256 public constant MAX_PAYLOAD_SIZE = 4_194_304;

// State variables
// slither-disable-next-line unused-state,constable-states
uint64 private sequenceId;

/// @dev Reserved storage gap for future upgrades
// slither-disable-next-line unused-state,naming-convention
uint256[50] private __gap;

// Initialization
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/IdentityUpdates.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ contract IdentityUpdates is Initializable, AccessControlUpgradeable, UUPSUpgrade
uint256 public constant MAX_PAYLOAD_SIZE = 4_194_304;

// State variables
// slither-disable-next-line unused-state,constable-states
uint64 private sequenceId;

/// @dev Reserved storage gap for future upgrades
// slither-disable-next-line unused-state,naming-convention
uint256[50] private __gap;

// Initialization
Expand Down
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
Loading
Loading