|
| 1 | +import "dotenv/config"; |
| 2 | +import { http, fallback, webSocket, createPublicClient } from "viem"; |
| 3 | +import { Entity } from "../../client/src/utils/game/entityLib"; |
| 4 | +import { LiveState } from "../../client/src/utils/sync"; |
| 5 | +import { GameConfig } from "../../client/src/utils/game/configLib"; |
| 6 | + |
| 7 | +import { stash } from "../../client/src/mud/stash"; |
| 8 | +import { Stash } from "@latticexyz/stash/internal"; |
| 9 | +import { syncToStash } from "@latticexyz/store-sync/internal"; |
| 10 | +import { ODYSSEY_CHAIN } from "../../client/src/utils/chains"; |
| 11 | +import Worlds from "../../contracts/worlds.json"; |
| 12 | + |
| 13 | +const chain = ODYSSEY_CHAIN; |
| 14 | +const WORLD_ADDRESS = Worlds[chain.id]?.address as `0x${string}`; |
| 15 | +if (!WORLD_ADDRESS) throw new Error(`No world address found for chain ${chain.id}`); |
| 16 | +const START_BLOCK = Worlds[chain.id]!.blockNumber!; |
| 17 | + |
| 18 | +const publicClient = createPublicClient({ |
| 19 | + chain, |
| 20 | + transport: fallback([webSocket(), http()]), |
| 21 | + pollingInterval: 100, |
| 22 | + cacheTime: 100, |
| 23 | +}); |
| 24 | + |
| 25 | +function botDecision( |
| 26 | + bot: Entity, |
| 27 | + liveState: LiveState, |
| 28 | + gameConfig: GameConfig, |
| 29 | + decision: "vertical" | "horizontal", |
| 30 | + wadTime: bigint |
| 31 | +): [string, string] { |
| 32 | + // TODO |
| 33 | + return ["up", "right"]; |
| 34 | +} |
| 35 | + |
| 36 | +export async function main() { |
| 37 | + syncToStash({ |
| 38 | + stash: stash as Stash, |
| 39 | + startSync: true, |
| 40 | + address: WORLD_ADDRESS, |
| 41 | + startBlock: BigInt(START_BLOCK ?? 0), |
| 42 | + publicClient: publicClient as any, |
| 43 | + indexerUrl: chain.indexerUrl, |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +console.log("Starting bot...", WORLD_ADDRESS, START_BLOCK); |
| 48 | +await main(); |
0 commit comments