Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Jul 24, 2024
1 parent 4bb65b8 commit 194035a
Show file tree
Hide file tree
Showing 207 changed files with 212 additions and 6,786 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 2.7.0-rc.4
66 changes: 20 additions & 46 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -1,83 +1,57 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "chess"
version = "0.6.0-alpha.6"
dependencies = [
"dojo",
]

[[package]]
name = "cubit"
version = "1.3.0"
source = "git+https://github.com/notV4l/cubit.git?branch=cairo_2.7#cadb27aa62509ad9059dfac4f075317893f1f614"
source = "git+https://github.com/dojoengine/cubit?branch=cairo_2.7#53020b6320a10f2ab55b661be9b8d895aca945e9"

[[package]]
name = "dojo"
version = "0.7.2"
source = "git+https://github.com/dojoengine/dojo?tag=v0.7.2#3da5cad9fdd39b81551e0668015d88262e6c5fc4"
version = "0.7.3"
source = "git+https://github.com/dojoengine/dojo?rev=a35ddcb#a35ddcb37a7c6499ca0720b0dccd739e400031c2"
dependencies = [
"dojo_plugin",
]

[[package]]
name = "dojo_plugin"
version = "0.3.11"
source = "git+https://github.com/dojoengine/dojo?tag=v0.3.11#1e651b5d4d3b79b14a7d8aa29a92062fcb9e6659"
version = "0.7.3"
source = "git+https://github.com/dojoengine/dojo?rev=d90b52b#d90b52b89749ac8af82f352dc08aa0b1378cfae6"

[[package]]
name = "governance"
version = "0.0.0"
name = "origami_algebra"
version = "0.1.0"
dependencies = [
"dojo",
"cubit",
]

[[package]]
name = "hex_map"
version = "0.0.0"
name = "origami_defi"
version = "0.1.0"
dependencies = [
"cubit",
"dojo",
"origami",
]

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

[[package]]
name = "matchmaker"
version = "0.0.0"
dependencies = [
"dojo",
"origami",
]
name = "origami_random"
version = "0.1.0"

[[package]]
name = "origami"
version = "0.7.2"
dependencies = [
"cubit",
"dojo",
]
name = "origami_rating"
version = "0.1.0"

[[package]]
name = "projectile"
version = "0.0.0"
dependencies = [
"cubit",
"dojo",
"origami",
]
name = "origami_security"
version = "0.1.0"

[[package]]
name = "token"
version = "0.0.0"
name = "origami_token"
version = "1.0.0-alpha.0"
dependencies = [
"dojo",
]
35 changes: 16 additions & 19 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
[workspace]
members = [
"crates",
"examples/chess",
"examples/hex_map",
"examples/market",
"examples/matchmaker",
"examples/projectile",
"token",
"governance"
]
# Scarb dependent crates.
"crates/algebra",
"crates/defi",
"crates/map",
"crates/random",
"crates/rating",
"crates/security",

[workspace.package]
version = "0.7.2"
description = "Community-maintained libraries for Cairo"
homepage = "https://github.com/dojoengine/origami"
authors = ["[email protected]"]
# Sozo dependent crates.
"crates/token",
# "governance"
]

