delegate.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 __setModuleDefault =
  26. (this && this.__setModuleDefault) ||
  27. (Object.create
  28. ? function (o, v) {
  29. Object.defineProperty(o, "default", { enumerable: true, value: v });
  30. }
  31. : function (o, v) {
  32. o["default"] = v;
  33. });
  34. var __importStar =
  35. (this && this.__importStar) ||
  36. function (mod) {
  37. if (mod && mod.__esModule) return mod;
  38. var result = {};
  39. if (mod != null)
  40. for (var k in mod)
  41. if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
  42. __createBinding(result, mod, k);
  43. __setModuleDefault(result, mod);
  44. return result;
  45. };
  46. Object.defineProperty(exports, "__esModule", { value: true });
  47. exports.createDelegateInstruction =
  48. exports.delegateInstructionDiscriminator =
  49. exports.delegateStruct =
  50. void 0;
  51. var beet = __importStar(require("@metaplex-foundation/beet"));
  52. var web3 = __importStar(require("@solana/web3.js"));
  53. var accounts_1 = require("./accounts");
  54. exports.delegateStruct = new beet.FixableBeetArgsStruct(
  55. [
  56. ["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
  57. ["validUntil", beet.i64],
  58. ["commitFrequencyMs", beet.u32],
  59. ],
  60. "DelegateInstructionArgs"
  61. );
  62. exports.delegateInstructionDiscriminator = [90, 147, 75, 178, 85, 88, 4, 137];
  63. function createDelegateInstruction(
  64. accounts,
  65. validUntil,
  66. commitFrequencyMs,
  67. programId
  68. ) {
  69. var _a, _b, _c, _d, _e;
  70. if (validUntil === void 0) {
  71. validUntil = 0;
  72. }
  73. if (commitFrequencyMs === void 0) {
  74. commitFrequencyMs = 30000;
  75. }
  76. if (programId === void 0) {
  77. programId = accounts.ownerProgram;
  78. }
  79. var data = exports.delegateStruct.serialize({
  80. instructionDiscriminator: exports.delegateInstructionDiscriminator,
  81. validUntil: validUntil,
  82. commitFrequencyMs: commitFrequencyMs,
  83. })[0];
  84. var _f = (0, accounts_1.getDelegationAccounts)(
  85. accounts.account,
  86. accounts.ownerProgram
  87. ),
  88. delegationPda = _f.delegationPda,
  89. delegatedAccountSeedsPda = _f.delegatedAccountSeedsPda,
  90. bufferPda = _f.bufferPda;
  91. var keys = [
  92. {
  93. pubkey: accounts.payer,
  94. isWritable: false,
  95. isSigner: true,
  96. },
  97. {
  98. pubkey: accounts.entity,
  99. isWritable: false,
  100. isSigner: false,
  101. },
  102. {
  103. pubkey: accounts.account,
  104. isWritable: true,
  105. isSigner: false,
  106. },
  107. {
  108. pubkey: accounts.ownerProgram,
  109. isWritable: false,
  110. isSigner: false,
  111. },
  112. {
  113. pubkey: (_a = accounts.buffer) !== null && _a !== void 0 ? _a : bufferPda,
  114. isWritable: true,
  115. isSigner: false,
  116. },
  117. {
  118. pubkey:
  119. (_b = accounts.delegationRecord) !== null && _b !== void 0
  120. ? _b
  121. : delegationPda,
  122. isWritable: true,
  123. isSigner: false,
  124. },
  125. {
  126. pubkey:
  127. (_c = accounts.delegateAccountSeeds) !== null && _c !== void 0
  128. ? _c
  129. : delegatedAccountSeedsPda,
  130. isWritable: true,
  131. isSigner: false,
  132. },
  133. {
  134. pubkey:
  135. (_d = accounts.delegationProgram) !== null && _d !== void 0
  136. ? _d
  137. : new web3.PublicKey(accounts_1.DELEGATION_PROGRAM_ID),
  138. isWritable: false,
  139. isSigner: false,
  140. },
  141. {
  142. pubkey:
  143. (_e = accounts.systemProgram) !== null && _e !== void 0
  144. ? _e
  145. : web3.SystemProgram.programId,
  146. isWritable: false,
  147. isSigner: false,
  148. },
  149. ];
  150. return new web3.TransactionInstruction({
  151. programId: programId,
  152. keys: keys,
  153. data: data,
  154. });
  155. }
  156. exports.createDelegateInstruction = createDelegateInstruction;
  157. //# sourceMappingURL=delegate.js.map