-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Levana-Protocol/initial-contract-code
Predictions markets: beginning of smart contracts
- Loading branch information
Showing
25 changed files
with
2,268 additions
and
0 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 @@ | ||
$0 !~ /(.*@levana\.exchange$)|(noreply@github\.com$)|(.*@users\.noreply\.github\.com$)/ { print "Invalid email found in your git commit: " $0; exit 1 } |
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,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" |
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,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" |
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,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 |
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 @@ | ||
wasm | ||
.envrc | ||
/source-tarballs/ |
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,2 @@ | ||
/target | ||
/schema |
Oops, something went wrong.