Skip to content
Merged
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
82 changes: 62 additions & 20 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,71 @@ on:
tags:
- "v*"

env:
SCARB_VERSION: 2.19.4
CRATES: origami_defi origami_hexmap origami_map origami_random origami_rating origami_security

jobs:
create-release:
release:
runs-on: ubuntu-latest

name: Package and create the GitHub release
permissions:
contents: write
steps:
- name: Extract version from tag
id: tag-version
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Check the tag against the crate versions
run: |
echo "::set-output name=version::${GITHUB_REF#refs/tags/v}"
tag="${GITHUB_REF_NAME#v}"
metadata=$(scarb metadata --format-version 1 --no-deps)
for crate in $CRATES; do
version=$(jq -r --arg name "$crate" '.packages[] | select(.name == $name) | .version' <<< "$metadata")
if [ "$version" != "$tag" ]; then
echo "::error::tag $GITHUB_REF_NAME does not match $crate version '$version'"
exit 1
fi
done
shell: bash
- name: Package
run: scarb package $(printf -- '-p %s ' $CRATES)
shell: bash
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --verify-tag --generate-notes --title "$GITHUB_REF_NAME" target/package/*.tar.zst
shell: bash

- name: Create GitHub Release
publish:
needs: release
runs-on: ubuntu-latest
name: Publish to scarbs.xyz
env:
# A secret cannot be tested in `if`: expose it as an env variable and test that instead.
# Without the secret every step is skipped and the job is a no-op.
SCARB_REGISTRY_AUTH_TOKEN: ${{ secrets.SCARB_REGISTRY_AUTH_TOKEN }}
steps:
- name: Registry token missing
if: ${{ env.SCARB_REGISTRY_AUTH_TOKEN == '' }}
run: echo "::notice::SCARB_REGISTRY_AUTH_TOKEN is not set, nothing published"
- uses: actions/checkout@v4
if: ${{ env.SCARB_REGISTRY_AUTH_TOKEN != '' }}
- uses: software-mansion/setup-scarb@v1
if: ${{ env.SCARB_REGISTRY_AUTH_TOKEN != '' }}
with:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Publish the versions not yet on the registry
if: ${{ env.SCARB_REGISTRY_AUTH_TOKEN != '' }}
run: |
curl -s \
-X POST \
-H "Authorization: token $GIT_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "v${{ steps.tag-version.outputs.version }}",
"name": "Release v${{ steps.tag-version.outputs.version }}",
"body": "Release of version ${{ steps.tag-version.outputs.version }}",
"draft": false,
"prerelease": false
}'
env:
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
version="${GITHUB_REF_NAME#v}"
for crate in $CRATES; do
# Index path of the registry: `{first two}/{next two}/{name}.json`
index="https://scarbs.xyz/api/v1/index/${crate:0:2}/${crate:2:2}/${crate}.json"
if curl -sf "$index" | jq -e --arg v "$version" 'any(.[]; .v == $v)' > /dev/null; then
echo "$crate $version is already on scarbs.xyz, skipped"
else
scarb publish -p "$crate"
fi
done
shell: bash
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ target
abis
manifests
.snfoundry_cache
.scratch
.p1
REPORT.md
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Changelog

All notable changes to the Origami crates. The six crates share one version.

## [1.8.0] - 2026-09-27

First release published on the [scarbs.xyz](https://scarbs.xyz) registry: `origami_defi`,
`origami_hexmap`, `origami_map`, `origami_random`, `origami_rating`, `origami_security`.

### Toolchain

- Scarb and Cairo 2.19.4 (from 2.12.2); `origami_hexmap` is tested with Starknet Foundry 0.61.0.
- Registry metadata on every crate (description, license, repository, homepage, documentation,
readme, keywords); versions and license inherited from the workspace and resolved in the
packages.
- Test-only files (integration tests; `origami_hexmap` benchmarks, printer and `GAS.md`) are kept
out of the packages with `.scarbignore`.
- Release workflow: on a `v*` tag, checks the tag against the crate versions, packages the six
crates and creates the GitHub release; publishes to scarbs.xyz the versions not yet there once
the `SCARB_REGISTRY_AUTH_TOKEN` secret is set.

### Removed

- `origami_algebra` (vectors and matrices) and its `cubit` dependency: use the
[`nalgebra`](https://scarbs.xyz/packages/nalgebra) or [`glam`](https://scarbs.xyz/packages/glam)
packages.

### Changed

- **`origami_defi`** runs on [`fixed`](https://scarbs.xyz/packages/fixed) 0.4.0 instead of
`cubit`: values are signed Q32.32 `fixed::Fixed` numbers, range `[-2^31, 2^31)`, resolution
`2^-32`. Only the inputs and the result have to fit: intermediate products are kept wide. The
domain limits of each function are documented (`# Domain`). Dependents add `fixed@0.4.0` to
build the values.

### Added

- **`origami_hexmap`**: hexagonal tile maps on a `felt252` bitmap (`W * H <= 251`), with the
`HexMap` facade that mirrors `origami_map::Map`:
- generators: `new_maze`, `new_cave`, `new_random_walk`, `new_hexagon`, `open_with_corridor`,
`open_with_maze`, `compute_distribution` (uniform), `keep_component`;
- finders: `search_path` (BFS), `distance_to`, `search_path_weighted` and
`field_of_movement` (up to 3 cost classes), `reachable`, `range`, `ring`, `hex_distance`,
`neighbor`, `is_walkable`;
- `u252`, an unsigned integer held in one `felt252`.
- Gas (snforge 0.61.0, sierra gas): the scenario cave + component + entrance + 10 objects +
path costs 1.14M on 17x14 (145.8M on `origami_map` 18x14, cairo-test estimate).
- Determinism: a seed gives the same map for a given version; the generators' streams are
part of the API from 1.8.0 on.
- `origami_defi`: `FixedStorePacking` (a `Fixed` stored as one `i64`).

### Fixed

- `origami_defi`: the fields of `DiscreteGDA` and `ContinuousGDA` are public, as those of
`LinearVRGDA` and `LogisticVRGDA`: the structs could not be built outside the crate.
- Every crate README example compiles against the current API (`tests/readme.cairo` in each
crate).

## [1.7.0]

Last release on git tags only (Scarb 2.12.2).
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,57 @@ It provides a set of powerful tools and libraries that enable game developers to

### Crates

- [Defi](./crates/defi/)
- [Hexmap](./crates/hexmap)
- [Map](./crates/map)
- Physics (WIP)
- [Random](./crates/random)
- [Rating](./crates/rating)
- [Security](./crates/security)
| Crate | Content |
|---|---|
| [`origami_defi`](./crates/defi) | Gradual Dutch auctions (discrete, continuous) and VRGDAs (linear, logistic) on `fixed` Q32.32 numbers |
| [`origami_hexmap`](./crates/hexmap) | Hexagonal tile maps: generators, BFS and weighted search, ranges and rings, bit-parallel on one `felt252` |
| [`origami_map`](./crates/map) | Square tile maps: maze, cave and random walk generators, A\*, BFS, DFS, Dijkstra and greedy finders |
| [`origami_random`](./crates/random) | Dice and card decks from a seed |
| [`origami_rating`](./crates/rating) | Elo rating |
| [`origami_security`](./crates/security) | Commit-reveal commitments |

### Easy integration into your project
### Installation

Incorporate `origami` seamlessly into your projects using Scarb.toml.
Toolchain: [Scarb](https://docs.swmansion.com/scarb) 2.19.4 (Cairo 2.19.4); `origami_hexmap` is
tested with [Starknet Foundry](https://foundry-rs.github.io/starknet-foundry) 0.61.0.

From the [scarbs.xyz](https://scarbs.xyz) registry:
From the [scarbs.xyz](https://scarbs.xyz) registry, one crate at a time:

```sh
scarb add origami_defi@1.8.0
scarb add origami_hexmap@1.8.0
scarb add origami_map@1.8.0
scarb add origami_random@1.8.0
scarb add origami_rating@1.8.0
scarb add origami_security@1.8.0
```

`origami_defi` takes and returns `fixed::Fixed` values: add `scarb add fixed@0.4.0` as well.

Or from git, in your `[dependencies]`:

```toml
[dependencies]
origami_random = { git = "https://github.com/dojoengine/origami", tag = "v1.8.0" }
origami_hexmap = { git = "https://github.com/dojoengine/origami", tag = "v1.8.0" }
origami_map = { git = "https://github.com/dojoengine/origami", tag = "v1.8.0" }
```

For linear algebra, use the [`nalgebra`](https://scarbs.xyz/packages/nalgebra) and [`glam`](https://scarbs.xyz/packages/glam) packages on scarbs.xyz.

### What's new in 1.8.0

- **Toolchain.** Scarb and Cairo 2.19.4 (from 2.12.2). The crates are published on scarbs.xyz
for the first time.
- **`origami_algebra` removed**, with its `cubit` dependency: use `nalgebra` or `glam`.
- **`origami_defi` on [`fixed`](https://scarbs.xyz/packages/fixed)** 0.4.0: signed Q32.32
numbers, range `[-2^31, 2^31)`, resolution `2^-32`; intermediate products are kept wide.
- **New `origami_hexmap`**: hexagonal maps where every operation works on the whole board at
once. Measured with snforge 0.61.0 (sierra gas, see
[`GAS.md`](./crates/hexmap/GAS.md)): a 17x14 cave, its connected component, an entrance,
10 objects and a 15-step path cost 1.14M gas, against 145.8M for the same scenario on
`origami_map` 18x14 (cairo-test estimate); `search_path` across a 17x14 cave (24 steps) 706k, `new_cave` 142k.

See [CHANGELOG.md](./CHANGELOG.md) for the details.

Now you will be able to use origami like any other Cairo package!

### 🏗️ Join Our Contributors
Expand Down
3 changes: 3 additions & 0 deletions crates/defi/.scarbignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kept out of the published package (`scarb package`), still in the repository.
# Integration tests (README examples).
/tests/
10 changes: 9 additions & 1 deletion crates/defi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ let price = gda.purchase_price(time_since_last, quantity);

These examples demonstrate how to create instances of the `DiscreteGDA` and `ContinuousGDA` structures, and how to utilize their `purchase_price` methods to calculate the price for purchasing specific quantities at given times.

You'll need the `fixed` package in your project to build the `Fixed` values: `use fixed::{FixedTrait, ONE};`.
The imports of these examples (the `fixed` package builds the `Fixed` values):

```rust
use fixed::{FixedTrait, ONE};
use origami_defi::auction::gda::{ContinuousGDA, ContinuousGDATrait, DiscreteGDA, DiscreteGDATrait};
```

## Conclusion

Expand Down Expand Up @@ -169,8 +174,11 @@ Make sure to import the required dependencies at the beginning of your Cairo fil

```rust
use fixed::{Fixed, FixedTrait};
use origami_defi::auction::vrgda::{LinearVRGDA, LogisticVRGDA, VRGDATargetTimeTrait, VRGDATrait};
```

Every example of this README is compiled by `tests/readme.cairo`.

These examples show you how to create instances of both `LinearVRGDA` and `LogisticVRGDA` and how to use their methods to calculate the target sale time and VRGDA price.

## Conclusion
Expand Down
14 changes: 7 additions & 7 deletions crates/defi/src/auction/gda.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use super::helpers::{FixedStorePacking, mul_div};
/// the auction has started.
#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct DiscreteGDA {
sold: Fixed,
initial_price: Fixed,
scale_factor: Fixed,
decay_constant: Fixed,
pub sold: Fixed,
pub initial_price: Fixed,
pub scale_factor: Fixed,
pub decay_constant: Fixed,
}

#[generate_trait]
Expand Down Expand Up @@ -70,9 +70,9 @@ pub impl DiscreteGDAImpl of DiscreteGDATrait {
/// emission rate, decay constant, and the time since the last purchase in days.
#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct ContinuousGDA {
initial_price: Fixed,
emission_rate: Fixed,
decay_constant: Fixed,
pub initial_price: Fixed,
pub emission_rate: Fixed,
pub decay_constant: Fixed,
}

#[generate_trait]
Expand Down
63 changes: 63 additions & 0 deletions crates/defi/tests/readme.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! The examples of `README.md`, compiled against the public API.

use fixed::{Fixed, FixedTrait, ONE};
use origami_defi::auction::gda::{ContinuousGDA, ContinuousGDATrait, DiscreteGDA, DiscreteGDATrait};
use origami_defi::auction::vrgda::{LinearVRGDA, LogisticVRGDA, VRGDATargetTimeTrait, VRGDATrait};

#[test]
fn test_readme_discrete_gda() {
let gda = DiscreteGDA {
sold: FixedTrait::from_int(0),
initial_price: FixedTrait::from_int(100),
scale_factor: FixedTrait::from_ratio(11, 10), // 1.1
decay_constant: FixedTrait::from_ratio(1, 2) // 0.5
};
let time_since_start = FixedTrait::from_int(2); // 2 days since the start
let quantity = FixedTrait::from_int(5); // Quantity to purchase
let price = gda.purchase_price(time_since_start, quantity);
assert!(price > FixedTrait::from_int(0));
}

#[test]
fn test_readme_continuous_gda() {
let gda = ContinuousGDA {
initial_price: FixedTrait::from_int(1000),
emission_rate: ONE,
decay_constant: FixedTrait::from_ratio(1, 2),
};
let time_since_last = FixedTrait::from_int(1); // 1 day since the last purchase
let quantity = FixedTrait::from_int(3); // Quantity to purchase
let price = gda.purchase_price(time_since_last, quantity);
assert!(price > FixedTrait::from_int(0));
}

#[test]
fn test_readme_linear_vrgda() {
let auction = LinearVRGDA {
target_price: FixedTrait::from_ratio(6942, 100), // 69.42
decay_constant: FixedTrait::from_ratio(31, 100), // 0.31
target_units_per_time: FixedTrait::from_int(2),
};
let sold_quantity: Fixed = FixedTrait::from_int(10);
let time_since_start: Fixed = FixedTrait::from_int(5);
let target_sale_time = auction.get_target_sale_time(sold_quantity);
let price = auction.get_vrgda_price(time_since_start, sold_quantity);
assert!(target_sale_time == FixedTrait::from_int(5));
assert!(price > FixedTrait::from_int(0));
}

#[test]
fn test_readme_logistic_vrgda() {
let auction = LogisticVRGDA {
target_price: FixedTrait::from_ratio(6942, 100), // 69.42
decay_constant: FixedTrait::from_ratio(31, 100), // 0.31
max_sellable: FixedTrait::from_int(6392),
time_scale: FixedTrait::from_ratio(23, 10000) // 0.0023
};
let sold_quantity: Fixed = FixedTrait::from_int(10);
let time_since_start: Fixed = FixedTrait::from_int(5);
let target_sale_time = auction.get_target_sale_time(sold_quantity);
let price = auction.get_vrgda_price(time_since_start, sold_quantity);
assert!(target_sale_time > FixedTrait::from_int(0));
assert!(price > FixedTrait::from_int(0));
}
10 changes: 10 additions & 0 deletions crates/hexmap/.scarbignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Kept out of the published package (`scarb package`), still in the repository.
# Integration tests (README examples).
/tests/
# Test-only modules: declared under `#[cfg(test)]` in `src/lib.cairo`, set for this package's own
# tests only (not `#[cfg(target: "test")]`, which scarb also sets when a dependent runs its
# tests), so the verification build and dependents compile without them.
/src/tests/
/src/helpers/printer.cairo
# Measurements, linked from the README on GitHub.
/GAS.md
Loading
Loading