-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_build.sh
executable file
·336 lines (261 loc) · 9.8 KB
/
run_build.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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/bash
#Build Flag
NETWORK=testnet
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
OWNER="lucas"
RETURN=""
TOKEN="HEART"
ADDR_OWNER=$(seid keys show $OWNER -a --keyring-backend test)
VALIDATOR="seivaloper183xtf2wmcah9fh5kpdr47wlspv3w47c0p8aqde"
echo "OWNER = $ADDR_OWNER"
WALLET="--from $OWNER"
GAS=0.001
echo "seid keys show $OWNER -a --keyring-backend test"
# OUTPUT="/root/Sei-IDO-Tier-Contract/command.txt"
echo "" > /root/Sei-IDO-Tier-Contract/command.txt
case $NETWORK in
localnet)
NODE="http://localhost:26657"
DENOM="usei"
CHAIN_ID="testchain-1"
;;
testnet)
NODE="https://rpc.atlantic-2.seinetwork.io:443"
DENOM="usei"
CHAIN_ID="atlantic-2"
;;
mainnet)
NODE="https://terra-classic-rpc.publicnode.com:443"
DENOM=uluna
CHAIN_ID=columbus-5
;;
esac
NODECHAIN="--node $NODE --chain-id $CHAIN_ID"
#TXFLAG="$NODECHAIN --gas=250000 --fees=250000usei --broadcast-mode block --keyring-backend test -y"
TXFLAG="$NODECHAIN --gas=250000 --fees=250000usei --broadcast-mode block --keyring-backend test -y"
CreateEnv() {
apt update
apt upgrade
apt install curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo apt-get update && sudo apt upgrade -y
sudo apt-get install make build-essential gcc git jq chrony -y
wget https://golang.org/dl/go1.18.1.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz
rm -rf go1.18.1.linux-amd64.tar.gz
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export GO111MODULE=on
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
rustup default stable
rustup target add wasm32-unknown-unknown
git clone https://github.com/classic-terra/core/
cd core
git fetch
git checkout main
make install
cd ../
rm -rf core
}
Execute() {
CMD=$1
echo "**************BEGIN**********************" >> /root/Sei-IDO-Tier-Contract/command.txt
echo $CMD >> /root/Sei-IDO-Tier-Contract/command.txt
echo "------------------------------------------" >> /root/Sei-IDO-Tier-Contract/command.txt
if [[ $CMD == cd* ]] ; then
$CMD > ~/out.log
RETURN=$(cat ~/out.log)
else
RETURN=$(eval $CMD)
fi
echo $RETURN >> /root/Sei-IDO-Tier-Contract/command.txt
echo "*************END*************************" >> /root/Sei-IDO-Tier-Contract/command.txt
}
RustBuild() {
CATEGORY=$1
echo "================================================="
echo "Rust Optimize Build Start for $CATEGORY"
Execute "cd $CATEGORY"
Execute "pwd"
rm -rf target
Execute "RUSTFLAGS='-C link-arg=-s' cargo wasm"
Execute "cp ./target/wasm32-unknown-unknown/release/$CATEGORY.wasm ../release/"
Execute "cd .."
}
Upload() {
CATEGORY=$1
echo "================================================="
echo "Upload Wasm for $CATEGORY"
Execute "seid tx wasm store release/$CATEGORY".wasm" $WALLET $NODECHAIN --gas=3000000 --fees=3000000usei --broadcast-mode block --keyring-backend test -y --output json | jq -r '.txhash'"
UPLOADTX=$RETURN
echo "Upload txHash: "$UPLOADTX
echo "================================================="
echo "GetCode"
CODE_ID=""
while [[ $CODE_ID == "" ]]
do
sleep 3
Execute "seid query tx $UPLOADTX $NODECHAIN --output json | jq -r '.logs[0].events[-1].attributes[-1].value'"
CODE_ID=$RETURN
done
echo "$CATEGORY Contract Code_id: "$CODE_ID
echo $CODE_ID > data/code_$CATEGORY
}
InstantiateTier() {
CATEGORY='tier'
echo "================================================="
echo "Instantiate Contract "$CATEGORY
#read from FILE_CODE_ID
CODE_ID=$(cat data/code_$CATEGORY)
echo "Code id: " $CODE_ID
Execute "seid tx wasm instantiate $CODE_ID '{\"validator\":\"'$VALIDATOR'\", \"admin\":\"'$ADDR_OWNER'\", \"deposits\":[\"300\",\"100\",\"50\",\"10\",\"1\"]}' --admin $ADDR_OWNER $WALLET $TXFLAG --label \"TierContract\" --output json | jq -r '.txhash'"
TXHASH=$RETURN
echo "Transaction hash = $TXHASH"
CONTRACT_ADDR=""
while [[ $CONTRACT_ADDR == "" ]]
do
sleep 3
Execute "seid query tx $TXHASH $NODECHAIN --output json | jq -r '.logs[0].events[0].attributes[0].value'"
CONTRACT_ADDR=$RETURN
done
echo "Contract Address: " $CONTRACT_ADDR
echo $CONTRACT_ADDR > data/contract_$CATEGORY
}
InstantiateIDO() {
CATEGORY='ido'
echo "================================================="
echo "Instantiate Contract "$CATEGORY
#read from FILE_CODE_ID
CODE_ID=$(cat data/code_$CATEGORY)
TIER_CONTRACT=$(cat data/contract_tier)
NFT_CONTRACT=$(cat data/contract_cw721_base)
echo "Code id: " $CODE_ID
echo "Tier Contract: " $TIER_CONTRACT
Execute "seid tx wasm instantiate $CODE_ID '{\"tier_contract\":\"'$TIER_CONTRACT'\", \"nft_contract\":\"'$NFT_CONTRACT'\", \"lock_periods\":[1,2,3,4,5,6]}' --admin $ADDR_OWNER $WALLET $TXFLAG --label \"IDOContract\" --output json | jq -r '.txhash'"
TXHASH=$RETURN
echo "Transaction hash = $TXHASH"
CONTRACT_ADDR=""
while [[ $CONTRACT_ADDR == "" ]]
do
sleep 3
Execute "seid query tx $TXHASH $NODECHAIN --output json | jq -r '.logs[0].events[0].attributes[0].value'"
CONTRACT_ADDR=$RETURN
done
echo "Contract Address: " $CONTRACT_ADDR
echo $CONTRACT_ADDR > data/contract_$CATEGORY
}
InstantiateCW20() {
CATEGORY='cw20_base'
echo "================================================="
echo "Instantiate Contract "$CATEGORY
#read from FILE_CODE_ID
CODE_ID=$(cat data/code_$CATEGORY)
echo "Code id: " $CODE_ID
Execute "seid tx wasm instantiate $CODE_ID '{\"name\":\"KAND\",\"symbol\":\"KAND\",\"decimals\":6,\"initial_balances\":[{\"address\":\"'$ADDR_OWNER'\",\"amount\":\"10000000000\"}],\"mint\":{\"minter\":\"'$ADDR_OWNER'\"},\"marketing\":{\"marketing\":\"'$ADDR_OWNER'\",\"logo\":{\"url\":\"\"}}}' --label \"HOLEV$CODE_CW20\" --admin $ADDR_OWNER $WALLET $TXFLAG --output json | jq -r '.txhash'"
TXHASH=$RETURN
echo "Transaction hash = $TXHASH"
CONTRACT_ADDR=""
while [[ $CONTRACT_ADDR == "" ]]
do
sleep 3
Execute "seid query tx $TXHASH $NODECHAIN --output json | jq -r '.logs[0].events[0].attributes[0].value'"
CONTRACT_ADDR=$RETURN
done
echo "Contract Address: " $CONTRACT_ADDR
echo $CONTRACT_ADDR > data/contract_$CATEGORY
}
InstantiateCW721() {
CATEGORY='cw721_base'
echo "================================================="
echo "Instantiate Contract "$CATEGORY
#read from FILE_CODE_ID
CODE_ID=$(cat data/code_$CATEGORY)
echo "Code id: " $CODE_ID
Execute "seid tx wasm instantiate $CODE_ID '{\"name\":\"KAND\",\"symbol\":\"KAND\",\"minter\":\"'$ADDR_OWNER'\"}' --label \"NFT-KAND\" --admin $ADDR_OWNER $WALLET $TXFLAG --output json | jq -r '.txhash'"
TXHASH=$RETURN
echo "Transaction hash = $TXHASH"
CONTRACT_ADDR=""
while [[ $CONTRACT_ADDR == "" ]]
do
sleep 3
Execute "seid query tx $TXHASH $NODECHAIN --output json | jq -r '.logs[0].events[0].attributes[0].value'"
CONTRACT_ADDR=$RETURN
done
echo "Contract Address: " $CONTRACT_ADDR
echo $CONTRACT_ADDR > data/contract_$CATEGORY
}
#################################################################################
PrintWalletBalance() {
echo "native balance"
echo "========================================="
seid query bank balances $ADDR_OWNER $NODECHAIN
echo "========================================="
# echo "CW20 Token balance"
# echo "========================================="
# seid query wasm contract-state smart "$(cat data/contract_cw20_base)" '{"balance":{"address":"'$ADDR_OWNER'"}}' $NODECHAIN
# echo "========================================="
}
TokenTransfer() {
echo "================================================="
echo "Token Transfer"
PARAM_1='{"transfer": {"recipient": "terra1gwzndny4e4xf7evm5kjva73fqedux5gfwdr0ta", "amount": "'$1'000000"}}'
printf "y\n" | seid tx wasm execute "$(cat data/contract_cw20_base)" "$PARAM_1" $WALLET $TXFLAG
sleep 5
echo "End"
}
CreateNewToken() {
echo "================================================="
echo "Create New Token"
# CODE_ID=$(cat data/code_$CATEGORY)
PAYLOAD='{"deposit": {"instantiate": {"decimals": 6,"initial_balances": [{"address": "terra1gwzndny4e4xf7evm5kjva73fqedux5gfwdr0ta","amount": "123000000"}],"marketing": {"logo": {"url": ""},"marketing": "terra1cajleyhmtf8lua47m8ctnduksr7qtd8at3aezppk89pt5qnwvcgsl9jrdc"},"name": "asd","symbol": "ads"}}}'
printf "y\n" | seid tx wasm execute terra1vuundfe5ck4fsgqyttyt7098k0cafegjxj59yvdzehn0y7gsv28q3xa7pt "$PAYLOAD" --amount 123000000uluna $WALLET $TXFLAG
sleep 5
echo "End"
}
DeployTier() {
CATEGORY=tier
RustBuild $CATEGORY
Upload $CATEGORY
InstantiateTier
}
DeployIDO() {
CATEGORY=ido
RustBuild $CATEGORY
Upload $CATEGORY
InstantiateIDO
}
DeployCw20base() {
CATEGORY=cw20_base
RustBuild $CATEGORY
Upload $CATEGORY
InstantiateCW20
}
DeployCw721base() {
CATEGORY=cw721_base
RustBuild $CATEGORY
Upload $CATEGORY
InstantiateCW721
}
Optimize() {
CATEGORY=$1
Execute "docker run --rm -v ./$CATEGORY --mount type=volume,source=/root/cache/$CATEGORY,target=/target/$CATEGORY --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/rust-optimizer:0.12.11"
}
# InstantiateCW20
# DeployCW20Base
# DeployCW20Stake
# DeployCW20TokenFactory
# TokenTransfer $1
# PrintWalletBalance
# RustBuild tier
# Optimize tier
# Upload tier
# InstantiateTier
# DeployTier
# RustBuild ido
# Upload ido
DeployIDO
# InstantiateIDO
# DeployCw20base
# InstantiateCW20
# DeployCw721base