-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cosmwasm deployment workflow (#11)
* feat: add schema of cw-hub-bnusd * feat: add archway as submodule * feat: add cosmwasm-check as dev dependencies * feat: add scripts for common tasks * feat: add workflow to deploy wasm contracts * feat: remove cosmwasm-check from dev dependencies and install as a tool * feat: use 1.69.0 rust version * install wasm-opt and cw-check in ci * fix: add missing rust flags * update package versions * feat: add installation packages as components * feat: use correct container name * feat: separate out copy command * feat: use sh command to run the script * feat: move caching option to first step * feat: install wasm-opt using downloaded file
- Loading branch information
1 parent
30ba970
commit 08aae81
Showing
13 changed files
with
218 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: CW Contracts Test Deployment | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- contracts/** | ||
- .github/workflows/deploy-cw-contracts.yml | ||
jobs: | ||
Build: | ||
name: Build & Deploy CW Contracts | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- name: Start local Archway Blockchain | ||
run: | | ||
cd contracts/archway | ||
sed -i 's/latest/v0.4.0/' docker-compose.yaml | ||
docker compose -f docker-compose.yaml up -d | ||
# git clean submodule directory | ||
git checkout . | ||
git clean -fdx | ||
- name: Cache Rust dependencies | ||
uses: Swatinem/rust-cache@v2 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: 1.69.0 | ||
target: wasm32-unknown-unknown | ||
override: true | ||
profile: minimal | ||
|
||
- name: Install cw-check | ||
run: | | ||
cargo install cosmwasm-check | ||
- name: Compile WASM | ||
run: bash ./scripts/generate_wasm.sh | ||
|
||
- name: Check WASM Size | ||
run: | | ||
max_size=800 | ||
echo "Check if size of wasm file exceeds $max_size kilobytes..." | ||
for file in artifacts/*.wasm; do | ||
size=$(du -k "$file" | awk '{print $1}') | ||
if [[ $size -gt $max_size ]]; then | ||
echo "Error: $file : $size has exceeded maximum contract size limit of 800KB." | ||
exit 1 | ||
fi | ||
echo "$file : $size" | ||
done | ||
echo "The size of all contracts is well within the 800 KB limit." | ||
- name: Deploy WASM | ||
run: | | ||
container=$(docker ps --format '{{.Names}}') | ||
cp scripts/deploy_cw.sh contracts/archway/contracts | ||
cp -r artifacts contracts/archway/contracts | ||
docker exec $container chmod +x /contracts/deploy_cw.sh | ||
docker exec $container sh /contracts/deploy_cw.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "contracts/archway"] | ||
path = contracts/archway | ||
url = https://github.com/archway-network/archway.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
contracts/token-contracts/cw-hub-bnusd/schema/cw-hub-bnusd.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"contract_name": "cw-hub-bnusd", | ||
"contract_version": "0.1.0", | ||
"idl_version": "1.0.0", | ||
"instantiate": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "InstantiateMsg", | ||
"type": "object", | ||
"additionalProperties": false | ||
}, | ||
"execute": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "ExecuteMsg", | ||
"type": "string", | ||
"enum": [] | ||
}, | ||
"query": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "QueryMsg", | ||
"type": "string", | ||
"enum": [] | ||
}, | ||
"migrate": null, | ||
"sudo": null, | ||
"responses": {} | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/token-contracts/cw-hub-bnusd/schema/raw/execute.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "ExecuteMsg", | ||
"type": "string", | ||
"enum": [] | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/token-contracts/cw-hub-bnusd/schema/raw/instantiate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "InstantiateMsg", | ||
"type": "object", | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "QueryMsg", | ||
"type": "string", | ||
"enum": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
WALLET=fd # This account is default while running the chain on docker. | ||
### LOCALNET ### | ||
ENDPOINT=http://localhost:26657 | ||
CHAIN_ID=localnet | ||
TOKEN=stake | ||
|
||
deploy_wasm() { | ||
RES=$(archwayd tx wasm store "$CONTRACT_WASM" \ | ||
--keyring-backend test \ | ||
--from $WALLET \ | ||
--node $ENDPOINT \ | ||
--chain-id $CHAIN_ID \ | ||
--gas-prices 0.02$TOKEN \ | ||
--gas auto \ | ||
--gas-adjustment 1.3 -y \ | ||
--output json -b block) | ||
|
||
echo "Result: " | ||
echo "$RES" | ||
} | ||
|
||
# This wasm directory is inside the docker container | ||
for CONTRACT_WASM in /contracts/artifacts/*.wasm; do | ||
echo "=> Deploying $CONTRACT_WASM" | ||
deploy_wasm "$CONTRACT_WASM" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# install wasm-opt | ||
BINARYEN_VERS=110 | ||
BINARYEN_DWN="https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERS}/binaryen-version_${BINARYEN_VERS}-x86_64-linux.tar.gz" | ||
|
||
if ! which wasm-opt; then | ||
curl -OL $BINARYEN_DWN | ||
tar xf binaryen-version_${BINARYEN_VERS}-x86_64-linux.tar.gz | ||
export PATH=$PATH:$PWD/binaryen-version_${BINARYEN_VERS}/bin | ||
fi | ||
|
||
# Generate optimized wasm files and verify generated wasm with cosmwasm-check | ||
mkdir -p artifacts | ||
RUSTFLAGS='-C link-arg=-s' cargo wasm | ||
for WASM in ./target/wasm32-unknown-unknown/release/*.wasm; do | ||
NAME=$(basename "$WASM" .wasm)${SUFFIX}.wasm | ||
echo "########Creating intermediate hash for $NAME ...########" | ||
sha256sum -- "$WASM" | tee -a artifacts/checksums_intermediate.txt | ||
echo "########Optimizing $NAME ...########" | ||
wasm-opt -Oz "$WASM" -o "artifacts/$NAME" | ||
echo "########Verifying $NAME file with cosmwasm-check ...########" | ||
cosmwasm-check "artifacts/$NAME" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
cargo fmt --all | ||
#cargo clippy --fix | ||
source ./scripts/run_in_subprojects.sh ./contracts/token-contracts/cw-hub-bnusd | ||
cargo clean |