anchor.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { BN, type IdlAccounts, Program } from '@coral-xyz/anchor';
  2. import { Connection, PublicKey, clusterApiUrl } from '@solana/web3.js';
  3. import { type ExtensionNft, IDL } from '../idl/extension_nft';
  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([Buffer.from(GAME_DATA_SEED, 'utf8')], program.programId);
  19. // Player Data Account Type from Idl
  20. export type PlayerData = IdlAccounts<ExtensionNft>['playerData'];
  21. export type GameData = IdlAccounts<ExtensionNft>['gameData'];
  22. // Constants for the game
  23. export const TIME_TO_REFILL_ENERGY: BN = new BN(60);
  24. export const MAX_ENERGY = 100;
  25. export const ENERGY_PER_TICK: BN = new BN(1);
  26. export const TOTAL_WOOD_AVAILABLE: BN = new BN(100000);