[workspace.dependencies]
# cubit = { git = "https://github.com/influenceth/cubit.git" }
cubit = { git = "https://github.com/notV4l/cubit.git", branch = "cairo_2.7" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.7.2" }
origami = { path = "crates" }
token = { path = "token" }
cubit = { git = "https://github.com/dojoengine/cubit", branch = "cairo_2.7" }
dojo = { git = "https://github.com/dojoengine/dojo", rev = "a35ddcb" }
starknet = "2.7.0-rc.3"

# Scripts are not supported for virtual workspaces.
11 changes: 11 additions & 0 deletions crates/algebra/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "origami_algebra"
version = "0.1.0"
description = "Algebra library for Dojo based games."
homepage = "https://github.com/dojoengine/origami/tree/main/crates/algebra"

# TODO: update to edition 2024_07, some traits are deprecated and others no longer accessible.
# Mostly related to `AddEq` -> `AddAssign` and so on.

[dependencies]
cubit.workspace = true
3 changes: 3 additions & 0 deletions crates/algebra/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod vec2;
mod vector;
mod matrix;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions crates/defi/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "origami_defi"
version = "0.1.0"
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ use cubit::f128::types::fixed::{Fixed, FixedTrait};
/// The purchase price for a given quantity is calculated based on
/// the initial price, scale factor, decay constant, and the time since
/// the auction has started.
#[derive(Copy, Drop, Serde, starknet::Storage)]
struct DiscreteGDA {
#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct DiscreteGDA {
sold: Fixed,
initial_price: Fixed,
scale_factor: Fixed,
decay_constant: Fixed,
}

#[generate_trait]
impl DiscreteGDAImpl of DiscreteGDATrait {
pub impl DiscreteGDAImpl of DiscreteGDATrait {
/// Calculates the purchase price for a given quantity of the item at a specific time.
///
/// # Arguments
Expand All @@ -39,15 +39,15 @@ impl DiscreteGDAImpl of DiscreteGDATrait {
/// A Gradual Dutch Auction represented using continuous time steps.
/// The purchase price is calculated based on the initial price,
/// emission rate, decay constant, and the time since the last purchase in days.
#[derive(Copy, Drop, Serde, starknet::Storage)]
struct ContinuousGDA {
#[derive(Copy, Drop, Serde, starknet::Store)]
pub struct ContinuousGDA {
initial_price: Fixed,
emission_rate: Fixed,
decay_constant: Fixed,
}

#[generate_trait]
impl ContinuousGDAImpl of ContinuousGDATrait {
pub impl ContinuousGDAImpl of ContinuousGDATrait {
/// Calculates the purchase price for a given quantity of the item at a specific time.
///
/// # Arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use cubit::f128::types::fixed::{Fixed, FixedTrait};

fn to_days_fp(x: Fixed) -> Fixed {
pub fn to_days_fp(x: Fixed) -> Fixed {
x / FixedTrait::new(86400, false)
}

fn from_days_fp(x: Fixed) -> Fixed {
pub fn from_days_fp(x: Fixed) -> Fixed {
x * FixedTrait::new(86400, false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ use cubit::f128::types::fixed::{Fixed, FixedTrait};

// Based on https://www.paradigm.xyz/2022/08/vrgda

trait VRGDAVarsTrait<T> {
pub trait VRGDAVarsTrait<T> {
fn get_target_price(self: @T) -> Fixed;
fn get_decay_constant(self: @T) -> Fixed;
}

trait VRGDATrait<T> {
pub trait VRGDATrait<T> {
fn get_vrgda_price(self: @T, time_since_start: Fixed, sold: Fixed) -> Fixed;
fn get_reverse_vrgda_price(self: @T, time_since_start: Fixed, sold: Fixed) -> Fixed;
}

trait VRGDATargetTimeTrait<T> {
pub trait VRGDATargetTimeTrait<T> {
fn get_target_sale_time(self: @T, sold: Fixed) -> Fixed;
}

impl TVRGDATrait<T, +VRGDAVarsTrait<T>, +VRGDATargetTimeTrait<T>> of VRGDATrait<T> {
pub impl TVRGDATrait<T, +VRGDAVarsTrait<T>, +VRGDATargetTimeTrait<T>> of VRGDATrait<T> {
/// Calculates the VRGDA price at a specific time since the auction started.
///
/// # Arguments
Expand Down Expand Up @@ -48,14 +48,14 @@ impl TVRGDATrait<T, +VRGDAVarsTrait<T>, +VRGDATargetTimeTrait<T>> of VRGDATrait<
/// Represents an auction where the price decays linearly based on the target price,
/// decay constant, and per-time-unit rate.
#[derive(Copy, Drop, Serde, starknet::Store)]
struct LinearVRGDA {
pub struct LinearVRGDA {
target_price: Fixed,
decay_constant: Fixed,
target_units_per_time: Fixed,
}


impl LinearVRGDAVarsImpl of VRGDAVarsTrait<LinearVRGDA> {
pub impl LinearVRGDAVarsImpl of VRGDAVarsTrait<LinearVRGDA> {
fn get_target_price(self: @LinearVRGDA) -> Fixed {
*self.target_price
}
Expand All @@ -80,10 +80,10 @@ impl LinearVRGDATargetTimeImpl of VRGDATargetTimeTrait<LinearVRGDA> {
}
}

impl LinearVRGDAImpl = TVRGDATrait<LinearVRGDA>;
pub impl LinearVRGDAImpl = TVRGDATrait<LinearVRGDA>;

#[derive(Copy, Drop, Serde, starknet::Store)]
struct LogisticVRGDA {
pub struct LogisticVRGDA {
target_price: Fixed,
decay_constant: Fixed,
max_sellable: Fixed,
Expand All @@ -99,7 +99,7 @@ impl LogisticVRGDAVarsImpl of VRGDAVarsTrait<LogisticVRGDA> {
}
}

impl LogisticVRGDATargetTimeImpl of VRGDATargetTimeTrait<LogisticVRGDA> {
pub impl LogisticVRGDATargetTimeImpl of VRGDATargetTimeTrait<LogisticVRGDA> {
/// Calculates the target sale time using a logistic function based on the quantity sold.
///
/// # Arguments
Expand All @@ -116,7 +116,7 @@ impl LogisticVRGDATargetTimeImpl of VRGDATargetTimeTrait<LogisticVRGDA> {
* ln((logistic_limit_double / (sold + logistic_limit)) - FixedTrait::ONE())
}
}
impl LogisticVRGDAImpl = TVRGDATrait<LogisticVRGDA>;
pub impl LogisticVRGDAImpl = TVRGDATrait<LogisticVRGDA>;


#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions crates/defi/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod auction {
pub mod gda;
pub mod vrgda;
pub mod helpers;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions crates/map/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "origami_map"
version = "0.1.0"
description = "Maps library for Dojo based games."
homepage = "https://github.com/dojoengine/origami/tree/main/crates/map"
edition = "2024_07"

[dependencies]
13 changes: 4 additions & 9 deletions crates/src/map/hex/hex.cairo → crates/map/src/hex/hex.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use core::clone::Clone;
use core::traits::Into;
use core::box::BoxTrait;
use core::option::OptionTrait;
use core::array::ArrayTrait;
use origami::map::hex::{types::{HexTile, Direction, DirectionIntoFelt252}};

trait IHexTile {
use super::types::{HexTile, Direction, DirectionIntoFelt252};

pub trait IHexTile {
fn new(col: u32, row: u32) -> HexTile;
fn neighbor(self: HexTile, direction: Direction) -> HexTile;
fn neighbor_even_y(self: HexTile, direction: Direction) -> HexTile;
Expand All @@ -14,7 +9,7 @@ trait IHexTile {
fn tiles_within_range(self: HexTile, range: u32) -> Array<HexTile>;
}

impl ImplHexTile of IHexTile {
pub impl ImplHexTile of IHexTile {
fn new(col: u32, row: u32) -> HexTile {
HexTile { col, row }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[derive(Drop, Copy, Serde)]
struct HexTile {
col: u32,
row: u32,
pub struct HexTile {
pub col: u32,
pub row: u32,
}

#[derive(Drop, Copy, Serde)]
enum Direction {
pub enum Direction {
East: (),
NorthEast: (),
NorthWest: (),
Expand All @@ -14,7 +14,7 @@ enum Direction {
SouthEast: (),
}

impl DirectionIntoFelt252 of Into<Direction, felt252> {
pub impl DirectionIntoFelt252 of Into<Direction, felt252> {
fn into(self: Direction) -> felt252 {
match self {
Direction::East => 0,
Expand Down
4 changes: 4 additions & 0 deletions crates/map/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod hex {
pub mod hex;
pub mod types;
}
6 changes: 6 additions & 0 deletions crates/random/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "origami_random"
version = "0.1.0"
9 changes: 9 additions & 0 deletions crates/random/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "origami_random"
version = "0.1.0"
description = "Random generator library for Dojo based games."
homepage = "https://github.com/dojoengine/origami/tree/main/crates/random"
edition = "2024_07"

[dependencies]

Loading

0 comments on commit 194035a

Please sign in to comment.