Skip to content

Commit

Permalink
Merge pull request #2 from Bal7hazar/feat/add-presets-and-examples
Browse files Browse the repository at this point in the history
✨ Introduce examples
  • Loading branch information
ponderingdemocritus authored Nov 6, 2023
2 parents f0cac62 + af37f02 commit db706b5
Show file tree
Hide file tree
Showing 41 changed files with 7,014 additions and 20 deletions.
38 changes: 34 additions & 4 deletions .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Test
name: Origami CI

on: [push, pull_request]

env:
DOJO_VERSION: v0.3.3
DOJO_VERSION: v0.3.4
SCARB_VERSION: v2.3.1

jobs:
check:
Expand All @@ -12,11 +13,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- name: Format
run: scarb fmt --package random --check
run: scarb fmt --check
shell: bash

build:
needs: check
runs-on: ubuntu-latest
name: Build package
steps:
Expand All @@ -25,8 +29,9 @@ jobs:
- name: Build
run: sozo build
shell: bash

algebra:
needs: [check, build]
runs-on: ubuntu-latest
name: Test algebra crate
steps:
Expand All @@ -37,6 +42,7 @@ jobs:
shell: bash

defi:
needs: [check, build]
runs-on: ubuntu-latest
name: Test defi crate
steps:
Expand All @@ -47,6 +53,7 @@ jobs:
shell: bash

random:
needs: [check, build]
runs-on: ubuntu-latest
name: Test random crate
steps:
Expand All @@ -57,11 +64,34 @@ jobs:
shell: bash

security:
needs: [check, build]
runs-on: ubuntu-latest
name: Test security crate
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Test
run: sozo test -f security
shell: bash

market:
needs: [check, build]
runs-on: ubuntu-latest
name: Test market example
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Test
run: sozo test -f market
shell: bash

projectile:
needs: [check, build]
runs-on: ubuntu-latest
name: Test projectile example
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Test
run: sozo test -f projectile
shell: bash
22 changes: 19 additions & 3 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,31 @@ dependencies = [

[[package]]
name = "dojo"
version = "0.3.3"
source = "git+https://github.com/dojoengine/dojo.git?tag=v0.3.3#3c9f109e667ca5d12739e6553fdb8261378f4ecf"
version = "0.3.4"
source = "git+https://github.com/dojoengine/dojo.git?tag=v0.3.4#a3140d88b08b79c5ff2261c1db81bafe80b5cc91"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.3"
version = "0.3.4"

[[package]]
name = "market"
version = "0.0.0"
dependencies = [
"cubit",
"dojo",
]

[[package]]
name = "projectile"
version = "0.0.0"
dependencies = [
"algebra",
"cubit",
]

[[package]]
name = "random"
Expand Down
8 changes: 3 additions & 5 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ version = "0.0.0"
description = "Community-maintained libraries for Cairo"
homepage = "https://github.com/dojoengine/origami"
members = [
"crates/algebra",
"crates/defi",
"crates/random",
"crates/security",
"crates/*",
"examples/*",
]

[workspace.dependencies]
dojo = { git = "https://github.com/dojoengine/dojo.git", tag = "v0.3.3" }
dojo = { git = "https://github.com/dojoengine/dojo.git", tag = "v0.3.4" }
2 changes: 1 addition & 1 deletion crates/algebra/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod vec2;
mod vector;
mod matrix;
mod matrix;
2 changes: 1 addition & 1 deletion crates/algebra/src/matrix.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,4 @@ mod tests {
assert(inverse.get(2, 1) == -1, 'Matrix: inversion failed');
assert(inverse.get(2, 2) == 1, 'Matrix: inversion failed');
}
}
}
10 changes: 5 additions & 5 deletions crates/algebra/src/vec2.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ impl Vec2Impl<T, impl TCopy: Copy<T>, impl TDrop: Drop<T>> of Vec2Trait<T> {
/// Vec2<T> -> Vec2<T>
#[inline(always)]
fn xx(self: Vec2<T>) -> Vec2<T> {
Vec2 { x: self.x, y: self.x, }
Vec2 { x: self.x, y: self.x, }
}

#[inline(always)]
fn xy(self: Vec2<T>) -> Vec2<T> {
Vec2 { x: self.x, y: self.y, }
Vec2 { x: self.x, y: self.y, }
}

#[inline(always)]
fn yx(self: Vec2<T>) -> Vec2<T> {
Vec2 { x: self.y, y: self.x, }
Vec2 { x: self.y, y: self.x, }
}

#[inline(always)]
fn yy(self: Vec2<T>) -> Vec2<T> {
Vec2 { x: self.y, y: self.y, }
Vec2 { x: self.y, y: self.y, }
}
}

