Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
env:
SQLX_OFFLINE: true
SIMPLEX_COMMIT: 1945d11b47fff8838c3e99c210133519a9522324
SIMPLEX_VERSION: 0.0.7

steps:
- name: Checkout
Expand All @@ -45,14 +45,15 @@ jobs:
BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
SIMPLEX_DIR="${SIMPLEX_DIR:-$BASE_DIR/.simplex}"
SIMPLEX_BIN_DIR="$SIMPLEX_DIR/bin"
"$SIMPLEX_BIN_DIR/simplexup" --commit "$SIMPLEX_COMMIT"
"$SIMPLEX_BIN_DIR/simplexup" --install "$SIMPLEX_VERSION"
echo "$SIMPLEX_BIN_DIR" >> "$GITHUB_PATH"
"$SIMPLEX_BIN_DIR/simplex" --version

- name: Generate contract artifacts
shell: bash
run: |
cd crates/contracts
simplex install
simplex build
test -f src/artifacts/mod.rs

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
SQLX_VERSION: 0.8.0
SQLX_FEATURES: "rustls,postgres"
SQLX_FEATURES_KEY: "rustls-postgres"
SIMPLEX_COMMIT: 1945d11b47fff8838c3e99c210133519a9522324
SIMPLEX_VERSION: 0.0.7
APP_USER: app
APP_USER_PWD: secret
APP_DB_NAME: lending-indexer
Expand Down Expand Up @@ -84,14 +84,15 @@ jobs:
BASE_DIR="${XDG_CONFIG_HOME:-$HOME}"
SIMPLEX_DIR="${SIMPLEX_DIR:-$BASE_DIR/.simplex}"
SIMPLEX_BIN_DIR="$SIMPLEX_DIR/bin"
"$SIMPLEX_BIN_DIR/simplexup" --commit "$SIMPLEX_COMMIT"
"$SIMPLEX_BIN_DIR/simplexup" --install "$SIMPLEX_VERSION"
echo "$SIMPLEX_BIN_DIR" >> "$GITHUB_PATH"
"$SIMPLEX_BIN_DIR/simplex" --version

- name: Generate contract artifacts
shell: bash
run: |
cd crates/contracts
simplex install
simplex build
test -f src/artifacts/mod.rs

Expand Down
68 changes: 36 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ multiple_crate_versions = "allow"
[workspace.dependencies]
ring = "0.17.14"
hex = "0.4.3"
smplx-std = "0.0.5"
smplx-std = "0.0.7"
sha2 = { version = "0.10.9", features = ["compress"] }
serde = { version = "1.0.228", features = ["derive"]}
thiserror = { version = "2.0.18" }
Expand Down
3 changes: 2 additions & 1 deletion crates/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/artifacts
src/artifacts
deps/
14 changes: 12 additions & 2 deletions crates/contracts/Simplex.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@
# simf_files = ["*.simf"]
# out_dir = "./src/artifacts"

[dependencies]
std = { git = "https://github.com/BlockstreamResearch/simplicityhl-std.git" }

# [regtest]
# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean"
# bitcoins = 10_000_000
# rpc_port = 18443
# esplora_port = 3000
# rpc_user = "user"
# rpc_password = "password"

# [test]
# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean"
# bitcoins = 10_000_000
# verbosity = 0 # 0 - none, 1 - debug, 2 - trace

# [test.esplora]
# url = "<esplora url>"
# network = "<Liquid, LiquidTestnet, ElementsRegtest>"

#
# [test.rpc]
# url = "<rpc url>"
# username = "<rpc username>"
# password = "<rpc password>"
# password = "<rpc password>"
28 changes: 28 additions & 0 deletions crates/contracts/fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# WIP: early development, not intended for external use.

set -euo pipefail

SIMF_DIR="./simf"

usage() {
echo "usage: $(basename "$0") <file.simf> | all" >&2
exit 2
}

[[ $# -eq 1 ]] || usage

case "$1" in
all)
[[ -d "$SIMF_DIR" ]] || { echo "no such dir: $SIMF_DIR" >&2; exit 1; }
# NUL-delimited so filenames with spaces survive
find "$SIMF_DIR" -type f -name '*.simf' -print0 \
| xargs -0 -r -n1 simfmt
;;
*)
[[ -f "$1" ]] || { echo "no such file: $1" >&2; exit 1; }
[[ "$1" == *.simf ]] || echo "warning: $1 is not a .simf file" >&2
simfmt "$1"
;;
esac
35 changes: 13 additions & 22 deletions crates/contracts/simf/asset_auth.simf
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
fn get_asset_and_amount(index: u32, is_input_index: bool) -> (u256, u64) {
let pair: (Asset1, Amount1) = match is_input_index {
true => unwrap(jet::input_amount(index)),
false => unwrap(jet::output_amount(index)),
};
let (asset, amount): (Asset1, Amount1) = pair;
let asset_bits: u256 = unwrap_right::<(u1, u256)>(asset);
let amount: u64 = unwrap_right::<(u1, u256)>(amount);
(asset_bits, amount)
}
use std::lib::op_return::assert_output_is_op_return;

fn ensure_output_is_op_return(index: u32) {
match jet::output_null_datum(index, 0) {
Some(entry: Option<Either<(u2, u256), Either<u1, u4>>>) => (),
None => panic!(),
}
}
use crate::helper::get_explicit_asset_and_amount;

fn ensure_asset_and_amount_eq(index: u32, is_input_index: bool, expected_asset_bits: u256, expected_amount: u64) {
let (asset_bits, amount): (u256, u64) = get_asset_and_amount(index, is_input_index);
fn ensure_asset_and_amount_eq(
index: u32,
is_input_index: bool,
expected_asset_bits: u256,
expected_amount: u64
) {
let (asset_bits, amount): (u256, u64) = get_explicit_asset_and_amount(index, is_input_index);
assert!(jet::eq_256(asset_bits, expected_asset_bits));
assert!(jet::eq_64(amount, expected_amount));
}
Expand All @@ -27,13 +18,13 @@ fn auth_with_burn_check(input_asset_index: u32, output_asset_index: u32) {
ensure_asset_and_amount_eq(output_asset_index, false, param::ASSET_ID, param::ASSET_AMOUNT);

match param::WITH_ASSET_BURN {
true => {
ensure_output_is_op_return(output_asset_index);
},
false => {},
true => {
assert_output_is_op_return(output_asset_index);
}
}
}

fn main() {
auth_with_burn_check(witness::INPUT_ASSET_INDEX, witness::OUTPUT_ASSET_INDEX);
}
}
Loading
Loading