index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. __exportStar(require("./delegation/accounts"), exports);
  53. __exportStar(require("./delegation/delegate"), exports);
  54. exports.PROGRAM_ADDRESS = "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n";
  55. exports.SYSVAR_INSTRUCTIONS_PUBKEY = new web3_js_1.PublicKey(
  56. "Sysvar1nstructions1111111111111111111111111"
  57. );
  58. exports.PROGRAM_ID = new web3_js_1.PublicKey(exports.PROGRAM_ADDRESS);
  59. function FindWorldRegistryPda(programId) {
  60. if (programId === void 0) {
  61. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  62. }
  63. return web3_js_1.PublicKey.findProgramAddressSync(
  64. [Buffer.from("registry")],
  65. programId
  66. )[0];
  67. }
  68. exports.FindWorldRegistryPda = FindWorldRegistryPda;
  69. function FindWorldPda(id, programId) {
  70. if (programId === void 0) {
  71. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  72. }
  73. id = CastToBN(id);
  74. var idBuffer = Buffer.from(id.toArrayLike(Buffer, "be", 8));
  75. return web3_js_1.PublicKey.findProgramAddressSync(
  76. [Buffer.from("world"), idBuffer],
  77. programId
  78. )[0];
  79. }
  80. exports.FindWorldPda = FindWorldPda;
  81. function FindEntityPda(worldId, entityId, extraSeed, programId) {
  82. if (programId === void 0) {
  83. programId = new web3_js_1.PublicKey(exports.PROGRAM_ID);
  84. }
  85. worldId = CastToBN(worldId);
  86. entityId = CastToBN(entityId);
  87. var worldIdBuffer = Buffer.from(worldId.toArrayLike(Buffer, "be", 8));
  88. var entityIdBuffer = Buffer.from(entityId.toArrayLike(Buffer, "be", 8));
  89. var seeds = [Buffer.from("entity"), worldIdBuffer];
  90. if (extraSeed != null) {
  91. seeds.push(Buffer.from(new Uint8Array(8)));
  92. seeds.push(Buffer.from(extraSeed));
  93. } else {
  94. seeds.push(entityIdBuffer);
  95. }
  96. return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
  97. }
  98. exports.FindEntityPda = FindEntityPda;
  99. function FindComponentPda(componentProgramId, entity, componentId) {
  100. if (componentId === void 0) {
  101. componentId = "";
  102. }
  103. return web3_js_1.PublicKey.findProgramAddressSync(
  104. [Buffer.from(componentId), entity.toBytes()],
  105. componentProgramId
  106. )[0];
  107. }
  108. exports.FindComponentPda = FindComponentPda;
  109. function CastToBN(id) {
  110. if (!(id instanceof bn_js_1.default)) {
  111. id = new bn_js_1.default(id);
  112. }
  113. return id;
  114. }
  115. function SerializeArgs(args) {
  116. if (args === void 0) {
  117. args = {};
  118. }
  119. var jsonString = JSON.stringify(args);
  120. var encoder = new TextEncoder();
  121. var binaryData = encoder.encode(jsonString);
  122. return Buffer.from(
  123. binaryData.buffer,
  124. binaryData.byteOffset,
  125. binaryData.byteLength
  126. );
  127. }
  128. exports.SerializeArgs = SerializeArgs;
  129. //# sourceMappingURL=index.js.map