anchor.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Program, IdlAccounts, BN } from "@coral-xyz/anchor"
  2. import { ExtensionNft, IDL } from "../idl/extension_nft"
  3. import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js"
  4. import { WrappedConnection } from "./wrappedConnection";
  5. export const CONNECTION = new WrappedConnection(process.env.NEXT_PUBLIC_RPC ? process.env.NEXT_PUBLIC_RPC : 'https://rpc.magicblock.app/devnet', {
  6. wsEndpoint: process.env.NEXT_PUBLIC_WSS_RPC ? process.env.NEXT_PUBLIC_WSS_RPC : "wss://rpc.magicblock.app/devnet",
  7. commitment: 'confirmed'
  8. });
  9. export const METAPLEX_READAPI = "https://devnet.helius-rpc.com/?api-key=78065db3-87fb-431c-8d43-fcd190212125";
  10. // Here you can basically use what ever seed you want. For example one per level or city or whatever.
  11. export const GAME_DATA_SEED = "level_2";
  12. // ExtensionNft game program ID
  13. const programId = new PublicKey("H31ofLpWqeAzF2Pg54HSPQGYifJad843tTJg8vCYVoh3")
  14. // Create the program interface using the idl, program ID, and provider
  15. export const program = new Program<ExtensionNft>(IDL, programId, {
  16. connection: CONNECTION,
  17. })
  18. export const [gameDataPDA] = PublicKey.findProgramAddressSync(
  19. [Buffer.from(GAME_DATA_SEED, "utf8")],
  20. program.programId
  21. )
  22. // Player Data Account Type from Idl
  23. export type PlayerData = IdlAccounts<ExtensionNft>["playerData"]
  24. export type GameData = IdlAccounts<ExtensionNft>["gameData"]
  25. // Constants for the game
  26. export const TIME_TO_REFILL_ENERGY: BN = new BN(60)
  27. export const MAX_ENERGY = 100
  28. export const ENERGY_PER_TICK: BN = new BN(1)
  29. export const TOTAL_WOOD_AVAILABLE: BN = new BN(100000)