-
Notifications
You must be signed in to change notification settings - Fork 3
/
justfile
152 lines (116 loc) · 5.41 KB
/
justfile
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
#set export
#set dotenv-filename := ".env"
set dotenv-load
ETH_RPC_URL := env('ETH_RPC_URL', 'https://rpc.sepolia.eth.gateway.fm')
CHAIN_ID := env('CHAIN_ID', '11155111')
ETH_PRIVATE_KEY := env_var('ETH_PRIVATE_KEY')
ETH_PUBLIC_KEY := env_var('ETH_PUBLIC_KEY')
BROADCAST := if env("BROADCAST", "") != "n" {"--broadcast "} else {""}
LEGACY := if env('LEGACY', "") != "" {"--legacy "} else {""}
VERIFIER := env('VERIFIER', 'etherscan')
VERIFY := if env('VERIFY', "") != "n" {"--verify " + VERIFIER} else {""}
forge-script SCRIPT TAIL *ARGS:
cd ./nearx/contract && \
forge script {{SCRIPT}} \
--ffi \
--sender {{ETH_PUBLIC_KEY}} \
--rpc-url {{ETH_RPC_URL}} \
--private-key {{ETH_PRIVATE_KEY}} \
{{TAIL}} {{ARGS}} -vvvv --json
# Deploy the NEARX contract
deploy-contract: (forge-script "Deploy" BROADCAST + VERIFY + LEGACY)
# Initialise the NEARX contract with any parameters such as owner
init-contract: init
forge-script Initialise
# Update the ids for the verifier
update-params: (forge-script "UpdateParams" BROADCAST + LEGACY)
# Upgrade the NEARX contract
upgrade: (forge-script "Upgrade" BROADCAST + VERIFY + LEGACY)
# Request a sync on-chain
request-sync: (forge-script "RequestSync" BROADCAST + LEGACY)
# Request a verify on-chain
request-verify: (forge-script "RequestVerify" BROADCAST + LEGACY)
brunoc := "npx -y @usebruno/cli run"
# Fetch the current active deployments
fetch-deployments OUTPUT:
{{brunoc}} "api/succinct/Get Deployments.bru" --env testnet -o {{OUTPUT}}
# Filter deployments for the specified chain id
filter-chain DEPLOYMENTS CHAIN_ID:
@cat {{DEPLOYMENTS}} | jq -r ".results[0].response.data" | jq -r "[.[] | select(.chain_id == {{CHAIN_ID}})]"
# Filter the deployments for the entrypoint
filter-version VERSION:
jq -r "[.[] | select((.edges.release.name | contains(\"{{VERSION}}\")))]"
# Filter the deployments for the entrypoint
filter-entrypoint ENTRYPOINT:
jq -r "[.[] | select((.edges.release.entrypoint | contains(\"{{ENTRYPOINT}}\")))]"
filter-all OUTPUT $ENTRYPOINT:
#!/usr/bin/env bash
set -euxo pipefail
filtered=`just filter-chain {{OUTPUT}} $CHAIN_ID`
filtered=`just filter-entrypoint $ENTRYPOINT <<< "$filtered"`
just filter-version $VERSION <<< "$filtered"
init: (fetch-deployments "/tmp/deployments.json")
#!/usr/bin/env bash
set -euxo pipefail
S_INFO=$(just filter-all /tmp/deployments.json sync)
echo $S_INFO | jq -r .gateway
echo $S_INFO | jq -r .function_id
just filter-all /tmp/deployments.json verify | jq -r .function_id
call-brunoc REQUEST:
{{brunoc}} "api/succinct/deploy/{{REQUEST}}.bru" --env testnet -o /tmp/{{REQUEST}}.json
check $CHECK_RELEASE_NUM:
{{brunoc}} "api/succinct/deploy/check.bru" --env testnet -o /tmp/check.json
wait-for-success RELEASE_NUM:
#!/usr/bin/env bash
for ((count=0; count<10; count++)); do
just check {{RELEASE_NUM}}
if [ $? -ne 0 ]; then
echo "non zero exit code: $?, trying in 30s"
sleep 60s
else
echo "success"
break
fi
done
extract-release-id:
cat /tmp/new-deployment.json | jq -r ".results[0].response.data.release_id"
extract-release-num:
cat /tmp/new-deployment.json | jq -r ".results[0].response.data.release_number"
current-release ENTRYPOINT:
just filter-all /tmp/deployments.json {{ENTRYPOINT}} | jq -r .edges.release
update-name $RELEASE_ID $VERSION:
npx -y @usebruno/cli run "api/succinct/deploy/update-name.bru" --env-var VERSION={{VERSION}} --env-var RELEASE_ID={{RELEASE_ID}} --env testnet -o /tmp/update-release-name.json
update-current-name ENTRYPOINT:
#!/usr/bin/env bash
ID=$(cat /tmp/{{ENTRYPOINT}}-release.json | jq -r .id)
VERSION=$(cat /tmp/{{ENTRYPOINT}}-release.json | jq -r .git_ref)
just update-name $ID $VERSION || exit 0
get-verifier OUTPUT:
cat {{OUTPUT}} | jq -r '.bytecode'
release-dev $ENTRYPOINT $VERSION:
#!/usr/bin/env bash
set -euxo pipefail
# just call-brunoc "new-deployment"
{{brunoc}} "api/succinct/deploy/new-deployment.bru" --env testnet -o /tmp/new-deployment.json
#
RELEASE_ID=`just extract-release-id`
RELEASE_NUM=`just extract-release-num`
just wait-for-success $RELEASE_NUM
just update-current-name $ENTRYPOINT
cat /tmp/check.json | jq -r ".results[0].response.data" > /tmp/{{ENTRYPOINT}}-release.json
just update-name $RELEASE_ID $VERSION
export CREATE2_SALT=`cast th "$RANDOM$RANDOM$RANDOM$RANDOM" | cast to-uint256| cast tb`
export FUNCTION_VERIFIER=`just get-verifier /tmp/{{ENTRYPOINT}}-release.json`
export DEPLOYOUTPUT=`just forge-script "DeployAndRegisterFunction" {{BROADCAST}} | jq -R 'fromjson?'`
export RETURN=$(jq '.returns' <<< $DEPLOYOUTPUT)
export FUNCTION_ID=$(echo $RETURN | jq -r '."0".value')
export VERIFIER_ADDRESS=$(echo $RETURN | jq -r '."1".value')
export TX_HASH=`cat ./nearx/contract/broadcast/DeployAndRegisterVerifier.sol/{{CHAIN_ID}}/run-latest.json | jq '.receipts[0].transactionHash'`
npx -y @usebruno/cli run "api/succinct/deploy/notify-deployment.bru" \
--env-var RELEASE_ID=$RELEASE_ID \
--env-var VERIFIER_ADDRESS=$VERIFIER_ADDRESS \
--env-var CHAIN_ID={{CHAIN_ID}} \
--env-var FUNCTION_ID=$FUNCTION_ID \
--env-var CREATE2_SALT=$CREATE2_SALT \
--env-var TX_HASH=$TX_HASH \
--env testnet -o /tmp/notify-deployment.json