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
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
pull_request:

env:
DOJO_VERSION: v1.0.1
SCARB_VERSION: 2.8.4
DOJO_VERSION: v1.1.2
SCARB_VERSION: 2.9.2

jobs:
check:
Expand Down Expand Up @@ -40,6 +40,9 @@ jobs:
name: Test origami_algebra
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_algebra
Expand All @@ -51,6 +54,9 @@ jobs:
name: Test origami_defi
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_defi
Expand All @@ -62,6 +68,9 @@ jobs:
name: Test origami_map
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_map
Expand All @@ -73,6 +82,9 @@ jobs:
name: Test origami_random
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_random
Expand All @@ -84,6 +96,9 @@ jobs:
name: Test origami_rating
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_rating
Expand All @@ -95,6 +110,9 @@ jobs:
name: Test origami_security
steps:
- uses: actions/checkout@v4
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: ${{ env.SCARB_VERSION }}
- uses: ./.github/actions/setup
- name: Test
run: sozo test --package origami_security
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.8.4
scarb 2.9.2
14 changes: 7 additions & 7 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ version = 1
[[package]]
name = "cubit"
version = "1.3.0"
source = "git+https://github.com/bal7hazar/cubit?branch=cairo-2.8.4#6bce623d5c735c097be47a4045c0e0432bad38e7"
source = "git+https://github.com/bengineer42/cubit?branch=bump-cairo-gt-2.8#32a20af893b3e26e6f5cf436c509457d6500ca5c"

[[package]]
name = "origami_algebra"
version = "1.0.0-rc.2"
version = "1.1.2"
dependencies = [
"cubit",
]

[[package]]
name = "origami_defi"
version = "1.0.0-rc.2"
version = "1.1.2"
dependencies = [
"cubit",
]

[[package]]
name = "origami_map"
version = "1.0.0-rc.2"
version = "1.1.2"

[[package]]
name = "origami_random"
version = "1.0.0-rc.2"
version = "1.1.2"

[[package]]
name = "origami_rating"
version = "1.0.0-rc.2"
version = "1.1.2"

[[package]]
name = "origami_security"
version = "1.0.0-rc.2"
version = "1.1.2"
12 changes: 6 additions & 6 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ members = [
]

[workspace.package]
version = "1.0.0-rc.2"
version = "1.1.2"
edition = "2024_07"

[workspace.dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.1" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.1.2" }
# dojo = { path = "../dojo/crates/dojo-core" }
cubit = { git = "https://github.com/bal7hazar/cubit", branch = "cairo-2.8.4" }
starknet = "^2.8.4"
cairo_test = "^2.8.4"
# Scripts are not supported for virtual workspaces.
cubit = { git = "https://github.com/bengineer42/cubit", branch = "bump-cairo-gt-2.8" }
starknet = "^2.9.2"
cairo_test = "^2.9.2"
2 changes: 2 additions & 0 deletions crates/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[package]
name = "origami"
version.workspace = true
edition.workspace = true
authors.workspace = true
description.workspace = true
homepage = "https://github.com/dojoengine/origami/tree/main/crates"

[dependencies]
cubit.workspace = true
dojo.workspace = true
cairo_test.workspace = true
2 changes: 2 additions & 0 deletions crates/algebra/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "origami_algebra"
version.workspace = true
edition.workspace = true
description = "Algebra library for Dojo based games."
homepage = "https://github.com/dojoengine/origami/tree/main/crates/algebra"

Expand All @@ -9,3 +10,4 @@ homepage = "https://github.com/dojoengine/origami/tree/main/crates/algebra"

[dependencies]
cubit.workspace = true
cairo_test.workspace = true
43 changes: 10 additions & 33 deletions crates/algebra/src/matrix.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zeroable::Zeroable;
use core::num::traits::Zero;
use core::ops::{AddAssign, SubAssign};


Expand All @@ -10,9 +10,9 @@ struct Matrix<T> {
}

mod errors {
const INVALID_INDEX: felt252 = 'Matrix: index out of bounds';
const INVALID_DIMENSION: felt252 = 'Matrix: invalid dimension';
const INVALID_MATRIX_INVERSION: felt252 = 'Matrix: matrix not invertible';
pub const INVALID_INDEX: felt252 = 'Matrix: index out of bounds';
pub const INVALID_DIMENSION: felt252 = 'Matrix: invalid dimension';
pub const INVALID_MATRIX_INVERSION: felt252 = 'Matrix: matrix not invertible';
}

