index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. var __importDefault =
  33. (this && this.__importDefault) ||
  34. function (mod) {
  35. return mod && mod.__esModule ? mod : { default: mod };
  36. };
  37. Object.defineProperty(exports, "__esModule", { value: true });
  38. exports.SerializeArgs =
  39. exports.FindComponentPda =
  40. exports.FindEntityPda =
  41. exports.FindWorldPda =
  42. exports.FindWorldRegistryPda =
  43. exports.PROGRAM_ID =
  44. exports.SYSVAR_INSTRUCTIONS_PUBKEY =
  45. exports.PROGRAM_ADDRESS =
  46. void 0;
  47. var web3_js_1 = require("@solana/web3.js");
  48. var bn_js_1 = __importDefault(require("bn.js"));
  49. __exportStar(require("./accounts"), exports);
  50. __exportStar(require("./instructions"), exports);
  51. __exportStar(require("./transactions/transactions"), exports);
  52. exports.PROGRAM_ADDRESS = "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
  53. exports.SYSVAR_INSTRUCTIONS_PUBKEY = new web3_js_1.PublicKey(
  54. "Sysvar1nstructions1111111111111111111111111"
  55. );
  56. exports.PROGRAM_ID = new web3_js_1.PublicKey(exports.PROGRAM_ADDRESS);
  57. function FindWorldRegistryPda(programId) {
  58. if (programId === void 0) {
  59. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  60. }
  61. return web3_js_1.PublicKey.findProgramAddressSync(
  62. [Buffer.from("registry")],
  63. programId
  64. )[0];
  65. }
  66. exports.FindWorldRegistryPda = FindWorldRegistryPda;
  67. function FindWorldPda(id, programId) {
  68. if (programId === void 0) {
  69. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  70. }
  71. id = CastToBN(id);
  72. var idBuffer = Buffer.from(id.toArrayLike(Buffer, "be", 8));
  73. return web3_js_1.PublicKey.findProgramAddressSync(
  74. [Buffer.from("world"), idBuffer],
  75. programId
  76. )[0];
  77. }
  78. exports.FindWorldPda = FindWorldPda;
  79. function FindEntityPda(worldId, entityId, extraSeed, programId) {
  80. if (programId === void 0) {
  81. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  82. }
  83. worldId = CastToBN(worldId);
  84. entityId = CastToBN(entityId);
  85. var worldIdBuffer = Buffer.from(worldId.toArrayLike(Buffer, "be", 8));
  86. var entityIdBuffer = Buffer.from(entityId.toArrayLike(Buffer, "be", 8));
  87. var seeds = [Buffer.from("entity"), worldIdBuffer];
  88. if (extraSeed != null) {
  89. seeds.push(Buffer.from(new Uint8Array(8)));
  90. seeds.push(Buffer.from(extraSeed));
  91. } else {
  92. seeds.push(entityIdBuffer);
  93. }
  94. return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
  95. }
  96. exports.FindEntityPda = FindEntityPda;
  97. function FindComponentPda(componentProgramId, entity, componentId) {
  98. if (componentId === void 0) {
  99. componentId = "";
  100. }
  101. return web3_js_1.PublicKey.findProgramAddressSync(
  102. [Buffer.from(componentId), entity.toBytes()],
  103. componentProgramId
  104. )[0];
  105. }
  106. exports.FindComponentPda = FindComponentPda;
  107. function CastToBN(id) {
  108. if (!(id instanceof bn_js_1.default)) {
  109. id = new bn_js_1.default(id);
  110. }
  111. return id;
  112. }
  113. function SerializeArgs(args) {
  114. if (args === void 0) {
  115. args = {};
  116. }
  117. var jsonString = JSON.stringify(args);
  118. var encoder = new TextEncoder();
  119. var binaryData = encoder.encode(jsonString);
  120. return Buffer.from(
  121. binaryData.buffer,
  122. binaryData.byteOffset,
  123. binaryData.byteLength
  124. );
  125. }
  126. exports.SerializeArgs = SerializeArgs;
  127. //# sourceMappingURL=index.js.map