Expand Down Expand Up @@ -266,4 +266,4 @@ mod tests {
assert(vec2yy.y.mag == 2 * ONE_u128, 'invalid y.mag');
assert(vec2yy.y.sign == true, 'invalid y.sign');
}
}
}
2 changes: 1 addition & 1 deletion crates/algebra/src/vector.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ mod tests {
let result = vector1.dot(vector2);
assert(result == 32, 'Vector: dot product failed'); // 1*4 + 2*5 + 3*6 = 32
}
}
}
1 change: 1 addition & 0 deletions examples/market/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
27 changes: 27 additions & 0 deletions examples/market/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "cubit"
version = "1.2.0"
source = "git+https://github.com/influenceth/cubit?rev=b459053#b4590530d5aeae9aabd36740cc2a3d9e6adc5fde"

[[package]]
name = "dojo"
version = "0.3.3"
source = "git+https://github.com/dojoengine/dojo.git?tag=v0.3.3#3c9f109e667ca5d12739e6553fdb8261378f4ecf"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.3"

[[package]]
name = "market"
version = "0.0.0"
dependencies = [
"cubit",
"dojo",
]
9 changes: 9 additions & 0 deletions examples/market/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "market"
version = "0.0.0"
description = "Example of defi crate usage."
homepage = "https://github.com/dojoengine/origami/tree/examples/market"

[dependencies]
cubit = { git = "https://github.com/influenceth/cubit", rev = "b459053" }
dojo.workspace = true
17 changes: 17 additions & 0 deletions examples/market/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod models {
mod cash;
mod item;
mod liquidity;
mod market;
}

mod systems {
mod liquidity;
mod trade;
}

#[cfg(test)]
mod tests {
mod setup;
mod trade;
}
10 changes: 10 additions & 0 deletions examples/market/src/models/cash.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Starknet imports

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
struct Cash {
#[key]
player: ContractAddress,
amount: u128,
}
12 changes: 12 additions & 0 deletions examples/market/src/models/item.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Starknet imports

use starknet::ContractAddress;

#[derive(Model, Copy, Drop, Serde)]
struct Item {
#[key]
player: ContractAddress,
#[key]
item_id: u32,
quantity: u128,
}
56 changes: 56 additions & 0 deletions examples/market/src/models/liquidity.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Starknet imports

use starknet::ContractAddress;

// Dojo imports

use dojo::database::schema::{Struct, Ty, SchemaIntrospection, Member, serialize_member};

// External imports

use cubit::f128::types::fixed::Fixed;

// Constants

const SCALING_FACTOR: u128 = 10000;

impl SchemaIntrospectionFixed of SchemaIntrospection<Fixed> {
#[inline(always)]
fn size() -> usize {
2
}

#[inline(always)]
fn layout(ref layout: Array<u8>) {
layout.append(128);
layout.append(1);
}

#[inline(always)]
fn ty() -> Ty {
Ty::Struct(
Struct {
name: 'Fixed',
attrs: array![].span(),
children: array![
serialize_member(
@Member { name: 'mag', ty: Ty::Primitive('u128'), attrs: array![].span() }
),
serialize_member(
@Member { name: 'sign', ty: Ty::Primitive('bool'), attrs: array![].span() }
)
]
.span()
}
)
}
}

#[derive(Model, Copy, Drop, Serde)]
struct Liquidity {
#[key]
player: ContractAddress,
#[key]
item_id: u32,
shares: Fixed,
}
Loading

0 comments on commit db706b5

Please sign in to comment.