diff --git a/.github/actions/release.yaml b/.github/actions/release.yaml new file mode 100644 index 00000000..34fbcc7e --- /dev/null +++ b/.github/actions/release.yaml @@ -0,0 +1,53 @@ +name: Build and NPM Release + +on: + workflow_dispatch: + +jobs: + build-and-release: + runs-on: ubuntu-latest + + strategy: + matrix: + package: ['packages/core', 'packages/create-burner', 'packages/utils'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: | + cd ${{ matrix.package }} + npm ci + + - name: Bump version + run: | + cd ${{ matrix.package }} + npm version patch -m "Bump version to %s" + env: + GH_TOKEN: ${{ secrets.GIT_TOKEN }} + + - name: Build + run: | + cd ${{ matrix.package }} + npm run build + + - name: Push changes + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GIT_TOKEN }} + directory: ${{ matrix.package }} + force: true + + - name: NPM Publish + run: | + cd ${{ matrix.package }} + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index abcedd04..950abfd3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/examples/react-app/.env b/examples/react-app/.env index 2e2ce2a8..070a4666 100644 --- a/examples/react-app/.env +++ b/examples/react-app/.env @@ -2,6 +2,6 @@ VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c74 VITE_PUBLIC_ACCOUNT_CLASS_HASH=0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f VITE_PUBLIC_MASTER_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 VITE_PUBLIC_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600 -VITE_PUBLIC_WORLD_ADDRESS=0x223b959926c92e10a5de78a76871fa40cefafbdce789137843df7c7b30e3e0 +VITE_PUBLIC_WORLD_ADDRESS=0x2430f23de0cd9a957e1beb7aa8ef2db2af872cc7bb3058b9be833111d5518f5 VITE_PUBLIC_NODE_URL=http://localhost:5050 VITE_PUBLIC_TORII=http://localhost:8080 \ No newline at end of file diff --git a/examples/react-app/bun.lockb b/examples/react-app/bun.lockb index 13370dad..129aba77 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 fc1ab209..608e6287 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -15,9 +15,9 @@ "@dojoengine/core": "link:dojo-packages/packages/core", "@dojoengine/create-burner": "link:dojo-packages/packages/create-burner", "@dojoengine/utils": "link:dojo-packages/packages/utils", - "@dojoengine/react": "^0.0.3", - "@latticexyz/recs": "^1.43.0", - "@latticexyz/utils": "^1.43.0", + "@latticexyz/react": "^2.0.0-next.9", + "@latticexyz/recs": "^2.0.0-next.9", + "@latticexyz/utils": "^2.0.0-next.9", "ethers": "^5.7.2", "graphql": "^16.7.1", "graphql-request": "^6.1.0", diff --git a/examples/react-app/src/App.tsx b/examples/react-app/src/App.tsx index dbeef83b..a7639f38 100644 --- a/examples/react-app/src/App.tsx +++ b/examples/react-app/src/App.tsx @@ -1,6 +1,6 @@ import './App.css'; import { useDojo } from './DojoContext'; -import { useComponentValue } from "@dojoengine/react"; +import { useComponentValue } from "@latticexyz/react"; import { Direction, } from './dojo/createSystemCalls' import { EntityIndex, setComponent } from '@latticexyz/recs'; import { useEffect } from 'react'; diff --git a/examples/react-app/src/dojo/createSystemCalls.ts b/examples/react-app/src/dojo/createSystemCalls.ts index a63022d8..19ea9d49 100644 --- a/examples/react-app/src/dojo/createSystemCalls.ts +++ b/examples/react-app/src/dojo/createSystemCalls.ts @@ -14,12 +14,13 @@ export function createSystemCalls( ) { const spawn = async (signer: Account) => { + const entityId = parseInt(signer.address) as EntityIndex; const positionId = uuid(); Position.addOverride(positionId, { entity: entityId, - value: { x: 1000, y: 1000 }, + value: { x: 10, y: 10 }, }); const movesId = uuid(); @@ -29,7 +30,7 @@ export function createSystemCalls( }); try { - const tx = await execute(signer, "spawn", []); + const tx = await execute(signer, "player_actions", 'spawn', []); console.log(tx) const receipt = await signer.waitForTransaction(tx.transaction_hash, { retryInterval: 100 }) @@ -62,7 +63,7 @@ export function createSystemCalls( }); try { - const tx = await execute(signer, "move", [direction]); + const tx = await execute(signer, "player_actions", "move", [direction]); console.log(tx) const receipt = await signer.waitForTransaction(tx.transaction_hash, { retryInterval: 100 }) diff --git a/examples/react-app/src/dojo/manifest.json b/examples/react-app/src/dojo/manifest.json new file mode 100644 index 00000000..fbe348c0 --- /dev/null +++ b/examples/react-app/src/dojo/manifest.json @@ -0,0 +1,1092 @@ +{ + "world": { + "name": "world", + "address": null, + "class_hash": "0x370195d9fa250c4844f750f68ca77adf86c7f3293cc1cbac5c65d3404e2b2af", + "abi": [ + { + "type": "impl", + "name": "World", + "interface_name": "dojo::world::IWorld" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "struct", + "name": "core::array::Span::>", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::>" + } + ] + }, + { + "type": "enum", + "name": "core::bool", + "variants": [ + { + "name": "False", + "type": "()" + }, + { + "name": "True", + "type": "()" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorld", + "items": [ + { + "type": "function", + "name": "component", + "inputs": [ + { + "name": "name", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::starknet::class_hash::ClassHash" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "register_component", + "inputs": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "uuid", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "emit", + "inputs": [ + { + "name": "keys", + "type": "core::array::Array::" + }, + { + "name": "values", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "view" + }, + { + "type": "function", + "name": "entity", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "keys", + "type": "core::array::Span::" + }, + { + "name": "offset", + "type": "core::integer::u8" + }, + { + "name": "length", + "type": "core::integer::u32" + }, + { + "name": "layout", + "type": "core::array::Span::" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "set_entity", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "keys", + "type": "core::array::Span::" + }, + { + "name": "offset", + "type": "core::integer::u8" + }, + { + "name": "values", + "type": "core::array::Span::" + }, + { + "name": "layout", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "entities", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "index", + "type": "core::felt252" + }, + { + "name": "length", + "type": "core::integer::u32" + }, + { + "name": "layout", + "type": "core::array::Span::" + } + ], + "outputs": [ + { + "type": "(core::array::Span::, core::array::Span::>)" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "set_executor", + "inputs": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "executor", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "delete_entity", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "keys", + "type": "core::array::Span::" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "is_owner", + "inputs": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "target", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "grant_owner", + "inputs": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "target", + "type": "core::felt252" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "revoke_owner", + "inputs": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "target", + "type": "core::felt252" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "is_writer", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "system", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "grant_writer", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "system", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "revoke_writer", + "inputs": [ + { + "name": "component", + "type": "core::felt252" + }, + { + "name": "system", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "constructor", + "name": "constructor", + "inputs": [ + { + "name": "executor", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::WorldSpawned", + "kind": "struct", + "members": [ + { + "name": "address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "caller", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::ComponentRegistered", + "kind": "struct", + "members": [ + { + "name": "name", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::SystemRegistered", + "kind": "struct", + "members": [ + { + "name": "name", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::StoreSetRecord", + "kind": "struct", + "members": [ + { + "name": "table", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "keys", + "type": "core::array::Span::", + "kind": "data" + }, + { + "name": "offset", + "type": "core::integer::u8", + "kind": "data" + }, + { + "name": "values", + "type": "core::array::Span::", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::StoreDelRecord", + "kind": "struct", + "members": [ + { + "name": "table", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "keys", + "type": "core::array::Span::", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::world::world::Event", + "kind": "enum", + "variants": [ + { + "name": "WorldSpawned", + "type": "dojo::world::world::WorldSpawned", + "kind": "nested" + }, + { + "name": "ComponentRegistered", + "type": "dojo::world::world::ComponentRegistered", + "kind": "nested" + }, + { + "name": "SystemRegistered", + "type": "dojo::world::world::SystemRegistered", + "kind": "nested" + }, + { + "name": "StoreSetRecord", + "type": "dojo::world::world::StoreSetRecord", + "kind": "nested" + }, + { + "name": "StoreDelRecord", + "type": "dojo::world::world::StoreDelRecord", + "kind": "nested" + } + ] + } + ] + }, + "executor": { + "name": "executor", + "address": null, + "class_hash": "0x2b35dd4816731188ed1ad16caa73bde76075c9d9cb8cbfa3e447d3ab9b1ab33", + "abi": [ + { + "type": "impl", + "name": "Executor", + "interface_name": "dojo::executor::IExecutor" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "interface", + "name": "dojo::executor::IExecutor", + "items": [ + { + "type": "function", + "name": "call", + "inputs": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash" + }, + { + "name": "entrypoint", + "type": "core::felt252" + }, + { + "name": "calldata", + "type": "core::array::Span::" + } + ], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "event", + "name": "dojo::executor::executor::Event", + "kind": "enum", + "variants": [] + } + ] + }, + "systems": [], + "contracts": [ + { + "name": "player_actions", + "address": "0x2ea8f5fb0bbba62e32dfa87cf1019c15345bd24b0d88be549e5a3f67693cd0e", + "class_hash": "0x48465b92d0b49ae15999132b88c619b84a0ac7877f92e134a2fef77d387035e", + "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", + "variants": [ + { + "name": "None", + "type": "()" + }, + { + "name": "Left", + "type": "()" + }, + { + "name": "Right", + "type": "()" + }, + { + "name": "Up", + "type": "()" + }, + { + "name": "Down", + "type": "()" + } + ] + }, + { + "type": "interface", + "name": "dojo_examples::systems::with_decorator::IPlayerActions", + "items": [ + { + "type": "function", + "name": "spawn", + "inputs": [ + { + "name": "world", + "type": "dojo::world::IWorldDispatcher" + } + ], + "outputs": [], + "state_mutability": "view" + }, + { + "type": "function", + "name": "move", + "inputs": [ + { + "name": "world", + "type": "dojo::world::IWorldDispatcher" + }, + { + "name": "direction", + "type": "dojo_examples::components::Direction" + } + ], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "function", + "name": "name", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "event", + "name": "dojo_examples::systems::with_decorator::player_actions::Moved", + "kind": "struct", + "members": [ + { + "name": "player", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "direction", + "type": "dojo_examples::components::Direction", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::systems::with_decorator::player_actions::Event", + "kind": "enum", + "variants": [ + { + "name": "Moved", + "type": "dojo_examples::systems::with_decorator::player_actions::Moved", + "kind": "nested" + } + ] + } + ] + }, + { + "name": "player_actions_external", + "address": null, + "class_hash": "0x17a570b3ae75ace7bad6da4581f55356dc3325fa2b454913372f6976d8d5b40", + "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", + "variants": [ + { + "name": "None", + "type": "()" + }, + { + "name": "Left", + "type": "()" + }, + { + "name": "Right", + "type": "()" + }, + { + "name": "Up", + "type": "()" + }, + { + "name": "Down", + "type": "()" + } + ] + }, + { + "type": "interface", + "name": "dojo_examples::systems::raw_contract::IPlayerActions", + "items": [ + { + "type": "function", + "name": "spawn", + "inputs": [ + { + "name": "world", + "type": "dojo::world::IWorldDispatcher" + } + ], + "outputs": [], + "state_mutability": "view" + }, + { + "type": "function", + "name": "move", + "inputs": [ + { + "name": "world", + "type": "dojo::world::IWorldDispatcher" + }, + { + "name": "direction", + "type": "dojo_examples::components::Direction" + } + ], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::systems::raw_contract::player_actions_external::Moved", + "kind": "struct", + "members": [ + { + "name": "player", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "direction", + "type": "dojo_examples::components::Direction", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::systems::raw_contract::player_actions_external::Event", + "kind": "enum", + "variants": [ + { + "name": "Moved", + "type": "dojo_examples::systems::raw_contract::player_actions_external::Moved", + "kind": "nested" + } + ] + } + ] + } + ], + "components": [ + { + "name": "Moves", + "members": [ + { + "name": "player", + "type": "ContractAddress", + "key": true + }, + { + "name": "remaining", + "type": "u8", + "key": false + }, + { + "name": "last_direction", + "type": "Direction", + "key": false + } + ], + "class_hash": "0x3682ef3ef44d8db8c8bfe72533e2e3b17e7b80efd6550b365deed7b4b3f8597", + "abi": [ + { + "type": "function", + "name": "name", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "size", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "function", + "name": "layout", + "inputs": [], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "struct", + "name": "core::array::Span::>", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::Struct", + "members": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "attrs", + "type": "core::array::Span::" + }, + { + "name": "children", + "type": "core::array::Span::>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::EnumMember", + "members": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "attrs", + "type": "core::array::Span::" + }, + { + "name": "values", + "type": "core::array::Span::>" + } + ] + }, + { + "type": "enum", + "name": "dojo::database::schema::Ty", + "variants": [ + { + "name": "Simple", + "type": "core::felt252" + }, + { + "name": "Struct", + "type": "dojo::database::schema::Struct" + }, + { + "name": "Enum", + "type": "dojo::database::schema::EnumMember" + } + ] + }, + { + "type": "function", + "name": "schema", + "inputs": [], + "outputs": [ + { + "type": "dojo::database::schema::Ty" + } + ], + "state_mutability": "view" + }, + { + "type": "event", + "name": "dojo_examples::components::moves::Event", + "kind": "enum", + "variants": [] + } + ] + }, + { + "name": "Position", + "members": [ + { + "name": "player", + "type": "ContractAddress", + "key": true + }, + { + "name": "vec", + "type": "Vec2", + "key": false + } + ], + "class_hash": "0x69889772f44397619cd8965660e1c8e80ba5f0c917ba40df29b2ffa5b440745", + "abi": [ + { + "type": "function", + "name": "name", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "size", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u32" + } + ], + "state_mutability": "view" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "function", + "name": "layout", + "inputs": [], + "outputs": [ + { + "type": "core::array::Span::" + } + ], + "state_mutability": "view" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "struct", + "name": "core::array::Span::>", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::Struct", + "members": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "attrs", + "type": "core::array::Span::" + }, + { + "name": "children", + "type": "core::array::Span::>" + } + ] + }, + { + "type": "struct", + "name": "dojo::database::schema::EnumMember", + "members": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "attrs", + "type": "core::array::Span::" + }, + { + "name": "values", + "type": "core::array::Span::>" + } + ] + }, + { + "type": "enum", + "name": "dojo::database::schema::Ty", + "variants": [ + { + "name": "Simple", + "type": "core::felt252" + }, + { + "name": "Struct", + "type": "dojo::database::schema::Struct" + }, + { + "name": "Enum", + "type": "dojo::database::schema::EnumMember" + } + ] + }, + { + "type": "function", + "name": "schema", + "inputs": [], + "outputs": [ + { + "type": "dojo::database::schema::Ty" + } + ], + "state_mutability": "view" + }, + { + "type": "event", + "name": "dojo_examples::components::position::Event", + "kind": "enum", + "variants": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/examples/react-app/src/dojo/setupNetwork.ts b/examples/react-app/src/dojo/setupNetwork.ts index d8c103df..8a5cdf96 100644 --- a/examples/react-app/src/dojo/setupNetwork.ts +++ b/examples/react-app/src/dojo/setupNetwork.ts @@ -1,12 +1,17 @@ import { defineContractComponents } from "./contractComponents"; import { world } from "./world"; import { RPCProvider, Query, } from "@dojoengine/core"; -import { Account, num } from "starknet"; +import { Account, TypedContract, num } from "starknet"; import { GraphQLClient } from 'graphql-request'; import { getSdk } from '../generated/graphql'; +import manifest from "./manifest.json"; export type SetupNetworkResult = Awaited>; +const getContractByName = (name: string) => { + return manifest.contracts.find((contract) => contract.name === name); +} + export async function setupNetwork() { // Extract environment variables for better readability. const { VITE_PUBLIC_WORLD_ADDRESS, VITE_PUBLIC_NODE_URL, VITE_PUBLIC_TORII } = import.meta.env; @@ -29,8 +34,8 @@ export async function setupNetwork() { graphSdk: createGraphSdk(), // Execute function. - execute: async (signer: Account, system: string, call_data: num.BigNumberish[]) => { - return provider.execute(signer, system, call_data); + execute: async (signer: Account, contract: string, system: string, call_data: num.BigNumberish[]) => { + return provider.execute(signer, getContractByName(contract)?.address || "", system, call_data); }, // Entity query function. diff --git a/package.json b/package.json index ea4e45f4..bebd96b5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "workspaces": [ "packages/create-burner", "packages/core", - "packages/react", "packages/utils" ] } \ No newline at end of file diff --git a/packages/core/.npmignore b/packages/core/.npmignore index e30ed30a..9e332b0a 100644 --- a/packages/core/.npmignore +++ b/packages/core/.npmignore @@ -3,4 +3,5 @@ !dist/** !package.json !readme.md -!changelog.md \ No newline at end of file +!changelog.md +!bin \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index 10e9182b..fe502bdd 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,15 +1,25 @@ { "name": "@dojoengine/core", - "version": "0.0.20", + "version": "0.0.27", "description": "Dojo engine core providers and types", + "type": "module", "scripts": { - "build": "tsc", - "postbuild": "cp -R bin dist/ && chmod a+x dist/bin/*", + "build": "tsup", + "postbuild": "cp -R bin/ dist/", "test": "jest" }, + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, "author": "Loaf", "license": "MIT", - "main": "dist/index.js", + "main": "./dist/index.js", + "dependencies": { + "starknet": "^5.19.5" + }, "devDependencies": { "@types/elliptic": "^6.4.14", "@types/jest": "^29.5.0", @@ -17,11 +27,11 @@ "bun-types": "^1.0.1", "fetch-mock": "^9.11.0", "jest": "^29.5.0", - "starknet": "^5.19.5", "ts-jest": "^29.1.0", + "tsup": "^7.2.0", "typescript": "^5.0.3" }, "bin": { - "create-components": "./dist/bin/generateComponents.cjs" + "create-components": "./bin/generateComponents.cjs" } -} +} \ No newline at end of file diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c5e46f3f..ef25e150 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,3 +1,3 @@ -export { RPCProvider } from './provider'; +export * from './provider'; export * from './utils' export * from './types'; diff --git a/packages/core/src/provider/RPCProvider.ts b/packages/core/src/provider/RPCProvider.ts index 6cdd1638..5412d747 100644 --- a/packages/core/src/provider/RPCProvider.ts +++ b/packages/core/src/provider/RPCProvider.ts @@ -81,19 +81,20 @@ export class RPCProvider extends Provider { * Executes a function with the given parameters. * * @param {Account} account - The account to use. - * @param {string} system - The system name to execute. + * @param {string} contract - The contract to execute. + * @param {string} call - The function to call. * @param {num.BigNumberish[]} call_data - The call data for the function. * @returns {Promise} - A promise that resolves to the response of the function execution. */ - public async execute(account: Account, system: string, call_data: num.BigNumberish[]): Promise { + public async execute(account: Account, contract: string, call: string, call_data: num.BigNumberish[]): Promise { try { const nonce = await account?.getNonce() return await account?.execute( { - contractAddress: this.getWorldAddress()!, - entrypoint: WorldEntryPoints.execute, - calldata: [shortString.encodeShortString(system), call_data.length, ...call_data] + contractAddress: contract, + entrypoint: call, + calldata: [this.getWorldAddress()!, ...call_data] }, undefined, { diff --git a/packages/core/src/provider/index.ts b/packages/core/src/provider/index.ts index ad860361..aabb0666 100644 --- a/packages/core/src/provider/index.ts +++ b/packages/core/src/provider/index.ts @@ -1 +1 @@ -export { RPCProvider } from "./RPCProvider"; \ No newline at end of file +export * from "./RPCProvider"; \ No newline at end of file diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 45451298..c2879667 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -7,9 +7,9 @@ "sourceMap": true, "noImplicitAny": true, "noUnusedLocals": true, - "moduleResolution": "bundler", + "moduleResolution": "node", // "noUnusedParameters": true, - // "resolveJsonModule": true, + "resolveJsonModule": true, "skipLibCheck": true, "strict": true, "strictNullChecks": true, diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts new file mode 100644 index 00000000..cacf8699 --- /dev/null +++ b/packages/core/tsup.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from "tsup"; +import { tsupConfig } from '../../tsup.config' + +export default defineConfig({ + ...tsupConfig +}); \ No newline at end of file diff --git a/packages/create-burner/.npmignore b/packages/create-burner/.npmignore index c6082568..078562ec 100644 --- a/packages/create-burner/.npmignore +++ b/packages/create-burner/.npmignore @@ -2,4 +2,5 @@ !dist/** !package.json -!readme.md \ No newline at end of file +!readme.md +!tsup.config.ts \ No newline at end of file diff --git a/packages/create-burner/package.json b/packages/create-burner/package.json index cc370a77..1a9408ec 100644 --- a/packages/create-burner/package.json +++ b/packages/create-burner/package.json @@ -1,17 +1,25 @@ { "name": "@dojoengine/create-burner", - "version": "0.0.18", + "version": "0.0.28", "description": "Useful hooks and functions to create a Starknet burner wallet", "source": "src/index.ts", "main": "dist/index.js", + "type": "module", "scripts": { - "build": "tsc", + "build": "tsup --dts-resolve", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Loaf", "license": "MIT", "peerDependencies": { - "react": "^17.0 || ^18.0" + "react": "^18.2.0", + "starknet": "^5.19.0" + }, + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } }, "devDependencies": { "@babel/core": "^7.21.4", @@ -25,12 +33,13 @@ "bun-types": "^1.0.1", "jest": "^29.5.0", "ts-jest": "^29.1.0", + "tsup": "^7.2.0", "typescript": "^5.0.3" }, "dependencies": { "@starknet-react/core": "^1.0.3", + "encoding": "^0.1.13", "get-starknet-core": "^3.2.0", - "js-cookie": "^3.0.5", - "starknet": "^5.14.1" + "js-cookie": "^3.0.5" } } diff --git a/packages/create-burner/tsconfig.json b/packages/create-burner/tsconfig.json index 7a5d4d30..86473bc3 100644 --- a/packages/create-burner/tsconfig.json +++ b/packages/create-burner/tsconfig.json @@ -4,6 +4,8 @@ "module": "ESNext", "moduleResolution": "node", "esModuleInterop": true, + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, "jsx": "react-jsx", "lib": [ "esnext", @@ -18,7 +20,7 @@ "skipLibCheck": true, "strict": true, "strictNullChecks": true, - "target": "es2021", + "target": "esnext", "types": [ "jest", "node", diff --git a/packages/create-burner/tsup.config.ts b/packages/create-burner/tsup.config.ts new file mode 100644 index 00000000..5b08d62c --- /dev/null +++ b/packages/create-burner/tsup.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from "tsup"; +import { tsupConfig } from '../../tsup.config' + +export default defineConfig({ + ...tsupConfig, + minify: false, + splitting: false +}); \ No newline at end of file diff --git a/packages/react/.gitignore b/packages/react/.gitignore deleted file mode 100644 index 76add878..00000000 --- a/packages/react/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -dist \ No newline at end of file diff --git a/packages/react/package.json b/packages/react/package.json deleted file mode 100644 index eaffc30c..00000000 --- a/packages/react/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "@dojoengine/react", - "version": "0.0.2", - "description": "Dojo React", - "source": "src/index.ts", - "main": "dist/index.js", - "scripts": { - "build": "tsc", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "pondering democritus", - "license": "MIT", - "peerDependencies": { - "react": "^17.0 || ^18.0", - "starknet": "next" - }, - "devDependencies": { - "@types/events": "^3.0.0", - "@types/jest": "^29.5.0", - "@types/react": "^18.0.33", - "jest": "^29.5.0", - "ts-jest": "^29.1.0", - "typescript": "^5.0.3", - "@babel/core": "^7.21.4", - "@babel/preset-env": "^7.21.4", - "@latticexyz/recs": "^1.43.0", - "bun-types": "^1.0.1", - "@types/bn.js": "^5.1.1", - "@types/elliptic": "^6.4.14", - "@types/node": "^18.15.11", - "@types/react-dom": "^18.0.11", - "elliptic": "^6.5.4", - "mobx": "^6.9.0", - "rxjs": "^7.8.1", - "type-fest": "^3.11.1" - } -} \ No newline at end of file diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts deleted file mode 100644 index 3b3566e8..00000000 --- a/packages/react/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./useComponentValue"; -export * from "./useEntityQuery"; -export * from "./useObservableValue"; \ No newline at end of file diff --git a/packages/react/src/useComponentValue.ts b/packages/react/src/useComponentValue.ts deleted file mode 100644 index 90bb46fd..00000000 --- a/packages/react/src/useComponentValue.ts +++ /dev/null @@ -1,50 +0,0 @@ -// HACK IMPORT FROM https://github.com/latticexyz/mud - ty Lattice! - -import { - Component, - ComponentValue, - defineQuery, - EntityIndex, - getComponentValue, - Has, - isComponentUpdate, - Metadata, - Schema, -} from "@latticexyz/recs"; -import { useEffect, useState } from "react"; - -export function useComponentValue( - component: Component, - entity: EntityIndex | undefined, - defaultValue: ComponentValue -): ComponentValue; - -export function useComponentValue( - component: Component, - entity: EntityIndex | undefined -): ComponentValue | undefined; - -export function useComponentValue( - component: Component, - entity: EntityIndex | undefined, - defaultValue?: ComponentValue -) { - const [value, setValue] = useState(entity != null ? getComponentValue(component, entity) : undefined); - - useEffect(() => { - // component or entity changed, update state to latest value - setValue(entity != null ? getComponentValue(component, entity) : undefined); - if (entity == null) return; - - const queryResult = defineQuery([Has(component)], { runOnInit: false }); - const subscription = queryResult.update$.subscribe((update: any) => { - if (isComponentUpdate(update, component) && update.entity === entity) { - const [nextValue] = update.value; - setValue(nextValue); - } - }); - return () => subscription.unsubscribe(); - }, [component, entity]); - - return value ?? defaultValue; -} \ No newline at end of file diff --git a/packages/react/src/useEntityQuery.ts b/packages/react/src/useEntityQuery.ts deleted file mode 100644 index 0d966cb0..00000000 --- a/packages/react/src/useEntityQuery.ts +++ /dev/null @@ -1,39 +0,0 @@ -// HACK IMPORT FROM https://github.com/latticexyz/mud - ty Lattice! - -import { defineQuery, QueryFragment } from "@latticexyz/recs"; -import { useEffect, useMemo, useState } from "react"; -import { useDeepMemo } from "./utils/useDeepMemo"; -import isEqual from "fast-deep-equal"; -import { distinctUntilChanged, map } from "rxjs"; - -// This does a little more rendering than is necessary when arguments change, -// but at least it's giving correct results now. Will optimize later! - -/** - * Returns all matching entities for a given entity query, - * and triggers a re-render as new query results come in. - * - * @param fragments Query fragments to match against, executed from left to right. - * @param options.updateOnValueChange False - re-renders only on entity array changes. True (default) - also on component value changes. - * @returns Set of entities matching the query fragments. - */ -export function useEntityQuery(fragments: QueryFragment[], options?: { updateOnValueChange?: boolean }) { - const updateOnValueChange = options?.updateOnValueChange ?? true; - - const stableFragments = useDeepMemo(fragments); - const query = useMemo(() => defineQuery(stableFragments, { runOnInit: true }), [stableFragments]); - const [entities, setEntities] = useState([...query.matching]); - - useEffect(() => { - setEntities([...query.matching]); - let observable = query.update$.pipe(map(() => [...query.matching])); - if (!updateOnValueChange) { - // re-render only on entity array changes - observable = observable.pipe(distinctUntilChanged((a, b) => isEqual(a, b))); - } - const subscription = observable.subscribe((entities) => setEntities(entities)); - return () => subscription.unsubscribe(); - }, [query, updateOnValueChange]); - - return entities; -} \ No newline at end of file diff --git a/packages/react/src/useObservableValue.ts b/packages/react/src/useObservableValue.ts deleted file mode 100644 index 247d1c0e..00000000 --- a/packages/react/src/useObservableValue.ts +++ /dev/null @@ -1,19 +0,0 @@ -// HACK IMPORT FROM https://github.com/latticexyz/mud - ty Lattice! - -import { useEffect, useState } from "react"; -import { Observable } from "rxjs"; - -export function useObservableValue(observable: Observable, defaultValue: T): T; - -export function useObservableValue(observable: Observable): T | undefined; - -export function useObservableValue(observable: Observable, defaultValue?: T) { - const [value, setValue] = useState(defaultValue); - - useEffect(() => { - const subscription = observable.subscribe(setValue); - return () => subscription.unsubscribe(); - }, [observable]); - - return value; -} \ No newline at end of file diff --git a/packages/react/src/utils/useDeepMemo.ts b/packages/react/src/utils/useDeepMemo.ts deleted file mode 100644 index 4a72c9bd..00000000 --- a/packages/react/src/utils/useDeepMemo.ts +++ /dev/null @@ -1,17 +0,0 @@ -// HACK IMPORT FROM https://github.com/latticexyz/mud - ty Lattice! - -import { useEffect, useState } from "react"; -import isEqual from "fast-deep-equal"; - -export const useDeepMemo = (currentValue: T): T => { - const [stableValue, setStableValue] = useState(currentValue); - - useEffect(() => { - if (!isEqual(currentValue, stableValue)) { - setStableValue(currentValue); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentValue]); - - return stableValue; -}; \ No newline at end of file diff --git a/packages/react/tsconfig.json b/packages/react/tsconfig.json deleted file mode 100644 index d204a86e..00000000 --- a/packages/react/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "jsx": "react", - "moduleResolution": "bundler", - "target": "ES2020", - "module": "ESNext", - "declaration": true, - "outDir": "./dist", - "strict": true, - "esModuleInterop": true - }, - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "node_modules", - "dist", - "**/*.test.ts" - ] -} \ No newline at end of file diff --git a/packages/utils/package.json b/packages/utils/package.json index 246f8f00..e2ef1798 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -2,26 +2,34 @@ "name": "@dojoengine/utils", "version": "0.0.2", "description": "Helpful Dojo Utils", + "type": "module", "scripts": { - "build": "tsc", + "build": "tsup", "test": "jest" }, + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, "author": "Loaf", "license": "MIT", "main": "dist/index.js", "devDependencies": { - "@latticexyz/recs": "^1.43.0", "@types/elliptic": "^6.4.14", "@types/jest": "^29.5.0", "@types/mocha": "^10.0.1", "bun-types": "^1.0.1", "fetch-mock": "^9.11.0", "jest": "^29.5.0", - "starknet": "^5.19.5", "ts-jest": "^29.1.0", "typescript": "^5.0.3" }, "dependencies": { - "micro-starknet": "^0.2.3" + "@latticexyz/recs": "^2.0.0-next.9", + "micro-starknet": "^0.2.3", + "@latticexyz/utils": "^2.0.0-next.9", + "starknet": "^5.19.5" } -} +} \ No newline at end of file diff --git a/packages/utils/tsup.config.ts b/packages/utils/tsup.config.ts new file mode 100644 index 00000000..cacf8699 --- /dev/null +++ b/packages/utils/tsup.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from "tsup"; +import { tsupConfig } from '../../tsup.config' + +export default defineConfig({ + ...tsupConfig +}); \ No newline at end of file diff --git a/readme.md b/readme.md index 10c929b8..4e85686c 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,9 @@ Monorepo for the [dojo engine](https://www.dojoengine.org/en/) npm packages. +- [core](./packages/core) +- [burner](./packages/create-burner) +- [utils](./packages/utils) ### Enviroment setup diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 00000000..e416b83c --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,11 @@ +import type { Options } from 'tsup' + +export const tsupConfig: Options = { + entry: ["src/index.ts"], + target: "esnext", + format: ["esm"], + dts: true, + sourcemap: true, + clean: true, + minify: true, +} \ No newline at end of file