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 bugs #2653

Merged
merged 1 commit into from
Jan 21, 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
4 changes: 2 additions & 2 deletions client/apps/game/.env.sepolia
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ VITE_PUBLIC_CLIENT_FEE_RECIPIENT=0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd486

VITE_PUBLIC_CHAIN=sepolia
VITE_PUBLIC_SLOT=sepolia-rc-17
VITE_PUBLIC_TORII=https://api.cartridge.gg/x/sepolia-rc-18/torii
VITE_PUBLIC_TORII=https://api.cartridge.gg/x/eternum/torii
VITE_PUBLIC_NODE_URL=https://api.cartridge.gg/x/starknet/sepolia
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Fsepolia-rc-18%2Ftorii%2Fwss
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Feternum%2Ftorii%2Fwss

// optional
VITE_PUBLIC_GAME_VERSION="v1.0.0-rc7"
Expand Down
4 changes: 2 additions & 2 deletions client/apps/game/dojoConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Chain, getGameManifest } from "@/utils/utils";
import { ETERNUM_CONFIG } from "@/utils/config";
import { Chain, getGameManifest } from "@config";
import { createDojoConfig } from "@dojoengine/core";
import { env } from "./env";
import { ETERNUM_CONFIG } from "@/utils/config";

const {
VITE_PUBLIC_NODE_URL,
Expand Down
1 change: 1 addition & 0 deletions client/apps/game/src/dojo/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const initialSync = async (setup: SetupResult, state: AppStore) => {
});

const eternumConfig = await ETERNUM_CONFIG();
console.log({ eternumConfig });
configManager.setDojo(setup.components, eternumConfig);

setLoading(LoadingStateKey.Events, true);
Expand Down
4 changes: 2 additions & 2 deletions client/apps/game/src/three/game-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ export default class GameRenderer {
this.camera.aspect = width / height;
this.camera.updateProjectionMatrix();
this.renderer.setSize(width, height);
this.labelRenderer.setSize(width, height);
this.labelRenderer?.setSize(width, height);
this.hudScene.onWindowResize(width, height);
} else {
// Fallback to window size if container not found
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.labelRenderer.setSize(window.innerWidth, window.innerHeight);
this.labelRenderer?.setSize(window.innerWidth, window.innerHeight);
this.hudScene.onWindowResize(window.innerWidth, window.innerHeight);
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/apps/game/src/ui/modules/rewards/rewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const Rewards = () => {
const [registrationTimeRemaining, setRegistrationTimeRemaining] = useState<string>("");
const [bridgeOutTimeRemaining, setBridgeOutTimeRemaining] = useState<string>("");

const [lordsAddress, setLordsAddress] = useState<string>();
const [lordsAddress, setLordsAddress] = useState<string | undefined>();

useEffect(() => {
const init = async () => {
Expand All @@ -46,7 +46,7 @@ export const Rewards = () => {
init();
}, []);

const prizePool = usePrizePool(lordsAddress || "");
const prizePool = usePrizePool(lordsAddress);
const togglePopup = useUIStore((state) => state.togglePopup);
const isOpen = useUIStore((state) => state.isPopupOpen(rewards));

Expand Down
2 changes: 1 addition & 1 deletion client/apps/game/src/utils/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain, getSeasonAddresses } from "@config";
import { env } from "../../env";
import { Chain, getSeasonAddresses } from "./utils";

export const getResourceAddresses = async () => {
const addresses = (await getSeasonAddresses(env.VITE_PUBLIC_CHAIN as Chain)).resources;
Expand Down
4 changes: 2 additions & 2 deletions client/apps/game/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getConfigFromNetwork, type NetworkType } from "../../../../../config/utils/environment";
import { Chain, getConfigFromNetwork } from "@config";
import { env } from "./../../env";

export const ETERNUM_CONFIG = async () => {
const config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN! as NetworkType);
const config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN! as Chain);
return config;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for environment variable.

The non-null assertion operator (!) assumes env.VITE_PUBLIC_CHAIN will always be defined. Add a validation check to handle undefined cases gracefully.

-  const config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN! as Chain);
+  if (!env.VITE_PUBLIC_CHAIN) {
+    throw new Error('VITE_PUBLIC_CHAIN environment variable is not defined');
+  }
+  const config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN as Chain);
📝 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 config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN! as Chain);
if (!env.VITE_PUBLIC_CHAIN) {
throw new Error('VITE_PUBLIC_CHAIN environment variable is not defined');
}
const config = await getConfigFromNetwork(env.VITE_PUBLIC_CHAIN as Chain);

};
84 changes: 0 additions & 84 deletions client/apps/game/src/utils/utils.ts

