forked from Lilypad-Tech/lilypad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack
executable file
·295 lines (251 loc) · 8.09 KB
/
stack
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OS_ARCH=$(uname -m | awk '{if ($0 ~ /arm64|aarch64/) print "arm64"; else if ($0 ~ /x86_64|amd64/) print "amd64"; else print "unsupported_arch"}')
############################################################################
# chain
############################################################################
function chain() {
ADMIN_ADDRESS=${@:-"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"}
docker run \
--rm \
--name chain \
-p 0.0.0.0:8547:8547 \
-p 0.0.0.0:8548:8548 \
offchainlabs/nitro-node:v2.3.4-b4cc111 \
--init.dev-init \
--init.dev-init-address $ADMIN_ADDRESS \
--node.dangerous.no-l1-listener \
--node.parent-chain-reader.enable=false \
--parent-chain.id=1337 \
--chain.id=412346 \
--persistent.chain /tmp/dev-test \
--node.sequencer \
--execution.sequencer.enable \
--node.dangerous.no-sequencer-coordinator \
--node.staker.enable=false \
--init.empty=false \
--http.port 8547 \
--http.addr 0.0.0.0 \
--ws.port 8548 \
--ws.addr 0.0.0.0
}
function chain-boot() {
echo "- Install local dependencies"
cd hardhat && npm install -y
echo "- Fund services with ether"
npx hardhat run scripts/fund-services-ether.ts --network dev
echo "- Compile contracts"
npx hardhat compile --network dev
cd ..
go-bindings
echo "- Deploy contracts"
cd hardhat
npx hardhat deploy --network dev
echo "- Fund services with tokens"
npx hardhat run scripts/fund-services-tokens.ts --network dev
echo "- Done"
}
function go-bindings() {
# check if the lilypad-solc image exists
# and only build it if it doesn't
if [[ -z $(docker images -q lilypad-solc) ]]; then
docker build -t lilypad-solc hardhat/solc
fi
rm -rf pkg/web3/bindings
mkdir -p pkg/web3/bindings
go-binding LilypadToken token
go-binding LilypadPayments payments
go-binding LilypadStorage storage
go-binding LilypadUsers users
go-binding LilypadMediationRandom mediation
go-binding LilypadOnChainJobCreator jobcreator
go-binding LilypadController controller
go-binding LilypadPow pow
echo "- Generated all go bindings pkg/contract/bindings/"
}
function go-binding() {
local name="$1"
local pkg="$2"
# compile the sol files into bytecode and ABI
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--entrypoint solc \
lilypad-solc \
--base-path . \
--include-path node_modules \
--overwrite \
--abi --bin \
"contracts/$name.sol" \
-o artifacts
chown -R $USER hardhat/artifacts
mkdir -p hardhat/artifacts/bindings/$pkg
# generate the go bindings
docker run --rm \
-v $(pwd)/hardhat:/src \
-w /src \
--entrypoint abigen \
lilypad-solc \
"--bin=artifacts/$name.bin" \
"--abi=artifacts/$name.abi" \
"--pkg=$pkg" "--out=artifacts/bindings/$pkg/$pkg.go"
chown -R $USER hardhat/artifacts/bindings/$pkg
chmod 0644 hardhat/artifacts/bindings/$pkg/$pkg.go
cp -r hardhat/artifacts/bindings/$pkg pkg/web3/bindings/$pkg
echo "- Generated go binding hardhat/artifacts/bindings/$pkg/$pkg.go"
}
function chain-clean(){
rm -rf $(pwd)/hardhat/artifacts
rm -rf $(pwd)/hardhat/cache
rm -rf $(pwd)/hardhat/deployments/geth
rm -rf $(pwd)/hardhat/deployments/dev
rm -rf $(pwd)/hardhat/.openzeppelin
}
############################################################################
# helpers
############################################################################
function hardhat-script() {
(
set -euo pipefail
cd hardhat
npx hardhat run "$@"
)
}
function print-env() {
hardhat-script scripts/print-env.ts | grep export
}
function print-contract-env() {
hardhat-script scripts/print-contract-env.ts | grep export
}
function print-local-dev-env() {
print-contract-env
}
function run-cowsay-onchain() {
cd hardhat
doppler run --preserve-env -p run-cowsay-onchain -c dev -- npx hardhat run scripts/run-cowsay-onchain.ts
}
############################################################################
# solver
############################################################################
function solver() {
echo "- Reminder to do doppler setup to project->solver and config->dev"
doppler run --preserve-env -p solver -c dev -- go run . solver --network dev
}
function solver-docker-build() {
docker build \
-t solver \
-f ./docker/solver/Dockerfile \
--build-arg arch=${OS_ARCH} \
--build-arg network=dev \
.
}
function solver-docker-run() {
docker run \
--rm \
--name solver \
--add-host localhost:host-gateway \
-p 8080:8080 \
-e DOPPLER_TOKEN="$(doppler configs tokens create -p solver -c dev docker --max-age 1m --plain)" \
solver
}
############################################################################
# job creator
############################################################################
function job-creator() {
echo "- Reminder to do doppler setup to project->job-creator and config->dev"
doppler run --preserve-env -p job-creator -c dev -- go run . jobcreator --network dev
}
function job-creator-docker-build() {
docker build \
-t job-creator \
-f ./docker/job-creator/Dockerfile \
--build-arg network=dev \
.
}
function job-creator-docker-run() {
docker run \
--rm \
--name job-creator \
--add-host localhost:host-gateway \
-e DOPPLER_TOKEN="$(doppler configs tokens create -p job-creator -c dev docker --max-age 1m --plain)" \
job-creator
}
############################################################################
# resource provider
############################################################################
function resource-provider() {
echo "- Reminder to do doppler setup to project->resource-provider and config->dev"
doppler run --preserve-env -p resource-provider -c dev -- go run . resource-provider "$@" --network dev --disable-pow true
}
function resource-provider-docker-build() {
docker build \
-t resource-provider \
-f ./docker/resource-provider/Dockerfile \
--build-arg NETWORK=dev \
--build-arg DISABLE_POW=true \
.
}
function resource-provider-docker-run() {
docker run \
--rm \
--privileged \
--name resource-provider \
--add-host localhost:host-gateway \
--env-file <(doppler -p resource-provider -c dev secrets download --no-file --format docker) \
-e OFFER_GPU=0 \
-e BACALHAU_API_HOST="DO_NOT_SET" \
resource-provider
}
############################################################################
# bacalhau node
############################################################################
function bacalhau-node(){
export BACALHAU_SERVE_IPFS_PATH=/tmp/lilypad/data/ipfs
export LOG_LEVEL=debug
bacalhau serve --node-type compute,requester --peer none --private-internal-ipfs=false --job-selection-accept-networked
}
function bacalhau-docker-build() {
docker build \
-t bacalhau \
-f ./docker/bacalhau/Dockerfile \
.
}
function bacalhau-docker-run() {
docker run \
--privileged \
--rm \
--name bacalhau \
--add-host localhost:host-gateway \
-v /tmp/lilypad/data:/tmp/lilypad/data \
-p 1234:1234 \
bacalhau
}
############################################################################
# mediator
############################################################################
function mediator() {
go run . mediator "$@"
}
############################################################################
# tests
############################################################################
function unit-tests() {
cd hardhat
npx hardhat test --network hardhat
}
# this assumes chain is running
# and chain-fund-admin
# and chain-boot
function integration-tests() {
cd test
doppler run --preserve-env -p integration-tests -c dev -- go test -v -count 1 .
}
############################################################################
# run
############################################################################
function run() {
doppler run --preserve-env -p run -c dev -- go run . run --network dev "$@"
}
eval "$@"