This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
249 lines (212 loc) · 10.8 KB
/
pipeline.yml
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
name: Pipeline
on:
push:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Build
run: |
cargo build --verbose
working-directory: .
test:
needs: build
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: test
run: |
cargo test --verbose
working-directory: .
devnet:
#needs: test
name: deploy on devnet
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: devnet
steps:
- uses: actions/checkout@v4
- name: Downloading elys
run: |
URL=https://github.com/elys-network/elys/releases/download/v0.30.0/elysd-v0.30.0-linux-amd64
wget $URL -O elysd
chmod +x elysd
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Compile
run: |
getNewVersionBYContract(){
local contractAddress=$1
ELYSD=./elysd
local json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "$contractAddress" '{ "version": {} }')
local VERSION=$(echo $json | jq -r ".data.version")
# Extract the major, minor, and patch versions
local version_parts=(${VERSION//./ })
local major=${version_parts[0]}
local minor=${version_parts[1]}
local patch=${version_parts[2]}
# Increment the minor version
local minor=$((minor + 1))
# Update the version string
VERSION="$major.$minor.$patch"
echo $VERSION
}
accountHistoryContractVersion=$(getNewVersionBYContract ${{vars.AH_CONTRACT_ADDRESS}})
tradeShieldContractVersion=$(getNewVersionBYContract ${{vars.TS_CONTRACT_ADDRESS}})
financialSnapshotContractVersion=$(getNewVersionBYContract ${{vars.FS_CONTRACT_ADDRESS}})
echo "new accountHistoryContractVersion: $accountHistoryContractVersion"
echo "new tradeShieldContractVersion: $tradeShieldContractVersion"
echo "new financialSnapshotContractVersion: $financialSnapshotContractVersion"
sed -i "s/^version = .*/version = \"$accountHistoryContractVersion\"/" contracts/account-history-contract/Cargo.toml
sed -i "s/^version = .*/version = \"$tradeShieldContractVersion\"/" contracts/trade-shield-contract/Cargo.toml
sed -i "s/^version = .*/version = \"$financialSnapshotContractVersion\"/" contracts/financial-snapshot-contract/Cargo.toml
cargo update
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0
- name: Deploy
run: |
# helper functions
extract_txhash() { awk -F 'txhash: ' '/txhash:/{print $2; exit}'; }
extract_code_id() { awk -F 'key: code_id|value: ' '/key: code_id/ { getline; gsub(/"/, "", $2); print $2; exit }'; }
extract_contract_address() { awk -F 'key: _contract_address|value: ' '/key: _contract_address/ { getline; gsub(/"/, "", $2); print $2; exit }'; }
extract_account_number() { awk -F 'account_number: ' '/account_number:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; }
extract_sequence() { awk -F 'sequence: ' '/sequence:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; }
ELYSD=./elysd
wait_for_tx() {
local txhash=$1
# loop until query tx cli does not fail
while ! $ELYSD q tx $txhash --node "$NODE" &> /dev/null; do
echo "Waiting for the transaction $txhash to be included in a block..."
sleep 0.5
done
}
exit_if_tx_is_empty() {
local tx=$1
if [[ -z "$tx" ]]; then
echo "Error: there is not a txhash"
exit 1
fi
}
# environment variables
NODE=${{vars.NODE}}
NAME=${{vars.NAME}}
# contract addresses enviroment variables
# set elysd config
$ELYSD config keyring-backend test
$ELYSD config node $NODE
$ELYSD config chain-id ${{vars.CHAIN_ID}}
$ELYSD config broadcast-mode sync
# save private keys to files
echo "${{ secrets.PRIVATE_KEY_MALLORCA }}" > /tmp/private_key_mallorca.txt
# recover keys
echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD keys import mallorca --keyring-backend test /tmp/private_key_mallorca.txt
user_address=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD keys show $NAME -a)
# get account and sequence number
account_number=$($ELYSD q account $user_address --node $NODE | extract_account_number)
sequence=$($ELYSD q account $user_address --node $NODE | extract_sequence)
echo "account_number: $account_number"
echo "sequence: $sequence"
# environment variables
OPTIONS="--from $NAME --node $NODE --chain-id ${{vars.CHAIN_ID}} --keyring-backend=test --gas auto --gas-adjustment 1.3 --fees 300000uelys -y --account-number $account_number -b async --log_level trace --trace"
##contracts
FS_CONTRACT_ADDRESS=${{vars.FS_CONTRACT_ADDRESS}}
TS_CONTRACT_ADDRESS=${{vars.TS_CONTRACT_ADDRESS}}
AH_CONTRACT_ADDRESS=${{vars.AH_CONTRACT_ADDRESS}}
printf "FS_CONTRACT_ADDRESS=%s\n" "$FS_CONTRACT_ADDRESS"
printf "TS_CONTRACT_ADDRESS=%s\n" "$TS_CONTRACT_ADDRESS"
printf "AH_CONTRACT_ADDRESS=%s\n" "$AH_CONTRACT_ADDRESS"
# store and init/migrate financial snapshot contract
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm store $OPTIONS --sequence $(($sequence + 1)) artifacts/financial_snapshot_contract.wasm | extract_txhash)
echo "fs store txhash: $txhash"
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id)
echo "fs code id: $codeid"
if [ "$FS_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$( echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 2)) $FS_CONTRACT_ADDRESS $codeid '{}' | extract_txhash)
echo "fs migrate txhash: $txhash"
else
txhash=$( echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 2)) --label "fs" --admin $NAME $codeid '{}' | extract_txhash)
echo "fs init txhash: $txhash"
fi
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
export fs_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address)
echo "fs_contract_address: $fs_contract_address"
# store and init/migrate trade shield contract
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm store $OPTIONS --sequence $(($sequence + 3)) artifacts/trade_shield_contract.wasm | extract_txhash)
echo "ts store txhash: $txhash"
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id)
echo "ts code id: $codeid"
if [ "$TS_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 4)) $TS_CONTRACT_ADDRESS $codeid '{
"account_history_address": "'"$AH_CONTRACT_ADDRESS"'"
}' | extract_txhash)
echo "ts migrate txhash: $txhash"
else
# set localnet AH deterministic address as param
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 4)) --label "ts" --admin $NAME $codeid '{
"account_history_address": "elys17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs98tvuy"
}' | extract_txhash)
echo "ts init txhash: $txhash"
fi
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
export ts_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address)
echo "ts_contract_address: $ts_contract_address"
# store and init/migrate account history contract
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm store artifacts/account_history_contract.wasm $OPTIONS --sequence $(($sequence + 5)) | extract_txhash)
echo "ah store txhash: $txhash"
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id)
echo "ah code id: $codeid"
if [ "$AH_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 6)) $AH_CONTRACT_ADDRESS $codeid '{
"trade_shield_address": "'"$TS_CONTRACT_ADDRESS"'",
"limit": 1
}' | extract_txhash)
echo "ah migrate txhash: $txhash"
else
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 6)) --label "ah" --admin $NAME $codeid '{
"limit": 300,
"expiration": {
"at_time": "604800000000000"
},
"trade_shield_address": "'"$ts_contract_address"'"
}' | extract_txhash)
echo "ah init txhash: $txhash"
fi
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
ah_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address)
echo "ah_contract_address: $ah_contract_address"
# print environment variables to set
printf "\nset those environment variables to use the contracts:\n\n"
printf "export NODE=%s\n" "$NODE"
printf "export NAME=%s\n" "$NAME"
printf "export FS_CONTRACT_ADDRESS=%s\n" "$fs_contract_address"
printf "export TS_CONTRACT_ADDRESS=%s\n" "$ts_contract_address"
printf "export AH_CONTRACT_ADDRESS=%s\n" "$ah_contract_address"