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

Fix counter + client optimisations #2417

Merged
merged 16 commits into from
Dec 11, 2024
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
7 changes: 6 additions & 1 deletion client/dojoConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createDojoConfig } from "@dojoengine/core";
import devManifest from "../contracts/manifest_dev.json";
import mainnetManifest from "../contracts/manifest_mainnet.json";
import productionManifest from "../contracts/manifest_prod.json";

import { env } from "./env";
const {
VITE_PUBLIC_NODE_URL,
Expand All @@ -11,9 +13,12 @@ const {
VITE_PUBLIC_ACCOUNT_CLASS_HASH,
VITE_PUBLIC_DEV,
VITE_PUBLIC_FEE_TOKEN_ADDRESS,
VITE_PUBLIC_CHAIN
} = env;

const manifest = VITE_PUBLIC_DEV === true ? devManifest : productionManifest;
let manifest = VITE_PUBLIC_DEV === true ? devManifest : productionManifest;

manifest = VITE_PUBLIC_CHAIN === "mainnet" ? mainnetManifest : manifest;

export const dojoConfig = createDojoConfig({
rpcUrl: VITE_PUBLIC_NODE_URL,
Expand Down
2 changes: 1 addition & 1 deletion client/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const envSchema = z.object({
VITE_PUBLIC_ACCOUNT_CLASS_HASH: z.string().startsWith("0x"),
VITE_PUBLIC_FEE_TOKEN_ADDRESS: z.string().startsWith("0x"),

VITE_CLIENT_FEE_RECIPIENT: z.string().startsWith("0x"),
VITE_PUBLIC_CLIENT_FEE_RECIPIENT: z.string().startsWith("0x"),

// External Contracts
VITE_SEASON_PASS_ADDRESS: z.string().startsWith("0x"),
Expand Down
23 changes: 13 additions & 10 deletions client/src/dojo/modelManager/ResourceInventoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { uuid } from "@latticexyz/utils";
import { type SetupResult } from "../setup";

export class ResourceInventoryManager {
entityId: ID;
carrierEntityId: ID;

constructor(
private readonly setup: SetupResult,
entityId: ID,
carrierEntityId: ID,
) {
this.entityId = entityId;
this.carrierEntityId = carrierEntityId;
}

private readonly _optimisticOffloadAll = (
Expand All @@ -21,32 +21,35 @@ export class ResourceInventoryManager {
inventoryResources: Resource[],
) => {
inventoryResources.forEach((resource) => {
const entity = getEntityIdFromKeys([BigInt(receiverEntityId), BigInt(resource.resourceId)]);
const receiverBalance = getComponentValue(this.setup.components.Resource, entity)?.balance || 0n;
const receiveResourceEntity = getEntityIdFromKeys([BigInt(receiverEntityId), BigInt(resource.resourceId)]);
const receiverBalance = getComponentValue(this.setup.components.Resource, receiveResourceEntity)?.balance || 0n;

// optimistically update the balance of the receiver
this.setup.components.Resource.addOverride(overrideId, {
entity,
entity: receiveResourceEntity,
value: {
entity_id: receiverEntityId,
resource_type: resource.resourceId,
balance: receiverBalance + BigInt(resource.amount),
},
});
});

const entity = getEntityIdFromKeys([BigInt(this.entityId)]);
const carrierEntity = getEntityIdFromKeys([BigInt(this.carrierEntityId)]);

this.setup.components.Weight.addOverride(overrideId, {
entity,
entity: carrierEntity,
value: {
entity_id: this.carrierEntityId,
value: 0n,
},
});

// need to update this for the arrivals list to get updated
this.setup.components.OwnedResourcesTracker.addOverride(overrideId, {
entity,
entity: carrierEntity,
value: {
entity_id: this.carrierEntityId,
resource_types: 0n,
},
});
Expand All @@ -59,7 +62,7 @@ export class ResourceInventoryManager {
if (inventoryResources.length > 0) {
await this.setup.systemCalls
.send_resources({
sender_entity_id: this.entityId,
sender_entity_id: this.carrierEntityId,
recipient_entity_id: receiverEntityId,
resources: inventoryResources.flatMap((resource) => [resource.resourceId, resource.amount]),
signer: useAccountStore.getState().account!,
Expand Down
Loading
Loading