Skip to content

Commit cb2f3ee

Browse files
committed
chore: bump dojo 1.5
1 parent 897ced9 commit cb2f3ee

File tree

50 files changed

+1942
-1667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1942
-1667
lines changed

.changeset/thirty-cheetahs-design.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@dojoengine/torii-wasm": minor
3+
"@dojoengine/state": minor
4+
"@dojoengine/sdk": minor
5+
"@dojoengine/core": minor
6+
"@dojoengine/create-burner": minor
7+
"@dojoengine/create-dojo": minor
8+
"@dojoengine/predeployed-connector": minor
9+
"@dojoengine/react": minor
10+
"@dojoengine/torii-client": minor
11+
"@dojoengine/utils": minor
12+
"@dojoengine/utils-wasm": minor
13+
---
14+
15+
chore: bump dojo 1.5

.github/workflows/ci.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ jobs:
4646
- run: curl -L https://install.dojoengine.org | bash
4747
- uses: software-mansion/setup-scarb@v1
4848
with:
49-
scarb-version: "2.9.2"
50-
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.2.1
49+
scarb-version: "2.10.1"
50+
- run: /home/runner/.config/.dojo/dojoup/dojoup install v1.5.0-alpha.2
5151
- run: |
5252
cd worlds/dojo-starter
53+
ls -la /home/runner/.config/.dojo/bin
5354
/home/runner/.config/.dojo/bin/sozo build
5455
/home/runner/.config/.dojo/bin/sozo test
5556
- run: |

.github/workflows/release.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
- name: Setup Node.js with PNPM cache
2929
uses: actions/setup-node@v4
3030
with:
31-
node-version: 'lts/*'
32-
cache: 'pnpm'
31+
node-version: "lts/*"
32+
cache: "pnpm"
3333
# The cache will be invalidated if these files change
34-
cache-dependency-path: '**/pnpm-lock.yaml'
34+
cache-dependency-path: "**/pnpm-lock.yaml"
3535

3636
# Cache the PNPM store to speed up installations
3737
- name: Get PNPM store directory
@@ -58,7 +58,7 @@ jobs:
5858
key: ${{ runner.os }}-build-${{ github.sha }}
5959
restore-keys: |
6060
${{ runner.os }}-build-
61-
61+
6262
# Add Cargo cache for torii-wasm
6363
- name: Cache Cargo dependencies and build artifacts
6464
uses: actions/cache@v3
@@ -74,8 +74,8 @@ jobs:
7474
- run: curl -L https://install.dojoengine.org | bash
7575
- uses: software-mansion/setup-scarb@v1
7676
with:
77-
scarb-version: "2.9.2"
78-
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.2.1
77+
scarb-version: "2.10.1"
78+
- run: /home/runner/.config/.dojo/dojoup/dojoup install v1.5.0-alpha.2
7979
- run: |
8080
cd worlds/dojo-starter
8181
/home/runner/.config/.dojo/bin/sozo build
@@ -106,7 +106,7 @@ jobs:
106106
STATUS=$(pnpm changeset status)
107107
echo "Changeset status:"
108108
echo "$STATUS"
109-
109+
110110
# Check if we have packages to bump
111111
if echo "$STATUS" | grep -q "NO packages to be bumped at patch" && \
112112
echo "$STATUS" | grep -q "NO packages to be bumped at minor" && \
@@ -124,7 +124,7 @@ jobs:
124124
run: |
125125
# Apply version bump based on release type
126126
pnpm changeset version
127-
127+
128128
# If this is a dry run, revert the version changes
129129
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
130130
echo "DRY RUN: Would version packages to ${NEW_VERSION}"
@@ -166,4 +166,4 @@ jobs:
166166
TAGS=$(pnpm changeset tag)
167167
echo "DRY RUN: Would commit changes with message: chore: release"
168168
echo "DRY RUN: Would create and push tag: $TAGS"
169-
git status
169+
git status

examples/example-node-worker/dojoConfig.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createDojoConfig } from "@dojoengine/core";
22

