Skip to content

Commit

Permalink
Merge pull request #1 from Levana-Protocol/initial-contract-code
Browse files Browse the repository at this point in the history
Predictions markets: beginning of smart contracts
  • Loading branch information
lvn-hasky-dragon authored Sep 3, 2024
2 parents 9a866b4 + 05b4bb9 commit d37acf3
Show file tree
Hide file tree
Showing 25 changed files with 2,268 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci/commit-check.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$0 !~ /(.*@levana\.exchange$)|(noreply@github\.com$)|(.*@users\.noreply\.github\.com$)/ { print "Invalid email found in your git commit: " $0; exit 1 }
37 changes: 37 additions & 0 deletions .ci/contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -euxo pipefail

SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
cd "$SCRIPTPATH"
cd ..

WASM_DIR="$(pwd)/wasm"
TARGET_CACHE="$WASM_DIR/target"
REGISTRY_CACHE="$WASM_DIR/registry"
CARGO_GIT_CACHE="$WASM_DIR/git"
ARTIFACTS="$WASM_DIR/artifacts"

OPTIMIZER_VERSION="cosmwasm/rust-optimizer":0.15.1

mkdir -p "$TARGET_CACHE" "$REGISTRY_CACHE" "$ARTIFACTS" "$CARGO_GIT_CACHE"

# Delete the old file to avoid false positives if the compilation fails
rm -f "$WASM_DIR/artifacts/gitrev"

docker run --rm --tty \
-u "$(id -u)":"$(id -g)" \
-v "$(pwd)/contract":/code \
-v "$TARGET_CACHE":/target \
-v "$ARTIFACTS":/code/artifacts \
-v "$REGISTRY_CACHE":/usr/local/cargo/registry \
-v "$CARGO_GIT_CACHE":/usr/local/cargo/git \
$OPTIMIZER_VERSION

# not sure how this was created since we mapped the tool's /code/artifacts
# but it's empty (the real artifacts are in wasm/artifacts)
rm -rf ./artifacts

# Only write the gitrev file on success
git rev-parse HEAD > "$WASM_DIR/artifacts/gitrev"
39 changes: 39 additions & 0 deletions .ci/make-source-tarball.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -euxo pipefail

if [ -z ${1+x} ]
then
echo "Please provide a Git hash or other tree-ish"
exit 1
fi

rm -rf tmp
mkdir -p tmp
git archive -o tmp/source.tar "$1"

pushd tmp
tar xf source.tar
rm source.tar
popd

DIR=levana-predict-$1
rm -rf "$DIR"
mkdir -p "$DIR"

mv -i tmp/.ci/contracts.sh tmp/contract/build.sh
mv -i tmp/contract "$DIR"

rm -rf tmp

pushd "$DIR/contract"
cargo test
rm -rf target
./build.sh
popd

mkdir -p source-tarballs
cp "$DIR/wasm/artifacts/checksums.txt" "source-tarballs/$DIR-checksums.txt"
rm -rf "$DIR/wasm"
tar czfv "source-tarballs/$DIR.tar.gz" "$DIR"
rm -rf "$DIR"
56 changes: 56 additions & 0 deletions .github/workflows/contracts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Rust

on:
push:
branches: [develop,main]
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUST_BACKTRACE: short
RUSTUP_MAX_RETRIES: 10

jobs:
contracts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@v2
with:
tool: [email protected]
- name: Check commit
run: just check-commits
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.75.0
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
contract
- name: Cache contract builds
uses: actions/cache@v4
with:
key: contracts-${{ hashFiles('Cargo.toml') }}-${{hashFiles('Cargo.lock')}}
restore-keys: |
contracts-${{ hashFiles('Cargo.toml') }}
contracts
path: |
wasm
- name: Compile
run: just cargo-compile
- name: Run tests
run: just cargo-test
- name: Clippy
run: just cargo-clippy-check
working-directory: contract
- name: Rustfmt
run: just cargo-fmt-check
working-directory: contract
- name: Build contracts
run: just build-contracts
- name: Print contract sizes
run: ls -l wasm/artifacts/*.wasm
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wasm
.envrc
/source-tarballs/
2 changes: 2 additions & 0 deletions contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/schema
Loading

0 comments on commit d37acf3

Please sign in to comment.