Skip to content

fix: use starknet.shortstring.encodeShortString instead of torii-wasm… #448

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
Jun 6, 2025

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Jun 6, 2025

… equivalent

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • Refactor
    • Standardized short string encoding across multiple packages by switching to the StarkNet-provided implementation.
    • Unified internal logic for building query clauses, consolidating code for improved maintainability.
  • Chores
    • Updated import and export paths for clause builder utilities to use a shared internal module.
    • Removed redundant files and adjusted type imports for clarity and efficiency.

Copy link

coderabbitai bot commented Jun 6, 2025

Walkthrough

This change standardizes short string encoding across multiple Dojo Engine packages by switching from the torii-wasm implementation to starknet.shortstring.encodeShortString. The clause builder utility was relocated from platform-specific files to a shared internal module, with corresponding updates to import and export paths and removal of the original web-specific file.

Changes

File(s) Change Summary
.changeset/sharp-rocks-enjoy.md Documents the switch to starknet.shortstring.encodeShortString for short string encoding across packages.
packages/sdk/src/__tests__/clauseBuilder.test.ts,
packages/sdk/src/__tests__/toriiQueryBuilder.test.ts
Updated imports for ClauseBuilder and related types to use the new internal module path.
packages/sdk/src/internal/clauseBuilder.ts Replaced cairoShortStringToFelt with shortString.encodeShortString; updated value conversion logic.
packages/sdk/src/node/index.ts,
packages/sdk/src/web/index.ts
Changed clauseBuilder exports to reference the internal shared module instead of platform-specific files.
packages/sdk/src/web/clauseBuilder.ts Deleted the web-specific clause builder implementation; logic moved to internal module.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ClauseBuilder (internal)
    participant starknet.shortString

    Caller->>ClauseBuilder (internal): Build clause with string value
    ClauseBuilder (internal)->>starknet.shortString: encodeShortString(value)
    starknet.shortString-->>ClauseBuilder (internal): Encoded value
    ClauseBuilder (internal)-->>Caller: Return clause with encoded value
Loading

Possibly related PRs

Poem

In the garden of code where short strings roam,
We swapped the keys to give them a new home.
From torii’s path to starknet’s gate,
Our clauses now encode first-rate!
The web file’s gone, but don’t you fear—
The builder’s heart beats strong and clear.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/sdk/src/internal/clauseBuilder.ts (1)

149-152: Verify encodeShortString integration in convertToPrimitive
Ensure that passing shortString.encodeShortString as the conversion callback preserves the expected behavior for plain string values and properly encodes shortstrings. Consider adding a unit test that exercises a MemberClause with a short string value to confirm the encoded FELT output matches expectations.

.changeset/sharp-rocks-enjoy.md (1)

15-15: Remove commit-type prefix from summary
Changeset summaries are rendered as release notes—no need for a fix: or other conventional commit tag. Consider rewriting to something like:
“Use starknet.shortstring.encodeShortString instead of the torii-wasm implementation.”

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36e5188 and 174e200.

📒 Files selected for processing (7)
  • .changeset/sharp-rocks-enjoy.md (1 hunks)
  • packages/sdk/src/__tests__/clauseBuilder.test.ts (1 hunks)
  • packages/sdk/src/__tests__/toriiQueryBuilder.test.ts (1 hunks)
  • packages/sdk/src/internal/clauseBuilder.ts (2 hunks)
  • packages/sdk/src/node/index.ts (1 hunks)
  • packages/sdk/src/web/clauseBuilder.ts (0 hunks)
  • packages/sdk/src/web/index.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/sdk/src/web/clauseBuilder.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: check
🔇 Additional comments (5)
packages/sdk/src/__tests__/toriiQueryBuilder.test.ts (1)

5-5: Update import path for ClauseBuilder
The test now correctly references the relocated clauseBuilder from the internal module.

packages/sdk/src/node/index.ts (1)

32-32: Update export to use internal ClauseBuilder
Switching the export to the shared internal module aligns with the consolidation of clauseBuilder.

packages/sdk/src/internal/clauseBuilder.ts (1)

11-11: Import shortString from StarkNet
Pulling in the StarkNet-provided shortString for encoding is correct and replaces the previous WASM-based function.

packages/sdk/src/web/index.ts (1)

35-35: Update export to use internal ClauseBuilder
Re-exporting from ../internal/clauseBuilder correctly reflects the removal of the web-specific implementation.

packages/sdk/src/__tests__/clauseBuilder.test.ts (1)

7-12: Update imports to the internal clauseBuilder module
All runtime and type-only imports have been adjusted to point at the shared internal implementation. The use of import type for purely type annotations is appropriate.

Comment on lines +2 to +12
"@dojoengine/sdk": patch
"@dojoengine/core": patch
"@dojoengine/create-burner": patch
"@dojoengine/create-dojo": patch
"@dojoengine/predeployed-connector": patch
"@dojoengine/react": patch
"@dojoengine/state": patch
"@dojoengine/torii-client": patch
"@dojoengine/torii-wasm": patch
"@dojoengine/utils": patch
"@dojoengine/utils-wasm": patch
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify package bump scope
Ensure you’re only bumping versions for packages that actually include code changes. Unnecessary version bumps across unrelated packages (e.g., @dojoengine/core, @dojoengine/react, etc.) can lead to noise and unintended releases.

Run the following script to list which packages have real file changes and confirm alignment with this changeset:

Compare the output to your list and prune any packages that didn’t change.


🏁 Script executed:

#!/bin/bash
# Identify packages with changes since main
base=$(git merge-base HEAD origin/main)
git diff --name-only $base HEAD \
  | grep '^packages/' \
  | cut -d'/' -f2 \
  | sort -u

Length of output: 199


Prune unchanged packages from this changeset
Only @dojoengine/sdk has file changes since main. Please remove all other package bumps from .changeset/sharp-rocks-enjoy.md.

  • File: .changeset/sharp-rocks-enjoy.md (lines 2–12)
  • Remove entries for unaffected packages

Suggested diff:

@@ .changeset/sharp-rocks-enjoy.md
- "@dojoengine/core": patch
- "@dojoengine/create-burner": patch
- "@dojoengine/create-dojo": patch
- "@dojoengine/predeployed-connector": patch
- "@dojoengine/react": patch
- "@dojoengine/state": patch
- "@dojoengine/torii-client": patch
- "@dojoengine/torii-wasm": patch
- "@dojoengine/utils": patch
- "@dojoengine/utils-wasm": patch

Leave only:

"@dojoengine/sdk": patch
🤖 Prompt for AI Agents
In the file .changeset/sharp-rocks-enjoy.md between lines 2 and 12, the
changeset currently lists version bumps for multiple packages, but only
@dojoengine/sdk has actual code changes. Remove all other package entries from
this changeset so that only "@dojoengine/sdk": patch remains, ensuring the
changeset accurately reflects the packages with real modifications.

@MartianGreed MartianGreed merged commit fd36752 into main Jun 6, 2025
6 checks passed
@MartianGreed MartianGreed deleted the fix/sn-shortstring-encode branch June 6, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant