-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
239 lines (203 loc) Β· 8.71 KB
/
Makefile
File metadata and controls
239 lines (203 loc) Β· 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/make -f
# Check if user is in docker group to determine if sudo is needed
SUDO := $(shell if groups | grep -q docker; then echo ''; else echo 'sudo'; fi)
# Define common variables
CARGO=cargo
INPUT_DATA?=``
COMPONENT_FILENAME?=wavs_eas_attest.wasm
CREDENTIAL?=""
DOCKER_IMAGE?=ghcr.io/lay3rlabs/wavs:35c96a4
MIDDLEWARE_DOCKER_IMAGE?=ghcr.io/lay3rlabs/wavs-middleware:0.4.1
IPFS_ENDPOINT?=http://127.0.0.1:5001
RPC_URL?=http://127.0.0.1:8545
SERVICE_FILE?=.docker/service.json
SERVICE_SUBMISSION_ADDR?=`jq -r .deployedTo .docker/submit.json`
SERVICE_TRIGGER_ADDR?=`jq -r .deployedTo .docker/trigger.json`
WASI_BUILD_DIR ?= ""
ENV_FILE?=.env
WAVS_CMD ?= $(SUDO) docker run --rm --network host $$(test -f ${ENV_FILE} && echo "--env-file ./${ENV_FILE}") -v $$(pwd):/data ${DOCKER_IMAGE} wavs-cli
WAVS_ENDPOINT?="http://127.0.0.1:8000"
-include ${ENV_FILE}
# Default target is build
default: build
## build: building the project
build: _build_forge wasi-build
## wasi-build: building WAVS wasi components | WASI_BUILD_DIR
wasi-build:
@echo "π¨ Building WASI components..."
@./script/build_components.sh $(WASI_BUILD_DIR)
@echo "β
WASI build complete"
## wasi-exec: executing the WAVS wasi component(s) with ABI function | COMPONENT_FILENAME, INPUT_DATA
wasi-exec: pull-image
@$(WAVS_CMD) exec --log-level=info --data /data/.docker --home /data \
--component "/data/compiled/$(COMPONENT_FILENAME)" \
--input $(shell cast abi-encode "f(string)" "${INPUT_DATA}") \
## wasi-exec-fixed: the same as wasi-exec, except uses a fixed input as bytes (used in Go & TS components) | COMPONENT_FILENAME, INPUT_DATA
wasi-exec-fixed: pull-image
@$(WAVS_CMD) exec --log-level=info --data /data/.docker --home /data \
--component "/data/compiled/$(COMPONENT_FILENAME)" \
--input `cast format-bytes32-string $(INPUT_DATA)`
## clean: cleaning the project files
clean: clean-docker
@forge clean
@$(CARGO) clean
@rm -rf cache
@rm -rf out
@rm -rf broadcast
## clean-docker: remove unused docker containers
clean-docker:
@$(SUDO) docker rm -v $(shell $(SUDO) docker ps -a --filter status=exited -q) > /dev/null 2>&1 || true
## validate-component: validate a WAVS component against best practices
validate-component:
@if [ -z "$(COMPONENT)" ]; then \
echo "Usage: make validate-component COMPONENT=your-component-name"; \
echo "Example: make validate-component COMPONENT=eth-price-oracle"; \
exit 1; \
fi
@if [ ! -d "./components/$(COMPONENT)" ]; then \
echo "Error: Component directory ./components/$(COMPONENT) not found"; \
exit 1; \
fi
@if [ ! -d "./test_utils" ]; then \
echo "Error: Test utilities not found. Please ensure test_utils exists."; \
exit 1; \
fi
@cd test_utils && ./validate_component.sh $(COMPONENT)
## fmt: formatting solidity and rust code
fmt:
@forge fmt --check
@$(CARGO) fmt
## test: running tests
test:
@forge test
## setup: install initial dependencies
setup: check-requirements
@echo "π¦ Installing dependencies..."
@echo " β’ Installing Forge dependencies..."
@forge install > /dev/null 2>&1
@echo " β’ Installing npm dependencies..."
@npm install > /dev/null 2>&1
@echo "β
Dependencies installed"
## start-all-local: starting anvil and core services (like IPFS for example)
start-all-local: clean-docker setup-env
@sh ./script/start_all.sh
## get-trigger-from-deploy: getting the trigger address from the script deploy
get-trigger-from-deploy:
@jq -r '.service_contracts.trigger' .docker/deployment_summary.json
## get-submit-from-deploy: getting the submit address from the script deploy
get-submit-from-deploy:
@jq -r '.logs[] | select(type == "string" and startswith("Attester deployed at:")) | split(": ")[1]' .docker/eas_deploy.json 2>/dev/null || echo ""
## wavs-cli: running wavs-cli in docker
wavs-cli:
@$(WAVS_CMD) $(filter-out $@,$(MAKECMDGOALS))
## upload-component: uploading the WAVS component | COMPONENT_FILENAME, WAVS_ENDPOINT
upload-component:
@if [ -z "${COMPONENT_FILENAME}" ]; then \
echo "β Error: COMPONENT_FILENAME is not set"; \
echo "π‘ Set it with: export COMPONENT_FILENAME=evm_price_oracle.wasm"; \
echo "π See 'make help' for more info"; \
exit 1; \
fi
@echo "π€ Uploading component: ${COMPONENT_FILENAME}..."
@wget --post-file=./compiled/${COMPONENT_FILENAME} --header="Content-Type: application/wasm" -O - ${WAVS_ENDPOINT}/upload | jq -r .digest
@echo "β
Component uploaded successfully"
IPFS_GATEWAY?="https://ipfs.io/ipfs"
## deploy-service: deploying the WAVS component service json | SERVICE_URL, CREDENTIAL, WAVS_ENDPOINT
deploy-service:
# this wait is required to ensure the WAVS service has time to service check
@if [ -z "${SERVICE_URL}" ]; then \
echo "β Error: SERVICE_URL is not set"; \
echo "π‘ Set it with: export SERVICE_URL=<ipfs-or-http-url>"; \
echo "π See 'make help' for more info"; \
exit 1; \
fi
@if [ -n "${WAVS_ENDPOINT}" ]; then \
echo "π Checking WAVS service at ${WAVS_ENDPOINT}..."; \
if [ "$$(curl -s -o /dev/null -w "%{http_code}" ${WAVS_ENDPOINT}/app)" != "200" ]; then \
echo "β WAVS service not reachable at ${WAVS_ENDPOINT}"; \
echo "π‘ Re-try running in 1 second, if not then validate the wavs service is online / started."; \
exit 1; \
fi; \
echo "β
WAVS service is running"; \
fi
@echo "π Deploying service from: ${SERVICE_URL}..."
@$(WAVS_CMD) deploy-service --service-url ${SERVICE_URL} --log-level=debug --data /data/.docker --home /data $(if $(WAVS_ENDPOINT),--wavs-endpoint $(WAVS_ENDPOINT),) $(if $(IPFS_GATEWAY),--ipfs-gateway $(IPFS_GATEWAY),)
@echo "β
Service deployed successfully"
PINATA_API_KEY?=""
## upload-to-ipfs: uploading the a service config to IPFS | SERVICE_FILE, [PINATA_API_KEY]
upload-to-ipfs:
@if [ `sh script/get-deploy-status.sh` = "LOCAL" ]; then \
curl -X POST "http://127.0.0.1:5001/api/v0/add?pin=true" -H "Content-Type: multipart/form-data" -F file=@${SERVICE_FILE} | jq -r .Hash; \
else \
if [ -z "${PINATA_API_KEY}" ]; then \
echo "Error: PINATA_API_KEY is not set. Please set it to your Pinata API key -- https://app.pinata.cloud/developers/api-keys."; \
exit 1; \
fi; \
curl -X POST --url https://uploads.pinata.cloud/v3/files --header "Authorization: Bearer ${PINATA_API_KEY}" --header 'Content-Type: multipart/form-data' --form file=@${SERVICE_FILE} --form network=public --form name=service-`date +"%b-%d-%Y"`.json | jq -r .data.cid; \
fi
COMMAND?=""
PAST_BLOCKS?=500
wavs-middleware:
@docker run --rm --network host --env-file ${ENV_FILE} \
$(if ${WAVS_SERVICE_MANAGER_ADDRESS},-e WAVS_SERVICE_MANAGER_ADDRESS=${WAVS_SERVICE_MANAGER_ADDRESS}) \
$(if ${PAST_BLOCKS},-e PAST_BLOCKS=${PAST_BLOCKS}) \
-v ./.nodes:/root/.nodes ${MIDDLEWARE_DOCKER_IMAGE} ${COMMAND}
## update-submodules: update the git submodules
update-submodules:
@git submodule update --init --recursive
# Declare phony targets
.PHONY: build clean fmt bindings test
.PHONY: help
help: Makefile
@echo
@echo " Choose a command run"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo
# helpers
_build_forge:
@forge build
.PHONY: setup-env
setup-env:
@if [ ! -f ${ENV_FILE} ]; then \
if [ -f .env.example ]; then \
echo "Creating ${ENV_FILE} file from .env.example..."; \
cp .env.example ${ENV_FILE}; \
echo "${ENV_FILE} file created successfully!"; \
fi; \
fi
pull-image:
@if ! docker image inspect ${DOCKER_IMAGE} &>/dev/null; then \
echo "Image ${DOCKER_IMAGE} not found. Pulling..."; \
$(SUDO) docker pull ${DOCKER_IMAGE}; \
fi
# check versions
## check-requirements: verify system requirements are installed
check-requirements:
@echo "π Validating system requirements..."
@$(MAKE) check-node check-jq check-cargo check-docker
@echo "β
All requirements satisfied"
check-command:
@command -v $(1) > /dev/null 2>&1 || (echo "β $(1) not found. Please install $(1), reference the System Requirements section"; exit 1)
check-command-with-help:
@command -v $(1) > /dev/null 2>&1 || \
(echo "β $(1) not found"; echo "π‘ Install: $(2)"; exit 1)
.PHONY: check-node
check-node:
@$(call check-command-with-help,node,"curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash && nvm install --lts")
@NODE_VERSION=$$(node --version); \
MAJOR_VERSION=$$(echo $$NODE_VERSION | sed 's/^v\([0-9]*\)\..*/\1/'); \
if [ $$MAJOR_VERSION -lt 21 ]; then \
echo "β Node.js version $$NODE_VERSION is less than required v21"; \
echo "π‘ Upgrade with: nvm install --lts"; \
exit 1; \
fi
.PHONY: check-jq
check-jq:
@$(call check-command-with-help,jq,"brew install jq (macOS) or apt install jq (Linux)")
.PHONY: check-cargo
check-cargo:
@$(call check-command-with-help,cargo,"curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh")
.PHONY: check-docker
check-docker:
@$(call check-command-with-help,docker,"https://docs.docker.com/get-docker/")