3-
import manifest from "../../worlds/dojo-starter/manifest_dev.json";
3+
import manifest from "../../worlds/dojo-starter/manifest_dev.json" with {
4+
type: "json",
5+
};
46

57
export const dojoConfig = createDojoConfig({
68
manifest,

examples/example-node-worker/env.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import "dotenv/config";
2+
import { z } from "zod";
3+
4+
const envSchema = z.object({
5+
IDENTITY: z.string(),
6+
SECRET_KEY: z.string(),
7+
});
8+
9+
export const env = envSchema.parse(process.env);

examples/example-node-worker/main.ts

Lines changed: 160 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,177 @@
1-
import { init, KeysClause, ToriiQueryBuilder } from "@dojoengine/sdk/node";
2-
import { dojoConfig } from "./dojoConfig";
1+
import {
2+
KeysClause,
3+
ToriiQueryBuilder,
4+
createWorker,
5+
init,
6+
type ParsedEntity,
7+
getModel,
8+
HistoricalToriiQueryBuilder,
9+
} from "@dojoengine/sdk/node";
10+
import { SigningKey } from "@dojoengine/torii-wasm/node";
11+
import { dojoConfig } from "./dojoConfig.ts";
12+
import {
13+
ModelsMapping,
14+
type Moves,
15+
type SchemaType,
16+
} from "./src/typescript/models.gen.ts";
17+
import { addAddressPadding, type BigNumberish } from "starknet";
18+
import { w3cwebsocket } from "websocket";
19+
import { env } from "./env.ts";
20+
21+
// Those lines are require so that websocket works.
22+
// @ts-ignore
23+
global.Websocket = w3cwebsocket;
24+
// @ts-ignore
25+
global.WorkerGlobalScope = global;
326

427
const sdk = await init({
528
client: {
629
toriiUrl: dojoConfig.toriiUrl,
7-
relayUrl: dojoConfig.relayUrl,
30+
relayUrl: "/ip4/127.0.0.1/tcp/9092/ws",
831
worldAddress: dojoConfig.manifest.world.address,
932
},
10-
domain: {},
33+
domain: {
34+
name: "node-worker",
35+
version: "0.0.1",
36+
chainId: "KATANA",
37+
revision: "1",
38+
},
39+
40+
identity: env.IDENTITY,
41+
signer: SigningKey.fromSecretScalar(env.SECRET_KEY),
1142
});
1243

13-
const query = new ToriiQueryBuilder()
14-
.withClause(
15-
KeysClause(
16-
["dojo_starter-Position", "dojo_starter-Moves"],
17-
[undefined]
18-
).build()
19-
)
20-
.includeHashedKeys();
21-
22-
function onEntityUpdated({ data, error }) {
23-
if (error) {
24-
console.error(error);
25-
return;
44+
type PositionCount = {
45+
Up: number;
46+
Down: number;
47+
Left: number;
48+
Right: number;
49+
};
50+
const defaultPositionCount = {
51+
Up: 0,
52+
Down: 0,
53+
Left: 0,
54+
Right: 0,
55+
};
56+
57+
const positionToU8 = (position: string) => {
58+
const mapping = {
59+
Up: 0,
60+
Down: 1,
61+
Left: 2,
62+
Right: 3,
63+
};
64+
65+
// 10 is used as default value
66+
return mapping[position] ?? 10;
67+
};
68+
const intoPositionCount = (
69+
pos: PositionCount
70+
): Array<[BigNumberish, BigNumberish]> => {
71+
return [
72+
[positionToU8("Up"), `0x${pos.Up.toString(16)}`],
73+
[positionToU8("Down"), `0x${pos.Down.toString(16)}`],
74+
[positionToU8("Left"), `0x${pos.Left.toString(16)}`],
75+
[positionToU8("Right"), `0x${pos.Right.toString(16)}`],
76+
];
77+
};
78+
79+
async function publishOffchainPositionCount(moves: Moves): Promise<void> {
80+
const model = await sdk.getEntities({
81+
query: new ToriiQueryBuilder()
82+
.withClause(
83+
KeysClause(
84+
[ModelsMapping.PositionCount],
85+
[addAddressPadding(moves.player)]
86+
).build()
87+
)
88+
.includeHashedKeys(),
89+
});
90+
const m = getModel(ModelsMapping.PositionCount, model);
91+
if (!m) {
92+
const data = sdk.generateTypedData(
93+
ModelsMapping.PositionCount,
94+
{
95+
identity: moves.player,
96+
position: intoPositionCount(positionCount),
97+
},
98+
[
99+
{
100+
name: "identity",
101+
type: "felt",
102+
},
103+
{
104+
name: "position",
105+
type: "(u8, u128)*",
106+
},
107+
]
108+
);
109+
110+
try {
111+
await sdk.sendMessage(data);
112+
} catch (err) {
113+
console.error(err);
114+
}
115+
} else {
116+
console.log(m.position);
26117
}
118+
}
27119

28-
const entity = data.pop();
29-
if (entity && entity.entityId !== "0x0") {
30-
// do whatever you need here
31-
console.log(entity.models.dojo_starter);
120+
let positionCount = defaultPositionCount;
121+
122+
function initPositionFromEvent(
123+
events: ParsedEntity<SchemaType>[]
124+
): PositionCount {
125+
const pc = defaultPositionCount;
126+
for (const e of events) {
127+
const moved = e.models.dojo_starter.Moved;
128+
if (!moved) {
129+
continue;
130+
}
131+
pc[moved.direction] += 1;
32132
}
133+
return pc;
33134
}
34135

35-
const [entities, sub] = await sdk.subscribeEntityQuery({
36-
query,
37-
callback: onEntityUpdated,
38-
historical: false,
39-
});
136+
await createWorker(async () => {
137+
async function onEntityUpdated({ data, error }) {
138+
if (error) {
139+
console.error(error);
140+
return;
141+
}
40142

41-
console.log(entities);
143+
const entity = data.pop();
144+
if (entity && entity.entityId !== "0x0") {
145+
// do whatever you need here
146+
const model = entity.models.dojo_starter;
147+
if (model?.Moves) {
148+
await publishOffchainPositionCount(model.Moves);
149+
}
150+
}
151+
}
42152

43-
process.on("SIGTERM", () => {
44-
// NOTE: do not forget to free sub here;
45-
sub.free();
46-
process.exit(0);
47-
});
153+
const query = new HistoricalToriiQueryBuilder()
154+
.withClause(
155+
KeysClause(
156+
[ModelsMapping.Moved, ModelsMapping.Moves],
157+
[undefined]
158+
).build()
159+
)
160+
.includeHashedKeys();
161+
162+
const events = await sdk.getEventMessages({
163+
query: query,
164+
});
165+
positionCount = initPositionFromEvent(events);
166+
167+
const [entities, sub] = await sdk.subscribeEntityQuery({
168+
query,
169+
callback: onEntityUpdated,
170+
});
171+
172+
console.log("Entities from worker", entities);
173+
console.log(positionCount);
48174

49-
process.on("SIGINT", () => {
50-
// NOTE: do not forget to free sub here;
51-
sub.free();
52-
process.exit(0);
175+
return [];
176+
return [sub];
53177
});

examples/example-node-worker/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
"version": "0.0.1",
44
"private": true,
55
"type": "module",
6+
"scripts": {
7+
"bun": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 bun run main.ts",
8+
"node": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 node main.ts",
9+
"build": "tsc -b"
10+
},
611
"dependencies": {
712
"@dojoengine/core": "workspace:*",
8-
"@dojoengine/sdk": "workspace:*"
13+
"@dojoengine/sdk": "workspace:*",
14+
"@dojoengine/torii-wasm": "workspace:*",
15+
"dotenv": "^16.4.7",
16+
"starknet": "catalog:",
17+
"websocket": "^1.0.35",
18+
"zod": "^3.24.3"
919
},
1020
"devDependencies": {
11-
"@types/node": "^22.14.1"
21+
"@types/node": "^22.14.1",
22+
"@types/websocket": "^1.0.10"
1223
}
1324
}

0 commit comments

Comments
 (0)