index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. var __createBinding =
  3. (this && this.__createBinding) ||
  4. (Object.create
  5. ? function (o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. var desc = Object.getOwnPropertyDescriptor(m, k);
  8. if (
  9. !desc ||
  10. ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
  11. ) {
  12. desc = {
  13. enumerable: true,
  14. get: function () {
  15. return m[k];
  16. },
  17. };
  18. }
  19. Object.defineProperty(o, k2, desc);
  20. }
  21. : function (o, m, k, k2) {
  22. if (k2 === undefined) k2 = k;
  23. o[k2] = m[k];
  24. });
  25. var __exportStar =
  26. (this && this.__exportStar) ||
  27. function (m, exports) {
  28. for (var p in m)
  29. if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
  30. __createBinding(exports, m, p);
  31. };
  32. Object.defineProperty(exports, "__esModule", { value: true });
  33. exports.SerializeArgs =
  34. exports.FindComponentPda =
  35. exports.FindEntityPda =
  36. exports.FindWorldPda =
  37. exports.FindWorldRegistryPda =
  38. exports.PROGRAM_ID =
  39. exports.SYSVAR_INSTRUCTIONS_PUBKEY =
  40. exports.PROGRAM_ADDRESS =
  41. void 0;
  42. var web3_js_1 = require("@solana/web3.js");
  43. __exportStar(require("./accounts"), exports);
  44. __exportStar(require("./instructions"), exports);
  45. __exportStar(require("./transactions/transactions"), exports);
  46. exports.PROGRAM_ADDRESS = "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
  47. exports.SYSVAR_INSTRUCTIONS_PUBKEY = new web3_js_1.PublicKey(
  48. "Sysvar1nstructions1111111111111111111111111"
  49. );
  50. exports.PROGRAM_ID = new web3_js_1.PublicKey(exports.PROGRAM_ADDRESS);
  51. function FindWorldRegistryPda(programId) {
  52. if (programId === void 0) {
  53. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  54. }
  55. return web3_js_1.PublicKey.findProgramAddressSync(
  56. [Buffer.from("registry")],
  57. programId
  58. )[0];
  59. }
  60. exports.FindWorldRegistryPda = FindWorldRegistryPda;
  61. function FindWorldPda(id, programId) {
  62. if (programId === void 0) {
  63. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  64. }
  65. return web3_js_1.PublicKey.findProgramAddressSync(
  66. [Buffer.from("world"), id.toBuffer("be", 8)],
  67. programId
  68. )[0];
  69. }
  70. exports.FindWorldPda = FindWorldPda;
  71. function FindEntityPda(worldId, entityId, extraSeed, programId) {
  72. if (programId === void 0) {
  73. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  74. }
  75. var seeds = [Buffer.from("entity"), worldId.toBuffer("be", 8)];
  76. if (extraSeed != null) {
  77. seeds.push(Buffer.from(new Uint8Array(8)));
  78. seeds.push(Buffer.from(extraSeed));
  79. } else {
  80. seeds.push(entityId.toBuffer("be", 8));
  81. }
  82. return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
  83. }
  84. exports.FindEntityPda = FindEntityPda;
  85. function FindComponentPda(componentProgramId, entity, componentId) {
  86. if (componentId === void 0) {
  87. componentId = "";
  88. }
  89. return web3_js_1.PublicKey.findProgramAddressSync(
  90. [Buffer.from(componentId), entity.toBytes()],
  91. componentProgramId
  92. )[0];
  93. }
  94. exports.FindComponentPda = FindComponentPda;
  95. function SerializeArgs(args) {
  96. if (args === void 0) {
  97. args = {};
  98. }
  99. var jsonString = JSON.stringify(args);
  100. var encoder = new TextEncoder();
  101. var binaryData = encoder.encode(jsonString);
  102. return Buffer.from(
  103. binaryData.buffer,
  104. binaryData.byteOffset,
  105. binaryData.byteLength
  106. );
  107. }
  108. exports.SerializeArgs = SerializeArgs;
  109. //# sourceMappingURL=index.js.map