@dojoengine/core
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "@dojoengine/core", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Dojo engine core providers and types", | ||
@@ -14,2 +14,3 @@ "scripts": { | ||
"@types/elliptic": "^6.4.14", | ||
"@latticexyz/recs": "^1.43.0", | ||
"@types/events": "^3.0.0", | ||
@@ -22,14 +23,12 @@ "@types/jest": "^29.5.0", | ||
"graphql-request": "^6.1.0", | ||
"graphql-tag": "^2.12.6", | ||
"jest": "^29.5.0", | ||
"micro-starknet": "^0.2.3", | ||
"mobx": "^6.9.0", | ||
"rxjs": "^7.8.1", | ||
"starknet": "^4.22.0", | ||
"ts-jest": "^29.1.0", | ||
"typescript": "^5.0.3", | ||
"winston": "^3.8.2", | ||
"@latticexyz/recs": "^1.43.0", | ||
"@latticexyz/utils": "^1.36.1\n", | ||
"mobx": "^6.9.0", | ||
"rxjs": "^7.8.1", | ||
"type-fest": "^3.12.0" | ||
"type-fest": "^3.12.0", | ||
"typescript": "^5.0.3" | ||
} | ||
} | ||
} |
export const KATANA_ACCOUNT_1_ADDRESS = "0x06f62894bfd81d2e396ce266b2ad0f21e0668d604e5bb1077337b6d570a54aea" | ||
export const KATANA_ACCOUNT_1_PRIVATEKEY = "0x07230b49615d175307d580c33d6fda61fc7b9aec91df0f5c1a5ebe3b8cbfee02" | ||
export const LOCAL_TORII = 'http://127.0.0.1:5050'; | ||
export const LOCAL_KATANA = 'http://127.0.0.1:5050'; | ||
export const DOJO_STARTER_WORLD = "0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84" |
@@ -1,6 +0,4 @@ | ||
import * as Providers from './provider'; | ||
import * as Account from './account' | ||
import { RPCProvider } from './provider'; | ||
import * as Utils from './utils' | ||
import { SyncWorker } from './network/SyncWorker'; | ||
import type { Query } from './types'; | ||
export { Providers, Account, Utils, Query, SyncWorker }; | ||
export { RPCProvider, Utils, Query }; |
@@ -1,3 +0,1 @@ | ||
import { RPCProvider } from "./RPCProvider"; | ||
import { WebSocketProvider } from "./WSProvider"; | ||
export { RPCProvider, WebSocketProvider }; | ||
export { RPCProvider } from "./RPCProvider"; |
@@ -1,6 +0,6 @@ | ||
import { RpcProvider, Provider as StarknetProvider, Account, stark, number, Call, InvokeFunctionResponse } from "starknet"; | ||
import { RpcProvider, Provider as StarknetProvider, Account, number, Call, InvokeFunctionResponse } from "starknet"; | ||
import { Provider } from "./provider"; | ||
import { Query, WorldEntryPoints } from "../types"; | ||
import { strTofelt252Felt } from '../utils' | ||
import { LOCAL_TORII } from '../constants'; | ||
import { LOCAL_KATANA } from '../constants'; | ||
@@ -12,3 +12,3 @@ export class RPCProvider extends Provider { | ||
constructor(world_address: string, url: string = LOCAL_TORII, loggingEnabled = false) { | ||
constructor(world_address: string, url: string = LOCAL_KATANA, loggingEnabled = false) { | ||
super(world_address); | ||
@@ -49,4 +49,2 @@ this.provider = new RpcProvider({ | ||
console.log(call) | ||
try { | ||
@@ -69,4 +67,2 @@ const response = await this.sequencerProvider.callContract(call); | ||
console.log(call) | ||
try { | ||
@@ -100,8 +96,2 @@ const response = await this.sequencerProvider.callContract(call); | ||
// DISCUSS: is this needed? | ||
// let call_data_obj = call_data.reduce((obj: any, item, index) => { | ||
// obj[index] = item; | ||
// return obj; | ||
// }, {}); | ||
try { | ||
@@ -117,3 +107,3 @@ const nonce = await account?.getNonce() | ||
{ | ||
nonce: nonce, | ||
nonce, | ||
maxFee: 0 // TODO: Update | ||
@@ -120,0 +110,0 @@ } |
@@ -1,5 +0,1 @@ | ||
import { EntityIndex, setComponent, Component, Schema, Components } from "@latticexyz/recs"; | ||
import { Event } from "starknet"; | ||
import { poseidonHashMany } from 'micro-starknet'; | ||
export function strTofelt252Felt(str: string): string { | ||
@@ -32,85 +28,1 @@ const encoder = new TextEncoder(); | ||
// DISCUSSION: MUD expects Numbers, but entities in Starknet are BigInts (from poseidon hash) | ||
// so I am converting them to Numbers here, but it means that there is a bigger risk of collisions | ||
export function getEntityIdFromKeys(keys: bigint[]): EntityIndex { | ||
if (keys.length === 1) { | ||
return parseInt(keys[0].toString()) as EntityIndex; | ||
} | ||
// calculate the poseidon hash of the keys | ||
let poseidon = poseidonHashMany([BigInt(keys.length), ...keys]); | ||
return parseInt(poseidon.toString()) as EntityIndex; | ||
} | ||
export function setComponentFromEntitiesQuery(component: Component, entities: bigint[]) { | ||
let index = 0; | ||
// Retrieve the number of entityIds | ||
const numEntityIds = Number(entities[index++]); | ||
// Retrieve entityIds | ||
const entityIds = entities.slice(index, index + numEntityIds); | ||
index += numEntityIds; | ||
// Retrieve the number of entities with component values | ||
const numEntities = Number(entities[index++]); | ||
for (let i = 0; i < numEntities; i++) { | ||
// Retrieve the number of component values for the current entity | ||
const numValues = Number(entities[index++]); | ||
// Retrieve entity's component values | ||
const valueArray = entities.slice(index, index + numValues) | ||
const componentValues = Object.keys(component.schema).reduce((acc: Schema, key, index) => { | ||
const value = valueArray[index]; | ||
acc[key] = Number(value); | ||
return acc; | ||
}, {}); | ||
const entityIndex = parseInt(entityIds[i].toString()) as EntityIndex; | ||
setComponent(component, entityIndex, componentValues) | ||
index += numValues; | ||
} | ||
} | ||
export function setComponentFromEvent(components: Components, eventData: string[]) { | ||
// retrieve the component name | ||
const componentName = hex_to_ascii(eventData[0]); | ||
// retrieve the component from name | ||
const component = components[componentName]; | ||
// get keys | ||
const keysNumber = parseInt(eventData[1]); | ||
let index = 2 + keysNumber + 1; | ||
const keys = eventData.slice(2, 2 + keysNumber).map((key) => BigInt(key)); | ||
// get entityIndex from keys | ||
const entityIndex = getEntityIdFromKeys(keys); | ||
// get values | ||
let numberOfValues = parseInt(eventData[index++]); | ||
// get values | ||
const values = eventData.slice(index, index + numberOfValues); | ||
// create component object from values with schema | ||
const componentValues = Object.keys(component.schema).reduce((acc: Schema, key, index) => { | ||
const value = values[index]; | ||
acc[key] = Number(value); | ||
return acc; | ||
}, {}); | ||
// set component | ||
setComponent(component, entityIndex, componentValues); | ||
} | ||
function hex_to_ascii(hex: string) { | ||
var str = ''; | ||
for (var n = 2; n < hex.length; n += 2) { | ||
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); | ||
} | ||
return str; | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "ESNext", | ||
"target": "esnext", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"moduleResolution": "bundler", | ||
"outDir": "./dist", | ||
@@ -8,0 +7,0 @@ "strict": true, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28616
18
37
745
1