-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
254 lines (233 loc) · 11 KB
/
Copy pathmakefile
File metadata and controls
254 lines (233 loc) · 11 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
.PHONY: deploy install-contract-deps anvil update-env update-contract-submodules update-saving-circles-dev reset-supabase start-local warp time-increase mine timestamp time-reset
ANVIL_ACCOUNTS := 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
0x90F79bf6EB2c4f870365E785982E1f101E93b906 \
0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 \
0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc \
0x976EA74026E726554dB657fA54763abd0C3a0aa9 \
0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 \
0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f \
0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
# Default values
RPC_URL ?= http://localhost:8545
# first anvil's account
PRIVATE_KEY ?= 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ADMIN_ADDRESS ?= 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
OZ_UPGRADEABLE_REENTRANCY_COMMIT ?= 5c4c29275d02e06265ce1cfcad5a420b58a5ca02
SAVING_CIRCLES_BRANCH ?= dev
SOLC_OPTIMIZER_RUNS ?= 200
anvil:
anvil --fork-url https://rpc.gnosischain.com --chain-id 31337 --block-time 5
anvil-reset:
@cast rpc anvil_reset --rpc-url $(RPC_URL)
@echo "✓ Reset fork to fresh state (run 'make reset-nonces' if nonces are still off)"
reset-nonces:
@echo "Resetting nonces for all Anvil accounts..."
@for account in $(ANVIL_ACCOUNTS); do \
cast rpc anvil_setNonce $$account 0 --rpc-url $(RPC_URL) > /dev/null; \
echo "✓ Reset nonce for $$account"; \
done
@echo "✓ All nonces reset successfully"
install-contract-deps:
cd contracts && forge install
deploy:
cd contracts && \
export RPC_URL=$(RPC_URL) && \
export PRIVATE_KEY=$(PRIVATE_KEY) && \
export ADMIN_ADDRESS=$(ADMIN_ADDRESS) && \
forge script script/Deploy.s.sol:Deploy \
--optimize \
--optimizer-runs $(SOLC_OPTIMIZER_RUNS) \
--rpc-url $(RPC_URL) \
--broadcast \
--private-key $(PRIVATE_KEY) \
--legacy
$(MAKE) update-env
update-env:
@echo "Updating .env.local with deployed contract addresses..."
@if [ ! -f contracts/out/SAVING_CIRCLES_DEPLOYMENT.json ]; then \
echo "Error: contracts/out/SAVING_CIRCLES_DEPLOYMENT.json not found"; \
exit 1; \
fi
@if [ ! -f .env.local ]; then \
echo "Error: .env.local not found"; \
exit 1; \
fi
$(eval BREAD_TOKEN := $(shell jq -r '.breadToken' contracts/out/SAVING_CIRCLES_DEPLOYMENT.json))
$(eval SAVING_CIRCLES_PROXY := $(shell jq -r '.savingCirclesProxy' contracts/out/SAVING_CIRCLES_DEPLOYMENT.json))
$(eval SAVING_CIRCLES_VIEWER := $(shell jq -r '.savingCirclesViewer' contracts/out/SAVING_CIRCLES_DEPLOYMENT.json))
$(eval AUTOMATIC_SAVING_CIRCLES := $(shell jq -r '.automaticSavingCircles' contracts/out/SAVING_CIRCLES_DEPLOYMENT.json))
$(eval CREATION_BLOCK := $(shell cast block latest --rpc-url $(RPC_URL) | grep number | awk '{print $$2}'))
@if [ -z "$(BREAD_TOKEN)" ] || [ "$(BREAD_TOKEN)" = "null" ]; then \
echo "Error: Could not parse breadToken from JSON file"; \
exit 1; \
fi
@if [ -z "$(SAVING_CIRCLES_PROXY)" ] || [ "$(SAVING_CIRCLES_PROXY)" = "null" ]; then \
echo "Error: Could not parse savingCirclesProxy from JSON file"; \
exit 1; \
fi
@if [ -z "$(SAVING_CIRCLES_VIEWER)" ] || [ "$(SAVING_CIRCLES_VIEWER)" = "null" ]; then \
echo "Error: Could not parse savingCirclesViewer from JSON file"; \
exit 1; \
fi
@if [ -z "$(AUTOMATIC_SAVING_CIRCLES)" ] || [ "$(AUTOMATIC_SAVING_CIRCLES)" = "null" ]; then \
echo "Error: Could not parse automaticSavingCircles from JSON file"; \
exit 1; \
fi
@sed -i.bak 's|^NEXT_PUBLIC_BREAD_TOKEN_ADDRESS=.*|NEXT_PUBLIC_BREAD_TOKEN_ADDRESS=$(BREAD_TOKEN)|' .env.local
@sed -i.bak 's|^NEXT_PUBLIC_SAVING_CIRCLES_CONTRACT_ADDRESS=.*|NEXT_PUBLIC_SAVING_CIRCLES_CONTRACT_ADDRESS=$(SAVING_CIRCLES_PROXY)|' .env.local
@sed -i.bak 's|^NEXT_PUBLIC_SAVING_CIRCLES_VIEWER_CONTRACT_ADDRESS=.*|NEXT_PUBLIC_SAVING_CIRCLES_VIEWER_CONTRACT_ADDRESS=$(SAVING_CIRCLES_VIEWER)|' .env.local
@sed -i.bak 's|^NEXT_PUBLIC_AUTOMATIC_SAVING_CIRCLES_CONTRACT_ADDRESS=.*|NEXT_PUBLIC_AUTOMATIC_SAVING_CIRCLES_CONTRACT_ADDRESS=$(AUTOMATIC_SAVING_CIRCLES)|' .env.local
@sed -i.bak 's|^NEXT_PUBLIC_SAVING_CIRCLES_CONTRACT_CREATION_BLOCK=.*|NEXT_PUBLIC_SAVING_CIRCLES_CONTRACT_CREATION_BLOCK=$(CREATION_BLOCK)|' .env.local
@rm -f .env.local.bak
@echo "✓ Updated .env.local successfully with contract addresses and creation block $(CREATION_BLOCK)"
update-contract-submodules:
git submodule sync --recursive && \
git submodule update --init --recursive
@# Recover any submodule with invalid HEAD or missing refs
@for submodule in $$(git config --file .gitmodules --get-regexp path | awk '{print $$2}'); do \
head_file=".git/modules/$$submodule/HEAD"; \
if [ -f "$$head_file" ] && grep -q "refs/heads/.invalid" "$$head_file"; then \
echo "Detected invalid $$submodule HEAD; reinitializing..."; \
git submodule deinit -f "$$submodule" || true; \
rm -rf ".git/modules/$$submodule"; \
rm -rf "$$submodule"; \
git submodule update --init "$$submodule"; \
elif ! git -C "$$submodule" rev-parse --verify HEAD >/dev/null 2>&1; then \
echo "Detected broken $$submodule checkout; reinitializing..."; \
git submodule deinit -f "$$submodule" || true; \
rm -rf ".git/modules/$$submodule"; \
rm -rf "$$submodule"; \
git submodule update --init "$$submodule"; \
fi; \
done
git -C contracts/lib/openzeppelin-contracts-upgradeable fetch origin master && \
git -C contracts/lib/openzeppelin-contracts-upgradeable checkout $(OZ_UPGRADEABLE_REENTRANCY_COMMIT)
@test -f contracts/lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol || \
( echo "Error: missing contracts/lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol after checkout $(OZ_UPGRADEABLE_REENTRANCY_COMMIT)"; exit 1 )
git -C contracts/lib/saving-circles fetch origin $(SAVING_CIRCLES_BRANCH) && \
git -C contracts/lib/saving-circles checkout $(SAVING_CIRCLES_BRANCH) && \
git -C contracts/lib/saving-circles pull --ff-only origin $(SAVING_CIRCLES_BRANCH)
update-saving-circles-dev:
git submodule update --init contracts/lib/saving-circles && \
git -C contracts/lib/saving-circles fetch origin $(SAVING_CIRCLES_BRANCH) && \
git -C contracts/lib/saving-circles checkout $(SAVING_CIRCLES_BRANCH) && \
git -C contracts/lib/saving-circles pull --ff-only origin $(SAVING_CIRCLES_BRANCH)
# Wipes the off-chain stack data so local dev starts from a clean slate.
# user_stacks is deleted before stacks_metadata to respect the FK (stack_id).
reset-supabase:
@if [ ! -f .env.local ]; then \
echo "Error: .env.local not found"; \
exit 1; \
fi
@NODE_ENV=$$(grep -E '^NEXT_PUBLIC_NODE_ENV=' .env.local | cut -d= -f2- | tr -d '"'\'' '); \
if [ "$$NODE_ENV" != "local" ]; then \
echo "Error: reset-supabase only runs when NEXT_PUBLIC_NODE_ENV=local (got '$$NODE_ENV'). Refusing to wipe a non-local database."; \
exit 1; \
fi; \
SUPABASE_URL=$$(grep -E '^NEXT_PUBLIC_SUPABASE_URL=' .env.local | cut -d= -f2- | tr -d '"'\'' '); \
SERVICE_KEY=$$(grep -E '^SUPABASE_SERVICE_ROLE_KEY=' .env.local | cut -d= -f2- | tr -d '"'\'' '); \
if [ -z "$$SUPABASE_URL" ] || [ -z "$$SERVICE_KEY" ]; then \
echo "Error: NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY must be set in .env.local"; \
exit 1; \
fi; \
echo "Clearing off-chain stack data (user_stacks, stacks_metadata)..."; \
for entry in "user_stacks:user_id" "stacks_metadata:id"; do \
table=$${entry%%:*}; col=$${entry##*:}; \
status=$$(curl -s -o /dev/null -w '%{http_code}' -X DELETE \
"$$SUPABASE_URL/rest/v1/$$table?$$col=not.is.null" \
-H "apikey: $$SERVICE_KEY" \
-H "Authorization: Bearer $$SERVICE_KEY"); \
if [ "$$status" != "200" ] && [ "$$status" != "204" ]; then \
echo "Error: failed to clear $$table (HTTP $$status)"; \
exit 1; \
fi; \
echo "✓ Cleared $$table"; \
done
# Make sure to start a new anvil instance before running this
start-local:
$(MAKE) reset-supabase
rm -rf contracts/broadcast contracts/cache contracts/out
$(MAKE) deploy
pnpm run dev
# Time manipulation commands for Anvil
mine:
@cast rpc evm_mine --rpc-url $(RPC_URL)
@echo "✓ Mined 1 block"
timestamp:
@echo "Current block timestamp:"
@cast block latest --rpc-url $(RPC_URL) | grep timestamp
warp:
@if [ -z "$(TIMESTAMP)" ]; then \
echo "Error: TIMESTAMP parameter required"; \
echo "Usage: make warp TIMESTAMP=1735689600"; \
exit 1; \
fi
@cast rpc evm_setNextBlockTimestamp $(TIMESTAMP) --rpc-url $(RPC_URL)
@cast rpc evm_mine --rpc-url $(RPC_URL)
@echo "✓ Warped to timestamp $(TIMESTAMP)"
time-increase:
@if [ -z "$(SECONDS)" ]; then \
echo "Error: SECONDS parameter required"; \
echo "Usage: make time-increase SECONDS=86400"; \
exit 1; \
fi
@cast rpc evm_increaseTime $(SECONDS) --rpc-url $(RPC_URL)
@cast rpc evm_mine --rpc-url $(RPC_URL)
@echo "✓ Increased time by $(SECONDS) seconds"
time-reset:
@echo "Resetting to current time..."
@cast rpc evm_setNextBlockTimestamp $$(date +%s) --rpc-url $(RPC_URL)
@cast rpc evm_mine --rpc-url $(RPC_URL)
@echo "✓ Reset to current timestamp: $$(date +%s)"
eth ?= __unset__
bread ?= __unset__
FUND_WALLET_ADDRESS := $(filter-out fund-wallet, $(MAKECMDGOALS))
# Fund one or more wallets with ETH and/or BREAD on the local Anvil chain.
# Pass any number of 0x addresses; the amounts apply to each one.
# make fund-wallet 0xAddr1 [0xAddr2 ...] # 100 ETH + 100 BREAD each (default)
# make fund-wallet 0xAddr1 0xAddr2 eth=50 # 50 ETH each, no BREAD
# make fund-wallet 0xAddr1 bread=200 # 200 BREAD each, no ETH
# Note: eth= and bread= are mutually exclusive — pass neither to fund both.
fund-wallet:
@if [ -z "$(FUND_WALLET_ADDRESS)" ]; then \
echo "Error: wallet address required"; \
echo "Usage: make fund-wallet 0xAddr1 [0xAddr2 ...] [eth=100] [bread=100]"; \
exit 1; \
fi
@BREAD_TOKEN=$$(jq -r '.breadToken' contracts/out/SAVING_CIRCLES_DEPLOYMENT.json); \
FUND_ETH=0; FUND_BREAD=0; \
if [ "$(eth)" = "__unset__" ] && [ "$(bread)" = "__unset__" ]; then \
FUND_ETH=100; FUND_BREAD=100; \
elif [ "$(eth)" != "__unset__" ]; then \
FUND_ETH=$(eth); \
elif [ "$(bread)" != "__unset__" ]; then \
FUND_BREAD=$(bread); \
fi; \
ETH_WEI_HEX=""; TOKEN_WEI=""; \
if [ "$$FUND_ETH" != "0" ]; then ETH_WEI_HEX=$$(printf '0x%x' $$(cast to-wei $$FUND_ETH)); fi; \
if [ "$$FUND_BREAD" != "0" ]; then TOKEN_WEI=$$(cast to-wei $$FUND_BREAD); fi; \
for WALLET in $(FUND_WALLET_ADDRESS); do \
echo "Funding $$WALLET..."; \
if [ "$$FUND_ETH" != "0" ]; then \
cast rpc anvil_setBalance $$WALLET $$ETH_WEI_HEX --rpc-url $(RPC_URL) > /dev/null; \
echo "✓ Set ETH balance to $$FUND_ETH ETH"; \
fi; \
if [ "$$FUND_BREAD" != "0" ]; then \
cast send $$BREAD_TOKEN \
"transfer(address,uint256)" \
$$WALLET $$TOKEN_WEI \
--rpc-url $(RPC_URL) \
--private-key $(PRIVATE_KEY) > /dev/null; \
echo "✓ Transferred $$FUND_BREAD BREAD to $$WALLET"; \
fi; \
echo "Balances for $$WALLET:"; \
ETH_BAL=$$(cast balance $$WALLET --rpc-url $(RPC_URL) --ether); \
BREAD_BAL=$$(cast call $$BREAD_TOKEN 'balanceOf(address)' $$WALLET --rpc-url $(RPC_URL) | cast --to-dec | cast from-wei); \
echo " ETH: $$ETH_BAL ETH"; \
echo " BREAD: $$BREAD_BAL BREAD"; \
echo ""; \
done
0x%:
@: