Skip to content

chore: bump dojo 1.5 #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/thirty-cheetahs-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@dojoengine/torii-wasm": minor
"@dojoengine/state": minor
"@dojoengine/sdk": minor
"@dojoengine/core": minor
"@dojoengine/create-burner": minor
"@dojoengine/create-dojo": minor
"@dojoengine/predeployed-connector": minor
"@dojoengine/react": minor
"@dojoengine/torii-client": minor
"@dojoengine/utils": minor
"@dojoengine/utils-wasm": minor
---

chore: bump dojo 1.5
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ jobs:
- run: curl -L https://install.dojoengine.org | bash
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.9.2"
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.2.1
scarb-version: "2.10.1"
- run: /home/runner/.config/.dojo/dojoup/dojoup install v1.5.0-alpha.2
- run: |
cd worlds/dojo-starter
ls -la /home/runner/.config/.dojo/bin
/home/runner/.config/.dojo/bin/sozo build
/home/runner/.config/.dojo/bin/sozo test
- run: |
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ jobs:
- name: Setup Node.js with PNPM cache
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'pnpm'
node-version: "lts/*"
cache: "pnpm"
# The cache will be invalidated if these files change
cache-dependency-path: '**/pnpm-lock.yaml'
cache-dependency-path: "**/pnpm-lock.yaml"

# Cache the PNPM store to speed up installations
- name: Get PNPM store directory
Expand All @@ -58,7 +58,7 @@ jobs:
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-

# Add Cargo cache for torii-wasm
- name: Cache Cargo dependencies and build artifacts
uses: actions/cache@v3
Expand All @@ -74,8 +74,8 @@ jobs:
- run: curl -L https://install.dojoengine.org | bash
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.9.2"
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.2.1
scarb-version: "2.10.1"
- run: /home/runner/.config/.dojo/dojoup/dojoup install v1.5.0-alpha.2
- run: |
cd worlds/dojo-starter
/home/runner/.config/.dojo/bin/sozo build
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
STATUS=$(pnpm changeset status)
echo "Changeset status:"
echo "$STATUS"

# Check if we have packages to bump
if echo "$STATUS" | grep -q "NO packages to be bumped at patch" && \
echo "$STATUS" | grep -q "NO packages to be bumped at minor" && \
Expand All @@ -124,7 +124,7 @@ jobs:
run: |
# Apply version bump based on release type
pnpm changeset version

# If this is a dry run, revert the version changes
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then
echo "DRY RUN: Would version packages to ${NEW_VERSION}"
Expand Down Expand Up @@ -166,4 +166,4 @@ jobs:
TAGS=$(pnpm changeset tag)
echo "DRY RUN: Would commit changes with message: chore: release"
echo "DRY RUN: Would create and push tag: $TAGS"
git status
git status
4 changes: 3 additions & 1 deletion examples/example-node-worker/dojoConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createDojoConfig } from "@dojoengine/core";

import manifest from "../../worlds/dojo-starter/manifest_dev.json";
import manifest from "../../worlds/dojo-starter/manifest_dev.json" with {
type: "json",
};

