Skip to content

Commit 68a5b38

Browse files
authored
feat: typed provider handle CairoCustomEnum (#492)
* feat(types): fix provider + handle CairoCustomEnum * feat(types): support CairoOption * fix: restore DojoProvider type compatibility
1 parent 17df0bb commit 68a5b38

File tree

17 files changed

+7802
-46
lines changed

17 files changed

+7802
-46
lines changed

etc/architecture/overview.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Dojo.js Architecture Overview
2+
3+
## High-Level Components
4+
5+
Dojo.js is organized as a set of focused packages that cooperate to index, query, and interact with Dojo worlds on Starknet.
6+
7+
- **@dojoengine/sdk** orchestrates Torii clients, message signing flows, and schema-aware queries for both web and node runtimes.
8+
- **@dojoengine/core** exposes the `DojoProvider`, a thin Starknet RPC wrapper that performs direct world contract reads and invokes.
9+
- **@dojoengine/grpc** supplies a rich gRPC client with streaming subscriptions and data mappers for Torii indexer interactions.
10+
- **@dojoengine/internal** concentrates shared schema utilities, query builders, pagination helpers, and token tooling used by the SDK.
11+
- **@dojoengine/state** and **@dojoengine/react** provide state management and UI bindings, enabling entity streaming and optimistic updates in applications.
12+
- **Tooling packages** such as `@dojoengine/create-burner`, `@dojoengine/predeployed-connector`, and `@dojoengine/create-dojo` enhance developer experience with wallet utilities and project scaffolding.
13+
14+
## Runtime Flow
15+
16+
```mermaid
17+
flowchart LR
18+
subgraph OnChain
19+
World[Dojo World Contracts]
20+
end
21+
22+
subgraph Indexer & Messaging
23+
ToriiIndexer[Torii Service\nHTTP/WebSocket/gRPC]
24+
end
25+
26+
subgraph CoreClient
27+
CoreProvider[@dojoengine/core\nRpcProvider & World ABI]
28+
ToriiWasm[@dojoengine/torii-wasm\n+ torii-client shim]
29+
GrpcClient[@dojoengine/grpc\nToriiGrpcClient]
30+
Internal[@dojoengine/internal\nSchema & Query Toolkit]
31+
SDK[@dojoengine/sdk\ninit/createSDK]
32+
end
33+
34+
subgraph App Integrations
35+
StatePkg[@dojoengine/state\nZustand & RECS stores]
36+
ReactPkg[@dojoengine/react\nHooks & RX bindings]
37+
Burner[@dojoengine/create-burner\nLocal wallets]
38+
Predeployed[@dojoengine/predeployed-connector\nInjected connector]
39+
UtilsPkg[@dojoengine/utils]
40+
end
41+
42+
subgraph Tooling
43+
Scaffolder[@dojoengine/create-dojo\nCLI scaffolds]
44+
Examples[Examples & Templates]
45+
end
46+
47+
World -- events & state --> ToriiIndexer
48+
CoreProvider -- invoke/call --> World
49+
ToriiIndexer -- queries/subscriptions --> ToriiWasm
50+
ToriiIndexer -- gRPC streams --> GrpcClient
51+
ToriiWasm --> SDK
52+
GrpcClient --> SDK
53+
Internal --> SDK
54+
SDK --> StatePkg
55+
SDK --> ReactPkg
56+
StatePkg --> ReactPkg
57+
SDK --> Burner
58+
SDK --> Predeployed
59+
SDK --> UtilsPkg
60+
Scaffolder --> Examples
61+
Burner --> ReactPkg
62+
Predeployed --> ReactPkg
63+
```
64+
65+
## Key Responsibilities
66+
67+
1. Torii indexes on-chain world events and exposes them via WASM bindings and gRPC streams for consumption by the SDK.
68+
2. The SDK coordinates Torii clients, message signing, and schema-driven parsing to provide a cohesive developer surface.
69+
3. `DojoProvider` gives direct Starknet RPC access when applications need to call world contracts outside the indexer path.
70+
4. Application layers like React hooks and Zustand stores sit on top of the SDK to deliver real-time entity state to UIs.
71+
5. Wallet tooling and scaffolding packages round out the developer workflow for building and testing Dojo-powered apps.

etc/architecture/whats-next.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# What's Next for Dojo.js
2+
3+
This roadmap captures the near-to-mid term architecture initiatives planned for the main branch. Each stream lists intent, key activities, and expected outcomes to inform prioritisation and sequencing.
4+
5+
## 1. Revamped Type System
6+
7+
- **Objective**: Replace the existing world/type plumbing with the new type system in `packages/core/src/types` to improve safety and compatibility with Cairo models.
8+
- **Key Steps**:
9+
1. Audit current exports and downstream usage across `core`, `sdk`, `state`, and `react` packages.
10+
2. Implement adapters or codemods to bridge the new types with legacy consumers while migration is in progress.
11+
3. Expand compiler/test coverage to prevent regressions (e.g., schema parsing, manifests, provider actions).
12+
- **Deliverables**: Updated type definitions, migration guide, comprehensive test suite for the new abstractions.
13+
14+
## 2. Framework-Agnostic Application Bindings
15+
16+
- **Objective**: Reduce React-specific hooks in favour of framework-agnostic bindings that can power multiple UI layers.
17+
- **Key Steps**:
18+
1. Extract core data subscription logic (currently in `@dojoengine/react`) into reusable primitives (signals, observables, store interfaces).
19+
2. Provide thin React adapters while enabling alternative bindings (e.g., Solid, Vue, Svelte) to consume the same core APIs.
20+
3. Update examples and documentation to highlight the framework-neutral approach.
21+
- **Deliverables**: Core binding package with React wrapper, updated samples, migration notes.
22+
23+
## 3. Abstract Starknet.js Dependencies
24+
25+
- **Objective**: Introduce an abstraction layer over Starknet.js so that downstream packages can swap providers or polyfill functionality.
26+
- **Key Steps**:
27+
1. Identify all points where Starknet.js types/classes are imported directly (providers, accounts, signing flows).
28+
2. Define an interface-based contract (e.g., `IStarknetTransport`, `Signer`, `AccountAdapter`) and implement default Starknet.js adapters.
29+
3. Provide dependency injection hooks in SDK/provider constructors and document how to supply alternative transports.
30+
- **Deliverables**: Adapter interfaces, default Starknet.js implementation, updated dependency guidelines.
31+
32+
## 4. TanStack/DB Integration
33+
34+
- **Objective**: Leverage TanStack DB for richer client-side entity persistence, caching, and querying.
35+
- **Key Steps**:
36+
1. Experiment with a proof-of-concept mapping Torii entity snapshots into TanStack DB tables.
37+
2. Define schema generation rules based on Dojo manifests and integrate with state management.
38+
3. Expose opt-in APIs within the SDK or a companion package for consuming TanStack DB features.
39+
- **Deliverables**: Prototype integration, API surface proposal, pilot example demonstrating offline/query benefits.
40+
41+
## 5. Native gRPC Client Enhancements
42+
43+
- **Objective**: Continue maturing the native gRPC client for reliability and feature completeness.
44+
- **Key Steps**:
45+
1. Close remaining parity gaps with Torii WASM client (subscriptions, controllers, token operations).
46+
2. Harden connection lifecycle management (reconnects, backoff, streaming ergonomics).
47+
3. Ship performance benchmarks and cross-platform validation (Node, Bun, browser with WASM transport).
48+
- **Deliverables**: Stable gRPC client API, resilience improvements, documentation and benchmarks.
49+
50+
## 6. Frontend Observability Integrations
51+
52+
- **Objective**: Provide opt-in hooks to plug observability tools (Sentry, PostHog, etc.) into Dojo.js-powered apps.
53+
- **Key Steps**:
54+
1. Define instrumentation points (SDK events, subscription lifecycle, transaction workflows).
55+
2. Create lightweight adapters for popular observability providers with configuration patterns.
56+
3. Document best practices and privacy considerations for instrumenting on-chain interactions.
57+
- **Deliverables**: Observability integration guide, reference adapters, example instrumentation snippets.
58+
59+
## Cross-Cutting Considerations
60+
61+
- Prioritise documentation and migration notes alongside each feature.
62+
- Invest in automated tests and benchmarks as new abstractions are introduced to safeguard performance and developer experience.

etc/knowledge-base.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Dojo.js Knowledge Base
2+
3+
## Architecture Snapshot (Main Branch)
4+
5+
- Reference diagram: [docs/architecture/overview.md](architecture/overview.md)
6+
- Highlights:
7+
- `@dojoengine/sdk` connects Torii indexer clients, message signing, and schema parsing for app consumption.
8+
- `@dojoengine/core` offers the `DojoProvider` Starknet RPC interface for direct world contract access.
9+
- `@dojoengine/grpc` provides streaming access to Torii via the `ToriiGrpcClient` and related mappers.
10+
- UI/state layers (`@dojoengine/state`, `@dojoengine/react`) build on the SDK for entity subscriptions and optimistic updates.
11+
- Tooling packages (`create-burner`, `predeployed-connector`, `create-dojo`) streamline wallet setup and application scaffolding.
12+
13+
_Last updated: 2025-09-25T13:27:58Z

examples/example-vite-react-sdk/src/App.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { WalletAccount } from "./wallet-account.tsx";
1212
import { useSystemCalls } from "./useSystemCalls.ts";
1313
import { Events } from "./events.tsx";
1414
import { HistoricalEvents } from "./historical-events.tsx";
15+
import { dojoProvider } from "./types.ts";
1516

1617
/**
1718
* Main application component that provides game functionality and UI.
@@ -20,10 +21,9 @@ import { HistoricalEvents } from "./historical-events.tsx";
2021
* @param props.sdk - The Dojo SDK instance configured with the game schema
2122
*/
2223
function App() {
23-
const { useDojoStore, client } = useDojoSDK();
24+
const { useDojoStore } = useDojoSDK();
2425
const { account } = useAccount();
2526
const entities = useDojoStore((state) => state.entities);
26-
console.log(entities);
2727

2828
const { spawn } = useSystemCalls();
2929

@@ -117,10 +117,9 @@ function App() {
117117
className={`${col} h-12 w-12 bg-gray-600 rounded-full shadow-md active:shadow-inner active:bg-gray-500 focus:outline-none text-2xl font-bold text-gray-200`}
118118
key={idx}
119119
onClick={async () => {
120-
await client.actions.move(
121-
account!,
122-
direction
123-
);
120+
await dojoProvider.move(account!, {
121+
direction: direction,
122+
});
124123
}}
125124
>
126125
{label}

0 commit comments

Comments
 (0)