Skip to content
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

chore: update sdk #398

Merged
merged 2 commits into from
Feb 19, 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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
run: git submodule update --init --recursive

- run: curl -L https://install.dojoengine.org | bash
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.10
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.9.2"
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.2.1
- run: |
cd worlds/dojo-starter
/home/runner/.config/.dojo/bin/sozo build
Expand Down
1 change: 0 additions & 1 deletion examples/example-vanillajs-phaser-recs/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export async function setup({ ...config }: Config) {
let toriiClient = null;
try {
toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: "",
worldAddress: config.manifest.world.address || "",
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-experimental-sdk/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ async function main() {

const sdk = await init({
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-grpc-playground/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { dojoConfig } from "../dojoConfig.ts";
async function main() {
const sdk = await init({
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
3 changes: 1 addition & 2 deletions examples/example-vite-kitchen-sink/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { dojoConfig } from "../dojoConfig";
import { setupWorld } from "./typescript/contracts.gen";
import { SchemaType } from "./typescript/models.gen";

import { env, getRpcUrl } from "@/env";
import { env } from "@/env";

async function main() {
const sdk = await init<SchemaType>({
client: {
rpcUrl: getRpcUrl(),
toriiUrl: env.VITE_TORII_URL,
relayUrl: env.VITE_RELAY_URL,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-phaser-sdk/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const useDojoStore = createDojoStore<SchemaType>();
async function main() {
const sdk = await init<SchemaType>({
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-react-app-recs/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// Initialize Torii client for interacting with the Dojo network
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: "",
worldAddress: config.manifest.world.address || "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// torii client
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: config.relayUrl,
worldAddress: config.manifest.world.address || "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// torii client
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: config.relayUrl,
worldAddress: config.manifest.world.address || "",
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-react-sdk/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import StarknetProvider from "./starknet-provider.tsx";
async function main() {
const sdk = await init<SchemaType>({
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-react-sql/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ declare module "@tanstack/react-router" {
async function main() {
const sdk = await init<SchemaType>({
client: {
rpcUrl: dojoConfig.rpcUrl,
toriiUrl: dojoConfig.toriiUrl,
relayUrl: dojoConfig.relayUrl,
worldAddress: dojoConfig.manifest.world.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// torii client
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: config.relayUrl,
worldAddress: config.manifest.world.address || "",
Expand Down
1 change: 0 additions & 1 deletion examples/example-vite-svelte-recs/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// torii client
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: "",
worldAddress: config.manifest.world.address || "",
Expand Down
13 changes: 2 additions & 11 deletions examples/example-vue-app-recs/src/dojo/generated/setup.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
createModelTypedData,
DojoConfig,
DojoProvider,
} from "@dojoengine/core";
import { DojoConfig, DojoProvider } from "@dojoengine/core";
import { getSyncEntities } from "@dojoengine/state";
import * as torii from "@dojoengine/torii-client";
import {
ArraySignatureType,
TypedData,
WeierstrassSignatureType,
} from "starknet";
import { ArraySignatureType } from "starknet";

import { createClientComponents } from "../createClientComponents";
import { createSystemCalls } from "../createSystemCalls";
Expand All @@ -22,7 +14,6 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
export async function setup({ ...config }: DojoConfig) {
// torii client
const toriiClient = await torii.createClient({
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: "",
worldAddress: config.manifest.world.address || "",
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/__example__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export const schema: MockSchemaType = {
async function exampleUsage() {
const db = await init<MockSchemaType>({
client: {
rpcUrl: "your-rpc-url",
toriiUrl: "your-torii-url",
relayUrl: "your-relay-url",
worldAddress: "your-world-address",
Expand Down
23 changes: 17 additions & 6 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,31 @@ export async function init<T extends SchemaType>(

/**
* @param {(string)[]} contract_addresses
* @param {string[]} token_ids
* @returns {Promise<Tokens>}
*/
getTokens: async (
contract_addresses: string[]
contract_addresses: string[],
token_ids: string[]
): Promise<torii.Tokens> => {
return await client.getTokens(contract_addresses);
return await client.getTokens(contract_addresses, token_ids);
},

/**
* @param {(string)[]} account_addresses
* @param {(string)[]} contract_addresses
* @param {string[]} token_ids
* @returns {Promise<TokenBalances>}
*/
getTokenBalances: async (
account_addresses: string[],
contract_addresses: string[]
contract_addresses: string[],
token_ids: string[]
): Promise<torii.TokenBalances> => {
return await client.getTokenBalances(
account_addresses,
contract_addresses
contract_addresses,
token_ids
);
},

Expand All @@ -286,6 +291,7 @@ export async function init<T extends SchemaType>(
* # Parameters
* @param {string[]} contract_addresses - Array of contract addresses to filter (empty for all)
* @param {string[]} account_addresses - Array of account addresses to filter (empty for all)
* @param {string[]} token_ids - Array of token ids to filter (empty for all)
* @param {Funtion} callback - JavaScript function to call on updates
*
* # Returns
Expand All @@ -295,11 +301,13 @@ export async function init<T extends SchemaType>(
onTokenBalanceUpdated: (
contract_addresses: string[],
account_addresses: string[],
token_ids: string[],
callback: Function
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace Function type with a more specific callback type.

Using the Function type reduces type safety as it accepts any function-like value. Consider defining a more specific callback type.

Apply this diff to improve type safety:

-callback: Function
+callback: (response: { data?: torii.TokenBalances; error?: Error }) => void
📝 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
callback: Function
callback: (response: { data?: torii.TokenBalances; error?: Error }) => void
🧰 Tools
🪛 Biome (1.9.4)

[error] 305-305: Don't use 'Function' as a type.

Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.

(lint/complexity/noBannedTypes)

): torii.Subscription => {
return client.onTokenBalanceUpdated(
contract_addresses,
account_addresses,
token_ids,
callback
);
},
Expand All @@ -311,6 +319,7 @@ export async function init<T extends SchemaType>(
* @param {torii.Subscription} subscription - Existing subscription to update
* @param {string[]} contract_addresses - New array of contract addresses to filter
* @param {string[]} account_addresses - New array of account addresses to filter
* @param {string[]} token_ids - New array of token ids to filter (empty for all)
*
* # Returns
* Result containing unit or error
Expand All @@ -319,12 +328,14 @@ export async function init<T extends SchemaType>(
updateTokenBalanceSubscription: async (
subscription: torii.Subscription,
contract_addresses: string[],
account_addresses: string[]
account_addresses: string[],
token_ids: string[]
): Promise<void> => {
return await client.updateTokenBalanceSubscription(
subscription,
contract_addresses,
account_addresses
account_addresses,
token_ids
);
},

Expand Down
16 changes: 13 additions & 3 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,24 @@ export interface SDK<T extends SchemaType> {

/**
* @param {string[]} contract_addresses
* @param {string[]} token_ids
* @returns {Promise<torii.Tokens>}
*/
getTokens(contract_addresses: string[]): Promise<torii.Tokens>;
getTokens(
contract_addresses: string[],
token_ids: string[]
): Promise<torii.Tokens>;

/**
* @param {string[]} account_addresses
* @param {string[]} contract_addresses
* @param {string[]} token_ids
* @returns {Promise<torii.TokenBalances>}
*/
getTokenBalances(
account_addresses: string[],
contract_addresses: string[]
contract_addresses: string[],
token_ids: string[]
): Promise<torii.TokenBalances>;

/**
Expand All @@ -344,6 +350,7 @@ export interface SDK<T extends SchemaType> {
* # Parameters
* @param {string[]} contract_addresses - Array of contract addresses to filter (empty for all)
* @param {string[]} account_addresses - Array of account addresses to filter (empty for all)
* @param {string[]} token_ids - Array of token ids to filter (empty for all)
* @param {Funtion} callback - JavaScript function to call on updates
*
* # Returns
Expand All @@ -353,6 +360,7 @@ export interface SDK<T extends SchemaType> {
onTokenBalanceUpdated: (
contract_addresses: string[],
account_addresses: string[],
token_ids: string[],
callback: Function
) => torii.Subscription;

Expand All @@ -363,6 +371,7 @@ export interface SDK<T extends SchemaType> {
* @param {torii.Subscription} subscription - Existing subscription to update
* @param {string[]} contract_addresses - New array of contract addresses to filter
* @param {string[]} account_addresses - New array of account addresses to filter
* @param {string[]} token_ids - New array of token ids to filter
*
* # Returns
* Result containing unit or error
Expand All @@ -371,7 +380,8 @@ export interface SDK<T extends SchemaType> {
updateTokenBalanceSubscription: (
subscription: torii.Subscription,
contract_addresses: string[],
account_addresses: string[]
account_addresses: string[],
token_ids: string[]
) => Promise<void>;

/**
Expand Down
Loading