diff --git a/client/apps/game/.env.sepolia b/client/apps/game/.env.sepolia index 384481578..ad7c60e39 100644 --- a/client/apps/game/.env.sepolia +++ b/client/apps/game/.env.sepolia @@ -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" diff --git a/client/apps/game/dojoConfig.ts b/client/apps/game/dojoConfig.ts index 5526ab7fa..b13c1b151 100644 --- a/client/apps/game/dojoConfig.ts +++ b/client/apps/game/dojoConfig.ts @@ -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, diff --git a/client/apps/game/src/dojo/sync.ts b/client/apps/game/src/dojo/sync.ts index 2aec0519b..3fcf6e6eb 100644 --- a/client/apps/game/src/dojo/sync.ts +++ b/client/apps/game/src/dojo/sync.ts @@ -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); diff --git a/client/apps/game/src/three/game-renderer.ts b/client/apps/game/src/three/game-renderer.ts index 948bd39e2..553316f58 100644 --- a/client/apps/game/src/three/game-renderer.ts +++ b/client/apps/game/src/three/game-renderer.ts @@ -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); } } diff --git a/client/apps/game/src/ui/modules/rewards/rewards.tsx b/client/apps/game/src/ui/modules/rewards/rewards.tsx index 6fdd6332d..543046619 100644 --- a/client/apps/game/src/ui/modules/rewards/rewards.tsx +++ b/client/apps/game/src/ui/modules/rewards/rewards.tsx @@ -36,7 +36,7 @@ export const Rewards = () => { const [registrationTimeRemaining, setRegistrationTimeRemaining] = useState(""); const [bridgeOutTimeRemaining, setBridgeOutTimeRemaining] = useState(""); - const [lordsAddress, setLordsAddress] = useState(); + const [lordsAddress, setLordsAddress] = useState(); useEffect(() => { const init = async () => { @@ -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)); diff --git a/client/apps/game/src/utils/addresses.ts b/client/apps/game/src/utils/addresses.ts index 862051fcd..abf29ac28 100644 --- a/client/apps/game/src/utils/addresses.ts +++ b/client/apps/game/src/utils/addresses.ts @@ -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; diff --git a/client/apps/game/src/utils/config.ts b/client/apps/game/src/utils/config.ts index f008a3320..3c4596bae 100644 --- a/client/apps/game/src/utils/config.ts +++ b/client/apps/game/src/utils/config.ts @@ -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; }; diff --git a/client/apps/game/src/utils/utils.ts b/client/apps/game/src/utils/utils.ts deleted file mode 100644 index ec4434eed..000000000 --- a/client/apps/game/src/utils/utils.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { SeasonAddresses } from "@bibliothecadao/eternum"; -import manifestMainnet from "../../../../../contracts/game/manifest_mainnet.json"; -import manifestSepolia from "../../../../../contracts/game/manifest_sepolia.json"; -import manifestLocal from "../../../../../contracts/game/manifest_slot.json"; - -import seasonAddressesMainnet from "../../../../../contracts/common/addresses/mainnet.json"; -import seasonAddressesSepolia from "../../../../../contracts/common/addresses/sepolia.json"; -import seasonAddressesLocal from "../../../../../contracts/common/addresses/slot.json"; - -/** Valid chain identifiers */ -export type Chain = "local" | "sepolia" | "mainnet" | "slot"; - -/** - * Retrieves the season addresses for a specific chain - * @param chain - The chain identifier - * @returns The contract addresses for the specified chain - * @throws Error if addresses cannot be loaded - */ -export function getSeasonAddresses(chain: Chain): SeasonAddresses { - const addressesMap = { - local: seasonAddressesLocal, - sepolia: seasonAddressesSepolia, - mainnet: seasonAddressesMainnet, - slot: seasonAddressesLocal, - }; - - const addresses = addressesMap[chain] as { - seasonPass?: string; - realms?: string; - lords?: string; - resources?: Record; - }; - - if (!addresses?.resources) { - throw new Error(`Invalid addresses for chain: ${chain}`); - } - - return { - seasonPass: addresses.seasonPass ?? "", - realms: addresses.realms ?? "", - lords: addresses.lords ?? "", - resources: Object.fromEntries( - Object.entries(addresses.resources).map(([key, value]) => [ - key, - Array.isArray(value) ? (value as [number, string]) : [0, value as string], - ]), - ), - } as SeasonAddresses; -} - -/** - * Interface representing the game manifest configuration - * @interface GameManifest - */ -interface GameManifest { - [key: string]: unknown; -} - -/** - * Retrieves the game manifest for a specific chain - * @param chain - The chain identifier - * @returns The game manifest configuration - * @throws Error if manifest cannot be loaded - */ -// export async function getGameManifest(chain: Chain): Promise { -export function getGameManifest(chain: Chain): GameManifest { - // const MANIFEST_FILE = `../../contracts/game/manifest_${chain}.json`; - try { - // const manifest = (await import(MANIFEST_FILE)).default; - - switch (chain) { - case "local": - return manifestLocal; - case "sepolia": - return manifestSepolia; - case "mainnet": - return manifestMainnet; - default: - throw new Error(`Invalid chain: ${chain}`); - } - } catch (error) { - throw new Error(`Failed to load game manifest for chain ${chain}: ${error}`); - } -} diff --git a/client/apps/game/tsconfig.json b/client/apps/game/tsconfig.json index 97fc8c1d9..c5b9d5217 100644 --- a/client/apps/game/tsconfig.json +++ b/client/apps/game/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "baseUrl": ".", "paths": { - "@/*": ["src/*"] + "@/*": ["src/*"], + "@config": ["../../../config/utils/utils"] }, "target": "ESNext", "useDefineForClassFields": true, @@ -24,7 +25,7 @@ "jsx": "react-jsx", "types": ["vite-plugin-svgr/client", "@types/node"] }, - "include": ["src", "eternumConfig.tsx"], + "include": ["src", "../../../config/utils/utils"], "exclude": ["node_modules", "./node_modules", "./node_modules/*", "src/node_modules", "dist", "**/*.spec.ts"], "references": [ { diff --git a/client/apps/game/vite.config.ts b/client/apps/game/vite.config.ts index 8597b4ea1..39614e6e7 100644 --- a/client/apps/game/vite.config.ts +++ b/client/apps/game/vite.config.ts @@ -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: { diff --git a/client/apps/landing/.env.mainnet b/client/apps/landing/.env.mainnet index b3888289d..8ffcea636 100644 --- a/client/apps/landing/.env.mainnet +++ b/client/apps/landing/.env.mainnet @@ -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" diff --git a/client/apps/landing/.env.slot b/client/apps/landing/.env.slot index 02b3bcf46..1be4cf1a1 100644 --- a/client/apps/landing/.env.slot +++ b/client/apps/landing/.env.slot @@ -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= diff --git a/client/apps/landing/codegen.ts b/client/apps/landing/codegen.ts index 5880f8432..1b40c1152 100644 --- a/client/apps/landing/codegen.ts +++ b/client/apps/landing/codegen.ts @@ -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: { diff --git a/config/deployer/index.ts b/config/deployer/index.ts index cbf58fb0d..a5495d821 100644 --- a/config/deployer/index.ts +++ b/config/deployer/index.ts @@ -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"; import { GameConfigDeployer } from "./config"; const { diff --git a/config/utils/environment.ts b/config/utils/environment.ts index 2a80a945c..d7bf89fb2 100644 --- a/config/utils/environment.ts +++ b/config/utils/environment.ts @@ -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 { - 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"); diff --git a/config/utils/utils.ts b/config/utils/utils.ts index 1ebbd44a8..e1a359d22 100644 --- a/config/utils/utils.ts +++ b/config/utils/utils.ts @@ -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"; @@ -40,3 +40,30 @@ export async function getGameManifest(chain: Chain): Promise { 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 { + 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}`); + } +} diff --git a/contracts/common/scripts/deploy.sh b/contracts/common/scripts/deploy.sh index 7547e3e47..036dcc269 100644 --- a/contracts/common/scripts/deploy.sh +++ b/contracts/common/scripts/deploy.sh @@ -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 echo "Setting up config..." diff --git a/packages/core/src/modelManager/ConfigManager.ts b/packages/core/src/modelManager/ConfigManager.ts index 8a609d957..504679884 100644 --- a/packages/core/src/modelManager/ConfigManager.ts +++ b/packages/core/src/modelManager/ConfigManager.ts @@ -32,6 +32,9 @@ 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(); @@ -39,6 +42,8 @@ export class ClientConfigManager { this.initializeResourceBuildingCosts(); this.initializeBuildingCosts(); this.initializeStructureCosts(); + + console.log({ resourceBuildingCosts: this.resourceBuildingCosts }); } public static instance(): ClientConfigManager { @@ -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 }) => ({ @@ -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, @@ -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, @@ -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, diff --git a/packages/react/src/hooks/helpers/use-rewards.ts b/packages/react/src/hooks/helpers/use-rewards.ts index ce4ae4606..30040a087 100644 --- a/packages/react/src/hooks/helpers/use-rewards.ts +++ b/packages/react/src/hooks/helpers/use-rewards.ts @@ -2,7 +2,7 @@ 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(0n); const { @@ -10,6 +10,7 @@ export const usePrizePool = (lordsAddress: string) => { } = useDojo(); const getBalance = async (address: string) => { + if (!lordsAddress) return; const balance = await account?.callContract({ contractAddress: lordsAddress, entrypoint: "balance_of", @@ -50,7 +51,7 @@ export const usePrizePool = (lordsAddress: string) => { const interval = setInterval(getPrizePool, 60000); // Every minute return () => clearInterval(interval); - }, []); + }, [lordsAddress]); return prizePool; };