This file was deleted.

5 changes: 3 additions & 2 deletions client/apps/game/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
"@/*": ["src/*"],
"@config": ["../../../config/utils/utils"]
},
"target": "ESNext",
"useDefineForClassFields": true,
Expand All @@ -24,7 +25,7 @@
"jsx": "react-jsx",
"types": ["vite-plugin-svgr/client", "@types/node"]
},
"include": ["src", "eternumConfig.tsx"],
"include": ["src", "../../../config/utils/utils"],
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Incorrect include pattern needs to be updated

The current include pattern "../../../config/utils/utils" is incorrect as:

  • The path doesn't exist in this structure
  • The actual utils files are located at config/utils/
  • Only environment utils appear to be used (REALM_MAX_LEVEL)

Consider updating to either:

  • "config/utils" if you need all utility files
  • "config/environments/utils" if you only need environment-specific utilities
🔗 Analysis chain

Consider more specific include patterns.

Including the entire config/utils/utils directory might bring in unnecessary files during compilation. Consider using more specific patterns or organizing the config files to minimize the compilation scope.

Let's analyze the directory contents:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# List all files in the config utils directory to assess compilation impact
fd --type f "." "../../../config/utils/utils"

# Check TypeScript file count and types
fd --type f -e ts -e tsx "." "../../../config/utils/utils" | wc -l

Length of output: 340


Script:

#!/bin/bash
# Find the utils directory
fd -t d "utils$" "config"

# Once we find it, let's see what files are in there
fd -t f "." "config/utils" || true

# Check for imports from utils in the game app
rg -g "*.{ts,tsx}" "from.*utils" "client/apps/game/src" || true

Length of output: 16137

