-
Notifications
You must be signed in to change notification settings - Fork 9
/
deploy.sh
executable file
·182 lines (126 loc) · 4.46 KB
/
deploy.sh
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
#!/bin/bash
# Solana mainnet
# slot # 268,321,180 @ May 27, 2024 21:40:11 UTC
# target slot # 268495152 @ May 28, 2024 10:00:00 PDT
# localnet
# url="http://127.0.0.1:8899"
# devnet
# url="https://api.devnet.solana.com"
# mainnet
url="https://api.mainnet-beta.solana.com"
# nohup solana-test-validator &
solana config set --url "$url"
# solana airdrop 100
max=4
miners=''
current_slot=$(solana slot | awk '{print $0}')
echo "current slot= $current_slot"
# start_slot=$((current_slot+330))
start_slot=268484759
echo "start slot= $start_slot"
timestamp=$(date +%s)
for (( kind=0; kind < $max; kind++ ))
do
echo
echo
echo "##### Miner kind=$kind #####"
echo
rm ./target/deploy/sol_xen_miner.so
rm ./target/deploy/sol_xen_miner-keypair.json
anchor build -p sol-xen-miner
key=$(anchor keys list | grep "sol_xen_miner" | awk -F': ' '{print $2}')
echo " key= $key"
gsed -i 's/declare_id!("\(.*\)");/declare_id!("'$key'");/' ./programs/sol-xen-miner/src/lib.rs
# const START_SLOT: u64 = 301_816_336;
gsed -i 's/const START_SLOT: u64 = \(.*\);/const START_SLOT: u64 = '$start_slot';/' ./programs/sol-xen-miner/src/lib.rs
anchor build -p sol-xen-miner
echo
echo
anchor deploy -p sol-xen-miner -- --with-compute-unit-price 1000000 --max-sign-attempts 1000
echo
echo "Sleeping for 5s..."
sleep 5
echo
echo "Initializing miner..."
echo
tsx ./admin/init_miner.ts --kind $kind
# should fail!
# tsx ./admin/init_miner.ts --kind $kind
solana program set-upgrade-authority "$key" -u "$url" --final
miners="$miners$key"
max_less_1=$((max - 1))
if [ "$kind" -lt "$max_less_1" ]; then
miners="$miners,"
fi
# "address": "5i4ZPZujwASXGSYENhQEEijiU4EWBzobPAKzKUs87khw",
gsed -i 's/"address": "\(.*\)",/"address": "'$key'",/' "./target/idl/sol_xen_miner_$kind.json"
gsed -i 's/"address": "\(.*\)",/"address": "'$key'",/' "./target/types/sol_xen_miner_$kind.ts"
echo
done
echo
echo "Miners=$miners"
echo
echo
echo "##### Minter #####"
echo
gsed -i 's/comma_delimited = "\(.*\)";/comma_delimited = "'$miners'";/' ./programs/sol-xen-minter/src/lib.rs
rm ./target/deploy/sol_xen_minter.so
rm ./target/deploy/sol_xen_minter-keypair.json
anchor build -p sol-xen-miner
minter_key=$(anchor keys list | grep "sol_xen_minter" | awk -F': ' '{print $2}')
echo " minter key= $minter_key"
gsed -i 's/declare_id!("\(.*\)");/declare_id!("'$minter_key'");/' ./programs/sol-xen-minter/src/lib.rs
gsed -i 's/const START_SLOT: u64 = \(.*\);/const START_SLOT: u64 = '$start_slot';/' ./programs/sol-xen-minter/src/lib.rs
anchor build -p sol-xen-minter
echo
echo
anchor deploy -p sol-xen-minter -- --with-compute-unit-price 1000000 ----max-sign-attempts 1000 --use-rpc
echo
echo "Sleeping for 5s..."
sleep 5
echo
echo "Initializing minter..."
echo
tsx ./admin/init_minter.ts
# should fail
# tsx ./admin/init_minter.ts
solana program set-upgrade-authority "$minter_key" -u "$url" --final
timestamp_end=$(date +%s)
delta=$((timestamp_end-timestamp))
echo "Deployment took $delta s"
# echo
# echo "Relinquishing control..."
# echo
# tsx ./admin/relinquish_mint_control.ts
echo
echo "Deployment done"
echo
echo
echo "Modifying clients"
echo
# || '....';
gsed -i "s/process.env.MINERS || '\(.*\)';/process.env.MINERS || '"$miners"';/" ./client/multiminer.ts
# const MINERS: &str = "
gsed -i 's/const MINERS: \&str = "\(.*\)";/const MINERS: \&str = "'$miners'";/' ./app/sol-xen-client/src/main.rs
gsed -i 's/const MINERS: \&str = "\(.*\)";/const MINERS: \&str = "'$miners'";/' ./app/sol-xen-multiminer/src/main.rs
gsed -i 's/const MINTER: \&str = "\(.*\)";/const MINTER: \&str = "'$minter_key'";/' ./app/sol-xen-multiminer/src/main.rs
# echo
# echo "Doing test mines and mints"
# echo "Running TSX multiminer"
# echo
# tsx ./client/multiminer.ts mine --address 0x6B889Dcfad1a6ddf7dE3bC9417F5F51128efc964 -r 10 -f 1 -d 1 -a 10
echo
# echo "Pausing for 5s"
# sleep 5
echo "Compiling and Running NodeJS multiminer"
tsc 1>/dev/null
# runner.ts
gsed -i "s/runner.ts/runner.js/" ./client/multiminer.js
gsed -i "s/autominter.ts/autominter.js/" ./client/multiminer.js
gsed -i "s/multiminer/multiminer.js/" ./client/runner.js
# node ./client/multiminer.js mine --address 0x6B889Dcfad1a6ddf7dE3bC9417F5F51128efc964 -r 10 -f 1 -d 1 -a 10
# echo
# echo "Pausing for 5s"
# sleep 5
# echo "Running Rust multiminer"
# cargo run --package sol-xen-multiminer -- --address 0x6B889Dcfad1a6ddf7dE3bC9417F5F51128efc964 -r 10 -f 1 -d 1 -a 10