export const dojoConfig = createDojoConfig({
manifest,
Expand Down
9 changes: 9 additions & 0 deletions examples/example-node-worker/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "dotenv/config";
import { z } from "zod";

const envSchema = z.object({
IDENTITY: z.string(),
SECRET_KEY: z.string(),
});

export const env = envSchema.parse(process.env);
196 changes: 160 additions & 36 deletions examples/example-node-worker/main.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,177 @@
import { init, KeysClause, ToriiQueryBuilder } from "@dojoengine/sdk/node";
import { dojoConfig } from "./dojoConfig";
import {
KeysClause,
ToriiQueryBuilder,
createWorker,
init,
type ParsedEntity,
getModel,
HistoricalToriiQueryBuilder,
} from "@dojoengine/sdk/node";
import { SigningKey } from "@dojoengine/torii-wasm/node";
import { dojoConfig } from "./dojoConfig.ts";
import {
ModelsMapping,
type Moves,
type SchemaType,
} from "./src/typescript/models.gen.ts";
import { addAddressPadding, type BigNumberish } from "starknet";
import { w3cwebsocket } from "websocket";
import { env } from "./env.ts";

// Those lines are require so that websocket works.
// @ts-ignore
global.Websocket = w3cwebsocket;
// @ts-ignore
global.WorkerGlobalScope = global;

Comment on lines +21 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Wrong global identifier: use WebSocket, not Websocket

Browsers (and most polyfills) expose global.WebSocket (uppercase S).
Assigning to Websocket leaves libraries that expect WebSocket undefined.

-// @ts-ignore
-global.Websocket = w3cwebsocket;
+// @ts-ignore
+global.WebSocket = w3cwebsocket;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Those lines are require so that websocket works.
// @ts-ignore
global.Websocket = w3cwebsocket;
// @ts-ignore
global.WorkerGlobalScope = global;
// Those lines are require so that websocket works.
// @ts-ignore
global.WebSocket = w3cwebsocket;
// @ts-ignore
global.WorkerGlobalScope = global;

const sdk = await init({
client: {
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
relayUrl: "/ip4/127.0.0.1/tcp/9092/ws",
worldAddress: dojoConfig.manifest.world.address,
},
domain: {},
domain: {
name: "node-worker",
version: "0.0.1",
chainId: "KATANA",
revision: "1",
},

identity: env.IDENTITY,
signer: SigningKey.fromSecretScalar(env.SECRET_KEY),
});

const query = new ToriiQueryBuilder()
.withClause(
KeysClause(
["dojo_starter-Position", "dojo_starter-Moves"],
[undefined]
).build()
)
.includeHashedKeys();

function onEntityUpdated({ data, error }) {
if (error) {
console.error(error);
return;
type PositionCount = {
Up: number;
Down: number;
Left: number;
Right: number;
};
const defaultPositionCount = {
Up: 0,
Down: 0,
Left: 0,
Right: 0,
};

const positionToU8 = (position: string) => {
const mapping = {
Up: 0,
Down: 1,
Left: 2,
Right: 3,
};

// 10 is used as default value
return mapping[position] ?? 10;
};
const intoPositionCount = (
pos: PositionCount
): Array<[BigNumberish, BigNumberish]> => {
return [
[positionToU8("Up"), `0x${pos.Up.toString(16)}`],
[positionToU8("Down"), `0x${pos.Down.toString(16)}`],
[positionToU8("Left"), `0x${pos.Left.toString(16)}`],
[positionToU8("Right"), `0x${pos.Right.toString(16)}`],
];
};

async function publishOffchainPositionCount(moves: Moves): Promise<void> {
const model = await sdk.getEntities({
query: new ToriiQueryBuilder()
.withClause(
KeysClause(
[ModelsMapping.PositionCount],
[addAddressPadding(moves.player)]
).build()
)
.includeHashedKeys(),
});
const m = getModel(ModelsMapping.PositionCount, model);
if (!m) {
const data = sdk.generateTypedData(
ModelsMapping.PositionCount,
{
identity: moves.player,
position: intoPositionCount(positionCount),
},
[
{
name: "identity",
type: "felt",
},
{
name: "position",
type: "(u8, u128)*",
},
]
);

try {
await sdk.sendMessage(data);
} catch (err) {
console.error(err);
}
} else {
console.log(m.position);
}
}

const entity = data.pop();
if (entity && entity.entityId !== "0x0") {
// do whatever you need here
console.log(entity.models.dojo_starter);
let positionCount = defaultPositionCount;

function initPositionFromEvent(
events: ParsedEntity<SchemaType>[]
): PositionCount {
const pc = defaultPositionCount;
for (const e of events) {
const moved = e.models.dojo_starter.Moved;
if (!moved) {
continue;
}
pc[moved.direction] += 1;
}
return pc;
}
Comment on lines +125 to +133
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

initPositionFromEvent mutates the shared constant

pc is an alias of defaultPositionCount, so every call mutates the constant and all future callers see cumulative side-effects.

-const pc = defaultPositionCount;
+const pc: PositionCount = { ...defaultPositionCount };

This also prevents accidental modification of the default object elsewhere.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const pc = defaultPositionCount;
for (const e of events) {
const moved = e.models.dojo_starter.Moved;
if (!moved) {
continue;
}
pc[moved.direction] += 1;
}
return pc;
const pc: PositionCount = { ...defaultPositionCount };
for (const e of events) {
const moved = e.models.dojo_starter.Moved;
if (!moved) {
continue;
}
pc[moved.direction] += 1;
}
return pc;


const [entities, sub] = await sdk.subscribeEntityQuery({
query,
callback: onEntityUpdated,
historical: false,
});
await createWorker(async () => {
async function onEntityUpdated({ data, error }) {
if (error) {
console.error(error);
return;
}

console.log(entities);
const entity = data.pop();
if (entity && entity.entityId !== "0x0") {
// do whatever you need here
const model = entity.models.dojo_starter;
if (model?.Moves) {
await publishOffchainPositionCount(model.Moves);
}
}
}

Comment on lines +137 to +151
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Potential data loss with data.pop()

data is already the argument supplied by the subscription.
Calling pop() both mutates the array and drops all but the last entity; if multiple entities arrive in the same batch they are silently ignored.

Iterate instead:

for (const entity of data) {
  // handle each entity
}

process.on("SIGTERM", () => {
// NOTE: do not forget to free sub here;
sub.free();
process.exit(0);
});
const query = new HistoricalToriiQueryBuilder()
.withClause(
KeysClause(
[ModelsMapping.Moved, ModelsMapping.Moves],
[undefined]
).build()
)
.includeHashedKeys();

const events = await sdk.getEventMessages({
query: query,
});
positionCount = initPositionFromEvent(events);

const [entities, sub] = await sdk.subscribeEntityQuery({
query,
callback: onEntityUpdated,
});

console.log("Entities from worker", entities);
console.log(positionCount);

process.on("SIGINT", () => {
// NOTE: do not forget to free sub here;
sub.free();
process.exit(0);
return [];
return [sub];
});
Comment on lines +175 to +176
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Unreachable code after the first return

The second return [sub]; can never execute—Biome rightfully flags it.

-    return [];
-    return [sub];
+    return [sub];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return [];
return [sub];
return [sub];
🧰 Tools
🪛 Biome (1.9.4)

[error] 176-176: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

15 changes: 13 additions & 2 deletions examples/example-node-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"bun": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 bun run main.ts",
"node": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 node main.ts",
"build": "tsc -b"
},
Comment on lines +6 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove hardcoded credentials from scripts

The scripts contain hardcoded private keys and identity values, which is a security risk. These should be moved to environment variables loaded from a .env file instead.

    "scripts": {
-        "bun": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 bun run main.ts",
-        "node": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 node main.ts",
+        "bun": "bun run main.ts",
+        "node": "node main.ts",
        "build": "tsc -b"
    },

Since you've already added dotenv as a dependency, you should use it to load these values from a .env file (which should be added to .gitignore).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"scripts": {
"bun": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 bun run main.ts",
"node": "IDENTITY=0x0127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466c3a21fa5cfcec SECRET_KEY=0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912 node main.ts",
"build": "tsc -b"
},
"scripts": {
"bun": "bun run main.ts",
"node": "node main.ts",
"build": "tsc -b"
},
🧰 Tools
🪛 Gitleaks (8.21.2)

7-7: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


8-8: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

"dependencies": {
"@dojoengine/core": "workspace:*",
"@dojoengine/sdk": "workspace:*"
"@dojoengine/sdk": "workspace:*",
"@dojoengine/torii-wasm": "workspace:*",
"dotenv": "^16.4.7",
"starknet": "catalog:",
"websocket": "^1.0.35",
"zod": "^3.24.3"
},
"devDependencies": {
"@types/node": "^22.14.1"
"@types/node": "^22.14.1",
"@types/websocket": "^1.0.10"
}
}
Loading
Loading