diff --git a/.github/dojo-mark-full-dark.svg b/.github/dojo-mark-full-dark.svg new file mode 100644 index 00000000..5bc5b839 --- /dev/null +++ b/.github/dojo-mark-full-dark.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 950abfd3..f98befe5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/examples/react-app/bun.lockb b/examples/react-app/bun.lockb index 129aba77..5c3db3bf 100755 Binary files a/examples/react-app/bun.lockb and b/examples/react-app/bun.lockb differ diff --git a/examples/react-app/package.json b/examples/react-app/package.json index 608e6287..b00d7f89 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -9,15 +9,15 @@ "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", "codegen": "graphql-codegen", - "create-components": "npx @dojoengine/core src/manifest.json src/dojo/contractComponents.ts" - }, + "create-components": "npx @dojoengine/core src/dojo/manifest.json src/dojo/contractComponents.ts" + }, "dependencies": { "@dojoengine/core": "link:dojo-packages/packages/core", "@dojoengine/create-burner": "link:dojo-packages/packages/create-burner", "@dojoengine/utils": "link:dojo-packages/packages/utils", - "@latticexyz/react": "^2.0.0-next.9", - "@latticexyz/recs": "^2.0.0-next.9", - "@latticexyz/utils": "^2.0.0-next.9", + "@latticexyz/react": "^2.0.0-next.11", + "@latticexyz/recs": "^2.0.0-next.11", + "@latticexyz/utils": "^2.0.0-next.11", "ethers": "^5.7.2", "graphql": "^16.7.1", "graphql-request": "^6.1.0", @@ -26,7 +26,9 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "rxjs": "^7.8.1", - "starknet": "^5.17.0" + "starknet": "^5.17.0", + "vite-plugin-top-level-await": "^1.3.1", + "vite-plugin-wasm": "^3.2.2" }, "devDependencies": { "@graphql-codegen/cli": "^5.0.0", diff --git a/examples/react-app/src/dojo/contractComponents.ts b/examples/react-app/src/dojo/contractComponents.ts index 490570a4..7c352473 100644 --- a/examples/react-app/src/dojo/contractComponents.ts +++ b/examples/react-app/src/dojo/contractComponents.ts @@ -10,10 +10,12 @@ export function defineContractComponents(world: World) { world, { remaining: RecsType.Number, + last_direction: RecsType.Number, }, { metadata: { name: name, + types: ["u8","Direction"], }, } ); @@ -24,39 +26,12 @@ export function defineContractComponents(world: World) { world, { x: RecsType.Number, - y: RecsType.Number, - }, - { - metadata: { - name: name, - }, - } - ); - })(), - AuthStatus: (() => { - const name = "AuthStatus"; - return defineComponent( - world, - { - is_authorized: RecsType.Boolean, - }, - { - metadata: { - name: name, - }, - } - ); - })(), - AuthRole: (() => { - const name = "AuthRole"; - return defineComponent( - world, - { - id: RecsType.Number, + y: RecsType.Number }, { metadata: { name: name, + types: ["Vec2"], }, } ); diff --git a/examples/react-app/src/dojo/createSystemCalls.ts b/examples/react-app/src/dojo/createSystemCalls.ts index 19ea9d49..9595ed0b 100644 --- a/examples/react-app/src/dojo/createSystemCalls.ts +++ b/examples/react-app/src/dojo/createSystemCalls.ts @@ -6,6 +6,7 @@ import { ClientComponents } from "./createClientComponents"; import { updatePositionWithDirection } from "../utils"; import { getEvents, setComponentsFromEvents } from "@dojoengine/utils"; + export type SystemCalls = ReturnType; export function createSystemCalls( diff --git a/examples/react-app/src/dojo/manifest.json b/examples/react-app/src/dojo/manifest.json index fbe348c0..c9e9b0f4 100644 --- a/examples/react-app/src/dojo/manifest.json +++ b/examples/react-app/src/dojo/manifest.json @@ -2,7 +2,7 @@ "world": { "name": "world", "address": null, - "class_hash": "0x370195d9fa250c4844f750f68ca77adf86c7f3293cc1cbac5c65d3404e2b2af", + "class_hash": "0xfd35fc17c6a9334c70e38da27aeed6a13297d9faa697547edac8a477e64448", "abi": [ { "type": "impl", @@ -29,6 +29,20 @@ } ] }, + { + "type": "enum", + "name": "core::option::Option::", + "variants": [ + { + "name": "Some", + "type": "core::felt252" + }, + { + "name": "None", + "type": "()" + } + ] + }, { "type": "struct", "name": "core::array::Span::>", @@ -59,7 +73,39 @@ "items": [ { "type": "function", - "name": "component", + "name": "metadata_uri", + "inputs": [ + { + "name": "resource", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "set_metadata_uri", + "inputs": [ + { + "name": "resource", + "type": "core::felt252" + }, + { + "name": "uri", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "model", "inputs": [ { "name": "name", @@ -75,7 +121,7 @@ }, { "type": "function", - "name": "register_component", + "name": "register_model", "inputs": [ { "name": "class_hash", @@ -85,6 +131,26 @@ "outputs": [], "state_mutability": "external" }, + { + "type": "function", + "name": "deploy_contract", + "inputs": [ + { + "name": "salt", + "type": "core::felt252" + }, + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "external" + }, { "type": "function", "name": "uuid", @@ -117,7 +183,7 @@ "name": "entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -149,7 +215,7 @@ "name": "set_entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -177,19 +243,23 @@ "name": "entities", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { "name": "index", - "type": "core::felt252" + "type": "core::option::Option::" }, { - "name": "length", + "name": "values", + "type": "core::array::Span::" + }, + { + "name": "values_length", "type": "core::integer::u32" }, { - "name": "layout", + "name": "values_layout", "type": "core::array::Span::" } ], @@ -223,12 +293,23 @@ ], "state_mutability": "view" }, + { + "type": "function", + "name": "base", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::class_hash::ClassHash" + } + ], + "state_mutability": "view" + }, { "type": "function", "name": "delete_entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -248,7 +329,7 @@ "type": "core::starknet::contract_address::ContractAddress" }, { - "name": "target", + "name": "resource", "type": "core::felt252" } ], @@ -268,7 +349,7 @@ "type": "core::starknet::contract_address::ContractAddress" }, { - "name": "target", + "name": "resource", "type": "core::felt252" } ], @@ -284,7 +365,7 @@ "type": "core::starknet::contract_address::ContractAddress" }, { - "name": "target", + "name": "resource", "type": "core::felt252" } ], @@ -296,7 +377,7 @@ "name": "is_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -316,7 +397,7 @@ "name": "grant_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -332,7 +413,7 @@ "name": "revoke_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -352,6 +433,10 @@ { "name": "executor", "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "contract_base", + "type": "core::starknet::class_hash::ClassHash" } ] }, @@ -366,7 +451,7 @@ "kind": "data" }, { - "name": "caller", + "name": "creator", "type": "core::starknet::contract_address::ContractAddress", "kind": "data" } @@ -374,11 +459,11 @@ }, { "type": "event", - "name": "dojo::world::world::ComponentRegistered", + "name": "dojo::world::world::ContractDeployed", "kind": "struct", "members": [ { - "name": "name", + "name": "salt", "type": "core::felt252", "kind": "data" }, @@ -386,12 +471,34 @@ "name": "class_hash", "type": "core::starknet::class_hash::ClassHash", "kind": "data" + }, + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" } ] }, { "type": "event", - "name": "dojo::world::world::SystemRegistered", + "name": "dojo::world::world::MetadataUpdate", + "kind": "struct", + "members": [ + { + "name": "resource", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "uri", + "type": "core::array::Span::", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::ModelRegistered", "kind": "struct", "members": [ { @@ -400,8 +507,13 @@ "kind": "data" }, { - "name": "contract_address", - "type": "core::starknet::contract_address::ContractAddress", + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + }, + { + "name": "prev_class_hash", + "type": "core::starknet::class_hash::ClassHash", "kind": "data" } ] @@ -450,6 +562,67 @@ } ] }, + { + "type": "event", + "name": "dojo::world::world::WriterUpdated", + "kind": "struct", + "members": [ + { + "name": "model", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "system", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "value", + "type": "core::bool", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::OwnerUpdated", + "kind": "struct", + "members": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "resource", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "value", + "type": "core::bool", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::ExecutorUpdated", + "kind": "struct", + "members": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "prev_address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, { "type": "event", "name": "dojo::world::world::Event", @@ -461,13 +634,18 @@ "kind": "nested" }, { - "name": "ComponentRegistered", - "type": "dojo::world::world::ComponentRegistered", + "name": "ContractDeployed", + "type": "dojo::world::world::ContractDeployed", "kind": "nested" }, { - "name": "SystemRegistered", - "type": "dojo::world::world::SystemRegistered", + "name": "MetadataUpdate", + "type": "dojo::world::world::MetadataUpdate", + "kind": "nested" + }, + { + "name": "ModelRegistered", + "type": "dojo::world::world::ModelRegistered", "kind": "nested" }, { @@ -479,6 +657,21 @@ "name": "StoreDelRecord", "type": "dojo::world::world::StoreDelRecord", "kind": "nested" + }, + { + "name": "WriterUpdated", + "type": "dojo::world::world::WriterUpdated", + "kind": "nested" + }, + { + "name": "OwnerUpdated", + "type": "dojo::world::world::OwnerUpdated", + "kind": "nested" + }, + { + "name": "ExecutorUpdated", + "type": "dojo::world::world::ExecutorUpdated", + "kind": "nested" } ] } @@ -542,31 +735,81 @@ } ] }, - "systems": [], + "base": { + "name": "base", + "class_hash": "0x7aec2b7d7064c1294a339cd90060331ff704ab573e4ee9a1b699be2215c11c9", + "abi": [ + { + "type": "impl", + "name": "Upgradeable", + "interface_name": "dojo::upgradable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::upgradable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "constructor", + "name": "constructor", + "inputs": [] + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + }, + { + "type": "event", + "name": "dojo::base::base::Event", + "kind": "enum", + "variants": [] + } + ] + }, "contracts": [ { "name": "player_actions", - "address": "0x2ea8f5fb0bbba62e32dfa87cf1019c15345bd24b0d88be549e5a3f67693cd0e", - "class_hash": "0x48465b92d0b49ae15999132b88c619b84a0ac7877f92e134a2fef77d387035e", + "address": null, + "class_hash": "0x723c28b9bd637109255b12be937109f405ebb5ff8ed48c0db0eef98bde128ae", "abi": [ { "type": "impl", "name": "PlayerActionsImpl", "interface_name": "dojo_examples::systems::with_decorator::IPlayerActions" }, - { - "type": "struct", - "name": "dojo::world::IWorldDispatcher", - "members": [ - { - "name": "contract_address", - "type": "core::starknet::contract_address::ContractAddress" - } - ] - }, { "type": "enum", - "name": "dojo_examples::components::Direction", + "name": "dojo_examples::models::Direction", "variants": [ { "name": "None", @@ -597,12 +840,7 @@ { "type": "function", "name": "spawn", - "inputs": [ - { - "name": "world", - "type": "dojo::world::IWorldDispatcher" - } - ], + "inputs": [], "outputs": [], "state_mutability": "view" }, @@ -610,13 +848,9 @@ "type": "function", "name": "move", "inputs": [ - { - "name": "world", - "type": "dojo::world::IWorldDispatcher" - }, { "name": "direction", - "type": "dojo_examples::components::Direction" + "type": "dojo_examples::models::Direction" } ], "outputs": [], @@ -647,7 +881,7 @@ }, { "name": "direction", - "type": "dojo_examples::components::Direction", + "type": "dojo_examples::models::Direction", "kind": "data" } ] @@ -669,26 +903,16 @@ { "name": "player_actions_external", "address": null, - "class_hash": "0x17a570b3ae75ace7bad6da4581f55356dc3325fa2b454913372f6976d8d5b40", + "class_hash": "0x1a80dbade1b3429f121303b3443a30d6412b85691f7733abe1ec5250509f081", "abi": [ { "type": "impl", "name": "PlayerActionsImpl", "interface_name": "dojo_examples::systems::raw_contract::IPlayerActions" }, - { - "type": "struct", - "name": "dojo::world::IWorldDispatcher", - "members": [ - { - "name": "contract_address", - "type": "core::starknet::contract_address::ContractAddress" - } - ] - }, { "type": "enum", - "name": "dojo_examples::components::Direction", + "name": "dojo_examples::models::Direction", "variants": [ { "name": "None", @@ -719,12 +943,7 @@ { "type": "function", "name": "spawn", - "inputs": [ - { - "name": "world", - "type": "dojo::world::IWorldDispatcher" - } - ], + "inputs": [], "outputs": [], "state_mutability": "view" }, @@ -732,13 +951,9 @@ "type": "function", "name": "move", "inputs": [ - { - "name": "world", - "type": "dojo::world::IWorldDispatcher" - }, { "name": "direction", - "type": "dojo_examples::components::Direction" + "type": "dojo_examples::models::Direction" } ], "outputs": [], @@ -758,7 +973,7 @@ }, { "name": "direction", - "type": "dojo_examples::components::Direction", + "type": "dojo_examples::models::Direction", "kind": "data" } ] @@ -778,7 +993,7 @@ ] } ], - "components": [ + "models": [ { "name": "Moves", "members": [ @@ -798,7 +1013,7 @@ "key": false } ], - "class_hash": "0x3682ef3ef44d8db8c8bfe72533e2e3b17e7b80efd6550b365deed7b4b3f8597", + "class_hash": "0xb37482a660983dfbf65968caa26eab260d3e1077986454b52ac06e58ae20c4", "abi": [ { "type": "function", @@ -813,7 +1028,18 @@ }, { "type": "function", - "name": "size", + "name": "unpacked_size", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "packed_size", "inputs": [], "outputs": [ { @@ -883,7 +1109,17 @@ }, { "type": "struct", - "name": "dojo::database::schema::EnumMember", + "name": "core::array::Span::<(core::felt252, core::array::Span::)>", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::<(core::felt252, core::array::Span::)>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::Enum", "members": [ { "name": "name", @@ -894,8 +1130,8 @@ "type": "core::array::Span::" }, { - "name": "values", - "type": "core::array::Span::>" + "name": "children", + "type": "core::array::Span::<(core::felt252, core::array::Span::)>" } ] }, @@ -904,7 +1140,7 @@ "name": "dojo::database::schema::Ty", "variants": [ { - "name": "Simple", + "name": "Primitive", "type": "core::felt252" }, { @@ -913,7 +1149,11 @@ }, { "name": "Enum", - "type": "dojo::database::schema::EnumMember" + "type": "dojo::database::schema::Enum" + }, + { + "name": "Tuple", + "type": "core::array::Span::>" } ] }, @@ -930,7 +1170,7 @@ }, { "type": "event", - "name": "dojo_examples::components::moves::Event", + "name": "dojo_examples::models::moves::Event", "kind": "enum", "variants": [] } @@ -950,7 +1190,7 @@ "key": false } ], - "class_hash": "0x69889772f44397619cd8965660e1c8e80ba5f0c917ba40df29b2ffa5b440745", + "class_hash": "0x6ffc643cbc4b2fb9c424242b18175a5e142269b45f4463d1cd4dddb7a2e5095", "abi": [ { "type": "function", @@ -965,7 +1205,18 @@ }, { "type": "function", - "name": "size", + "name": "unpacked_size", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "packed_size", "inputs": [], "outputs": [ { @@ -1035,7 +1286,17 @@ }, { "type": "struct", - "name": "dojo::database::schema::EnumMember", + "name": "core::array::Span::<(core::felt252, core::array::Span::)>", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::<(core::felt252, core::array::Span::)>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::Enum", "members": [ { "name": "name", @@ -1046,8 +1307,8 @@ "type": "core::array::Span::" }, { - "name": "values", - "type": "core::array::Span::>" + "name": "children", + "type": "core::array::Span::<(core::felt252, core::array::Span::)>" } ] }, @@ -1056,7 +1317,7 @@ "name": "dojo::database::schema::Ty", "variants": [ { - "name": "Simple", + "name": "Primitive", "type": "core::felt252" }, { @@ -1065,7 +1326,11 @@ }, { "name": "Enum", - "type": "dojo::database::schema::EnumMember" + "type": "dojo::database::schema::Enum" + }, + { + "name": "Tuple", + "type": "core::array::Span::>" } ] }, @@ -1082,7 +1347,7 @@ }, { "type": "event", - "name": "dojo_examples::components::position::Event", + "name": "dojo_examples::models::position::Event", "kind": "enum", "variants": [] } diff --git a/examples/react-app/tsconfig.json b/examples/react-app/tsconfig.json index 761deb73..b14406fc 100644 --- a/examples/react-app/tsconfig.json +++ b/examples/react-app/tsconfig.json @@ -9,14 +9,12 @@ ], "module": "ESNext", "skipLibCheck": true, - /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, diff --git a/examples/react-app/vite.config.ts b/examples/react-app/vite.config.ts index 5a33944a..780c9121 100644 --- a/examples/react-app/vite.config.ts +++ b/examples/react-app/vite.config.ts @@ -1,7 +1,9 @@ import { defineConfig } from 'vite' +import wasm from "vite-plugin-wasm"; import react from '@vitejs/plugin-react' +import topLevelAwait from "vite-plugin-top-level-await"; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()], + plugins: [react(), wasm(), topLevelAwait()], }) diff --git a/package.json b/package.json index bebd96b5..db941662 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "workspaces": [ "packages/create-burner", "packages/core", - "packages/utils" + "packages/utils", + "packages/torii" ] } \ No newline at end of file diff --git a/packages/core/bin/generateComponents.cjs b/packages/core/bin/generateComponents.cjs index 262acea5..e9b92109 100755 --- a/packages/core/bin/generateComponents.cjs +++ b/packages/core/bin/generateComponents.cjs @@ -18,6 +18,8 @@ const { dependencies } = require(path.resolve("./package.json")); const recsVersion = dependencies?.["@latticexyz/recs"] ?? ""; const isRecsVersion2 = /^[\^\~]?2./g.exec(recsVersion) != null; console.log(`...generating for @latticexyz/recs version ${isRecsVersion2 ? '2 (bigint support, Entity as string)' : '1 (no bigint, EntityIndex as number)'}`) +console.log('---------------------------') +console.log('WARNING: Currently does not generate custom types. You will have to manually add this.') const cairoToRecsType = { "bool": "RecsType.Boolean", diff --git a/readme.md b/readme.md index 4e85686c..a41d1e13 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,31 @@ -## Dojo Packages + +
+ +
+
+
+ + + + + + + + + +[![discord](https://img.shields.io/badge/join-dojo-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4) +![Github Actions][gha-badge] [![Telegram Chat][tg-badge]][tg-url] + +[gha-badge]: https://img.shields.io/github/actions/workflow/status/dojoengine/dojo/ci.yml?branch=main +[tg-badge]: https://img.shields.io/endpoint?color=neon&logo=telegram&label=chat&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fdojoengine +[tg-url]: https://t.me/dojoengine +
+ +# Dojo: The Provable Game Engine + +**Dojo is a community driven open-source, Provable Game Engine, providing a comprehensive toolkit for building verifiable games and autonomous worlds.** + +### Packages Monorepo for the [dojo engine](https://www.dojoengine.org/en/) npm packages. @@ -17,12 +44,15 @@ curl -fsSL https://bun.sh/install | bash ### Development -From the root to install all the packages deps. +From the root to install all the packages deps ``` bun install ``` -This will watch for local changes made to the package and compile, which will be reflected in the example. +### Building packages + +Navigate to a package and run the following. This will launch bun and watch for local changes, automatically compiling and updating. + ``` bun run build --watch ```