trait MatrixTrait<T> {
Expand All @@ -38,7 +38,7 @@ impl MatrixImpl<
+Sub<T>,
+SubAssign<T, T>,
+Neg<T>,
+Zeroable<T>,
+Zero<T>,
+Copy<T>,
+Drop<T>,
> of MatrixTrait<T> {
Expand Down Expand Up @@ -102,7 +102,7 @@ impl MatrixImpl<
return (self.get(0, 0) * self.get(1, 1)) - (self.get(0, 1) * self.get(1, 0));
}

let mut det: T = Zeroable::zero();
let mut det: T = Zero::zero();
let mut col: u8 = 0;
loop {
if col >= self.cols {
Expand Down Expand Up @@ -166,7 +166,7 @@ impl MatrixAdd<
+Sub<T>,
+SubAssign<T, T>,
+Neg<T>,
+Zeroable<T>,
+Zero<T>,
+Copy<T>,
+Drop<T>,
> of Add<Matrix<T>> {
Expand Down Expand Up @@ -198,7 +198,7 @@ impl MatrixSub<
+Sub<T>,
+SubAssign<T, T>,
+Neg<T>,
+Zeroable<T>,
+Zero<T>,
+Copy<T>,
+Drop<T>,
> of Sub<Matrix<T>> {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl MatrixMul<
+Sub<T>,
+SubAssign<T, T>,
+Neg<T>,
+Zeroable<T>,
+Zero<T>,
+Copy<T>,
+Drop<T>,
> of Mul<Matrix<T>> {
Expand All @@ -248,7 +248,7 @@ impl MatrixMul<
let row = index / rhs.cols;
let col = index % rhs.cols;

let mut sum: T = Zeroable::zero();
let mut sum: T = Zero::zero();
let mut k: u8 = 0;
loop {
if k == lhs.cols {
Expand All @@ -268,30 +268,7 @@ impl MatrixMul<

#[cfg(test)]
mod tests {
use core::traits::TryInto;
use super::{Matrix, MatrixTrait};
use debug::PrintTrait;

impl I128Zeroable of Zeroable<i128> {
fn zero() -> i128 {
0
}
fn is_zero(self: i128) -> bool {
self == 0
}
fn is_non_zero(self: i128) -> bool {
self != 0
}
}

// impl I128Div of Div<i128> {
// fn div(lhs: i128, rhs: i128) -> i128 {
// let lhs_u256: u256 = Into::<felt252, u256>::into(lhs.into());
// let rhs_u256: u256 = Into::<felt252, u256>::into(rhs.into());
// let div: felt252 = (lhs_u256 / rhs_u256).try_into().unwrap();
// div.try_into().unwrap()
// }
// }

#[test]
fn test_matrix_get() {
Expand Down
12 changes: 6 additions & 6 deletions crates/algebra/src/vec2.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cubit::f128::types::fixed::{Fixed, FixedTrait, ONE_u128};
use cubit::f128::types::fixed::{FixedTrait, ONE_u128};

struct Vec2<T> {
x: T,
y: T
y: T,
}

impl Vec2Copy<T, impl TCopy: Copy<T>> of Copy<Vec2<T>>;
Expand Down 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
31 changes: 7 additions & 24 deletions crates/algebra/src/vector.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use core::ops::AddAssign;
use core::num::traits::Zero;

#[derive(Copy, Drop)]
struct Vector<T> {
data: Span<T>,
}

mod errors {
const INVALID_INDEX: felt252 = 'Vector: index out of bounds';
const INVALID_SIZE: felt252 = 'Vector: invalid size';
pub const INVALID_INDEX: felt252 = 'Vector: index out of bounds';
pub const INVALID_SIZE: felt252 = 'Vector: invalid size';
}

trait VectorTrait<T> {
Expand All @@ -20,7 +21,7 @@ trait VectorTrait<T> {
fn dot(self: Vector<T>, vector: Vector<T>) -> T;
}

impl VectorImpl<T, +Mul<T>, +AddAssign<T, T>, +Zeroable<T>, +Copy<T>, +Drop<T>,> of VectorTrait<T> {
impl VectorImpl<T, +Mul<T>, +AddAssign<T, T>, +Zero<T>, +Copy<T>, +Drop<T>> of VectorTrait<T> {
fn new(data: Span<T>) -> Vector<T> {
Vector { data }
}
Expand All @@ -37,7 +38,7 @@ impl VectorImpl<T, +Mul<T>, +AddAssign<T, T>, +Zeroable<T>, +Copy<T>, +Drop<T>,>
// [Check] Dimesions are compatible
assert(self.size() == vector.size(), errors::INVALID_SIZE);
// [Compute] Dot product in a loop
let mut value = Zeroable::zero();
let mut value = Zero::zero();
loop {
match self.data.pop_front() {
Option::Some(x_value) => {
Expand All @@ -51,7 +52,7 @@ impl VectorImpl<T, +Mul<T>, +AddAssign<T, T>, +Zeroable<T>, +Copy<T>, +Drop<T>,>
}

impl VectorAdd<
T, +Mul<T>, +AddAssign<T, T>, +Add<T>, +Zeroable<T>, +Copy<T>, +Drop<T>,
T, +Mul<T>, +AddAssign<T, T>, +Add<T>, +Zero<T>, +Copy<T>, +Drop<T>,
> of Add<Vector<T>> {
fn add(mut lhs: Vector<T>, mut rhs: Vector<T>) -> Vector<T> {
// [Check] Dimesions are compatible
Expand All @@ -71,7 +72,7 @@ impl VectorAdd<
}

impl VectorSub<
T, +Mul<T>, +AddAssign<T, T>, +Sub<T>, +Zeroable<T>, +Copy<T>, +Drop<T>,
T, +Mul<T>, +AddAssign<T, T>, +Sub<T>, +Zero<T>, +Copy<T>, +Drop<T>,
> of Sub<Vector<T>> {
fn sub(mut lhs: Vector<T>, mut rhs: Vector<T>) -> Vector<T> {
// [Check] Dimesions are compatible
Expand All @@ -92,26 +93,8 @@ impl VectorSub<

#[cfg(test)]
mod tests {
// Core imports

use debug::PrintTrait;

// Local imports

use super::{Vector, VectorTrait};

impl I128Zeroable of Zeroable<i128> {
fn zero() -> i128 {
0
}
fn is_zero(self: i128) -> bool {
self == 0
}
fn is_non_zero(self: i128) -> bool {
self != 0
}
}

#[test]
fn test_vector_get() {
let mut vector: Vector = VectorTrait::new(array![1, 2, 3, 4].span());
Expand Down
3 changes: 2 additions & 1 deletion crates/defi/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[package]
name = "origami_defi"
version.workspace = true
edition.workspace = true
description = "DeFi library for Dojo based games."
homepage = "https://github.com/dojoengine/origami/tree/main/crates/defi"
edition = "2024_07"

[dependencies]
cubit.workspace = true
starknet.workspace = true
cairo_test.workspace = true
Loading