"exclude": ["node_modules", "./node_modules", "./node_modules/*", "src/node_modules", "dist", "**/*.spec.ts"],
"references": [
{
Expand Down
1 change: 1 addition & 0 deletions client/apps/game/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default defineConfig({
"@/assets": path.resolve(__dirname, "../../public/assets"),
events: "events",
"@": path.resolve(__dirname, "./src"),
"@config": path.resolve(__dirname, "../../../config/utils/utils"),
},
},
build: {
Expand Down
2 changes: 1 addition & 1 deletion client/apps/landing/.env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ VITE_PUBLIC_CHAIN=sepolia
VITE_PUBLIC_SLOT=sepolia-rc-17
VITE_PUBLIC_TORII=http://localhost:8080/
VITE_PUBLIC_NODE_URL=https://api.cartridge.gg/x/starknet/sepolia
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Fsepolia-rc-18%2Ftorii%2Fwss
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Feternum%2Ftorii%2Fwss

// optional
VITE_PUBLIC_GAME_VERSION="v1.0.0-rc7"
Expand Down
4 changes: 2 additions & 2 deletions client/apps/landing/.env.slot
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ VITE_PUBLIC_MASTER_ADDRESS="0x127fd5f1fe78a71f8bcd1fec63e3fe2f0486b6ecd5c86a0466
VITE_PUBLIC_MASTER_PRIVATE_KEY="0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912"
VITE_PUBLIC_ACCOUNT_CLASS_HASH="0x07dc7899aa655b0aae51eadff6d801a58e97dd99cf4666ee59e704249e51adf2"
VITE_PUBLIC_FEE_TOKEN_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_TORII=https://api.cartridge.gg/x/sepolia-rc-18/torii
VITE_PUBLIC_TORII=https://api.cartridge.gg/x/eternum/torii
VITE_PUBLIC_NODE_URL=https://api.cartridge.gg/x/starknet/sepolia
VITE_PUBLIC_GAME_VERSION="v1.0.0-rc7"
VITE_PUBLIC_GRAPHICS_DEV=false
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Fsepolia-rc-18%2Ftorii%2Fwss
VITE_PUBLIC_TORII_RELAY=/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Feternum%2Ftorii%2Fwss

VITE_PUBLIC_CHAIN=sepolia
VITE_PUBLIC_SLOT=
Expand Down
2 changes: 1 addition & 1 deletion client/apps/landing/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dotenvConfig({ path: "./.env.local" }); //Change for production?

const config: CodegenConfig = {
overwrite: true,
schema: "https://api.cartridge.gg/x/sepolia-rc-18/torii" + "/graphql",
schema: "https://api.cartridge.gg/x/eternum/torii" + "/graphql",
documents: "src/**/*.tsx",
ignoreNoDocuments: true,
generates: {
Expand Down
9 changes: 2 additions & 7 deletions config/deployer/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { EternumProvider } from "@bibliothecadao/eternum";
import { Account } from "starknet";
import { confirmNonLocalDeployment } from "../utils/confirmation";
import {
getConfigFromNetwork,
logNetwork,
saveConfigJsonFromConfigTsFile,
type NetworkType,
} from "../utils/environment";
import { getGameManifest, type Chain } from "../utils/utils";
import { logNetwork, saveConfigJsonFromConfigTsFile, type NetworkType } from "../utils/environment";
import { getConfigFromNetwork, getGameManifest, type Chain } from "../utils/utils";
Comment on lines +4 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix type inconsistency and add environment validation.

Issues found:

  1. Inconsistent use of NetworkType and Chain types
  2. Multiple non-null assertions without validation
  3. Type mismatch in getConfigFromNetwork call (expects Chain but receives NetworkType)
-import { logNetwork, saveConfigJsonFromConfigTsFile, type NetworkType } from "../utils/environment";
-import { getConfigFromNetwork, getGameManifest, type Chain } from "../utils/utils";
+import { logNetwork, saveConfigJsonFromConfigTsFile } from "../utils/environment";
+import { getConfigFromNetwork, getGameManifest, type Chain } from "../utils/utils";

+// Validate environment variables
+const requiredEnvVars = {
+  VITE_PUBLIC_MASTER_ADDRESS,
+  VITE_PUBLIC_MASTER_PRIVATE_KEY,
+  VITE_PUBLIC_NODE_URL,
+  VITE_PUBLIC_CHAIN,
+  VITE_PUBLIC_VRF_PROVIDER_ADDRESS,
+} as const;
+
+Object.entries(requiredEnvVars).forEach(([key, value]) => {
+  if (!value) throw new Error(`Missing required environment variable: ${key}`);
+});

-await saveConfigJsonFromConfigTsFile(VITE_PUBLIC_CHAIN! as NetworkType);
-const configuration = await getConfigFromNetwork(VITE_PUBLIC_CHAIN! as NetworkType);
+await saveConfigJsonFromConfigTsFile(VITE_PUBLIC_CHAIN as Chain);
+const configuration = await getConfigFromNetwork(VITE_PUBLIC_CHAIN as Chain);

Also applies to: 24-25

import { GameConfigDeployer } from "./config";

const {
Expand Down
27 changes: 0 additions & 27 deletions config/utils/environment.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
import type { Config } from "@bibliothecadao/eternum";
export type NetworkType = "local" | "sepolia" | "slot" | "mainnet";
/**
* Loads the environment-specific configuration based on the network type.
*
* @async
* @remarks
* Configuration files must follow these naming conventions:
* - Located in environments/ directory
* - Named exactly as the NetworkType: local.ts, sepolia.ts, slot.ts, mainnet.ts
* - Must export a default Config object
*
* @throws {Error} If the configuration file cannot be loaded
*
* @example
* ```typescript
* const config = await getConfigFromNetwork('local'); // loads from environments/local.ts
* ```
*/
export async function getConfigFromNetwork(chain: NetworkType): Promise<Config> {
const CONFIGURATION_FILE = `../environments/data/${chain}.json`;
try {
const configurationJson = (await import(CONFIGURATION_FILE)).default;
return configurationJson.configuration;
} catch (error) {
throw new Error(`Failed to load configuration for chain ${chain}: ${error}`);
}
}

export async function saveConfigJsonFromConfigTsFile(chain: NetworkType) {
const fs = require("fs");
Expand Down
29 changes: 28 additions & 1 deletion config/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SeasonAddresses } from "@bibliothecadao/eternum";
import type { Config, SeasonAddresses } from "@bibliothecadao/eternum";

/** Valid chain identifiers */
export type Chain = "local" | "sepolia" | "mainnet" | "slot";
Expand Down Expand Up @@ -40,3 +40,30 @@ export async function getGameManifest(chain: Chain): Promise<GameManifest> {
throw new Error(`Failed to load game manifest for chain ${chain}: ${error}`);
}
}

/**
* Loads the environment-specific configuration based on the network type.
*
* @async
* @remarks
* Configuration files must follow these naming conventions:
* - Located in environments/ directory
* - Named exactly as the NetworkType: local.ts, sepolia.ts, slot.ts, mainnet.ts
* - Must export a default Config object
*
* @throws {Error} If the configuration file cannot be loaded
*
* @example
* ```typescript
* const config = await getConfigFromNetwork('local'); // loads from environments/local.ts
* ```
*/
export async function getConfigFromNetwork(chain: Chain): Promise<Config> {
const CONFIGURATION_FILE = `../environments/data/${chain}.json`;
try {
const configurationJson = (await import(/* @vite-ignore */ CONFIGURATION_FILE)).default;
return configurationJson.configuration;
} catch (error) {
throw new Error(`Failed to load configuration for chain ${chain}: ${error}`);
}
}
2 changes: 1 addition & 1 deletion contracts/common/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ echo "Migrating world..."
sozo migrate --profile mainnet --fee eth

echo "Setting up remote indexer on slot..."
slot deployments create -t epic sepolia-rc-18 torii --version v1.0.7 --world 0x3dc74e8caadbde233bb750a6608e095daba2891d9784ea0fb7fbf9988948c15 --rpc https://api.cartridge.gg/x/starknet/sepolia --indexing.pending true --config ./torii-sepolia.toml
slot deployments create -t epic eternum torii --version v1.0.7 --world 0x3dc74e8caadbde233bb750a6608e095daba2891d9784ea0fb7fbf9988948c15 --rpc https://api.cartridge.gg/x/starknet/sepolia --indexing.pending true --config ./torii-sepolia.toml
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update config file path in deployment command

The deployment configuration is correct, but the config file path needs to be updated:

- slot deployments create -t epic eternum torii --version v1.0.7 --world 0x3dc74e8caadbde233bb750a6608e095daba2891d9784ea0fb7fbf9988948c15 --rpc https://api.cartridge.gg/x/starknet/sepolia --indexing.pending true --config ./torii-sepolia.toml
+ slot deployments create -t epic eternum torii --version v1.0.7 --world 0x3dc74e8caadbde233bb750a6608e095daba2891d9784ea0fb7fbf9988948c15 --rpc https://api.cartridge.gg/x/starknet/sepolia --indexing.pending true --config contracts/game/torii-sepolia.toml

Note: Using sepolia RPC and config is correct as this is deploying eternum (the game) to the sepolia network.

🔗 Analysis chain

Verify deployment configuration consistency.

The deployment command shows potential inconsistencies:

  1. Using eternum as deployment target but still referencing sepolia RPC URL
  2. Using torii-sepolia.toml config file for eternum deployment
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if sepolia config file contains eternum-specific settings

# Check if the config file contains any sepolia-specific settings
rg -i "sepolia" ./torii-sepolia.toml

# List all configuration files to see if there's an eternum-specific one
fd -e toml

Length of output: 18136


Script:

#!/bin/bash
# Check contents of sepolia config and search for eternum-specific files/settings
cat contracts/game/torii-sepolia.toml

# Search for eternum-specific config files
fd -t f -e toml eternum
fd -t f -e toml torii

# Search for eternum configuration references in the codebase
rg -i "eternum.*config" -A 5

Length of output: 75610


echo "Setting up config..."

Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/modelManager/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export class ClientConfigManager {
public setDojo(components: ContractComponents, config: Config) {
this.components = components;
this.config = config;

console.log("setting dojo for config manager");

this.initializeResourceInputs();
this.initializeResourceOutput();
this.initializeHyperstructureTotalCosts();
this.initializeRealmUpgradeCosts();
this.initializeResourceBuildingCosts();
this.initializeBuildingCosts();
this.initializeStructureCosts();

console.log({ resourceBuildingCosts: this.resourceBuildingCosts });
}

public static instance(): ClientConfigManager {
Expand Down Expand Up @@ -87,7 +92,6 @@ export class ClientConfigManager {

// this.resourceInputs[Number(resourceType)] = inputs;
// }
return ;
this.resourceInputs = Object.entries(this.config.resources.resourceInputs).reduce(
(acc, [key, inputs]) => {
acc[Number(key)] = inputs.map((input: { resource: number; amount: number }) => ({
Expand Down Expand Up @@ -163,7 +167,6 @@ export class ClientConfigManager {
// }
// this.realmUpgradeCosts[index] = resources;
// }
return;
this.realmUpgradeCosts = Object.fromEntries(
Object.entries(this.config.realmUpgradeCosts).map(([key, costs]) => [
key,
Expand Down Expand Up @@ -200,7 +203,6 @@ export class ClientConfigManager {
// this.resourceBuildingCosts[Number(resourceId)] = resourceCosts;

// }
return;
this.resourceBuildingCosts = Object.fromEntries(
Object.entries(this.config.resources.resourceBuildingCosts).map(([key, costs]) => [
key,
Expand Down Expand Up @@ -238,7 +240,6 @@ export class ClientConfigManager {
// }
// this.buildingCosts[Number(buildingType)] = resourceCosts;
// }
return;
this.buildingCosts = Object.fromEntries(
Object.entries(this.config.buildings.buildingCosts).map(([key, costs]) => [
key,
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/hooks/helpers/use-rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { configManager } from "@bibliothecadao/eternum";
import { useEffect, useState } from "react";
import { useDojo } from "../";

export const usePrizePool = (lordsAddress: string) => {
export const usePrizePool = (lordsAddress: string | undefined) => {
const [prizePool, setPrizePool] = useState<bigint>(0n);

const {
account: { account },
} = useDojo();

const getBalance = async (address: string) => {
if (!lordsAddress) return;
const balance = await account?.callContract({
contractAddress: lordsAddress,
entrypoint: "balance_of",
Expand Down Expand Up @@ -50,7 +51,7 @@ export const usePrizePool = (lordsAddress: string) => {
const interval = setInterval(getPrizePool, 60000); // Every minute

return () => clearInterval(interval);
}, []);
}, [lordsAddress]);

return prizePool;
};
Loading