allow_undelegation.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import * as beet from "@metaplex-foundation/beet";
  2. import * as web3 from "@solana/web3.js";
  3. import {
  4. DelegateAccounts,
  5. DELEGATION_PROGRAM_ID,
  6. } from "@magicblock-labs/ephemeral-rollups-sdk";
  7. export const allowUndelegationStruct = new beet.BeetArgsStruct<{
  8. instructionDiscriminator: number[] /* size: 8 */;
  9. }>(
  10. [["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)]],
  11. "allowUndelegationInstructionArgs",
  12. );
  13. export interface AllowUndelegationInstructionAccounts {
  14. delegatedAccount: web3.PublicKey;
  15. ownerProgram: web3.PublicKey;
  16. buffer?: web3.PublicKey;
  17. }
  18. export const allowUndelegateInstructionDiscriminator = [
  19. 255, 66, 82, 208, 247, 5, 210, 126,
  20. ];
  21. /**
  22. * Creates a Delegate instruction.
  23. */
  24. export function createAllowUndelegationInstruction(
  25. accounts: AllowUndelegationInstructionAccounts,
  26. ) {
  27. const [data] = allowUndelegationStruct.serialize({
  28. instructionDiscriminator: allowUndelegateInstructionDiscriminator,
  29. });
  30. const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
  31. accounts.delegatedAccount,
  32. accounts.ownerProgram,
  33. );
  34. const keys: web3.AccountMeta[] = [
  35. {
  36. pubkey: accounts.delegatedAccount,
  37. isWritable: false,
  38. isSigner: false,
  39. },
  40. {
  41. pubkey: delegationPda,
  42. isWritable: false,
  43. isSigner: false,
  44. },
  45. {
  46. pubkey: delegationMetadata,
  47. isWritable: true,
  48. isSigner: false,
  49. },
  50. {
  51. pubkey: bufferPda,
  52. isWritable: false,
  53. isSigner: false,
  54. },
  55. {
  56. pubkey: new web3.PublicKey(DELEGATION_PROGRAM_ID),
  57. isWritable: true,
  58. isSigner: false,
  59. },
  60. ];
  61. const programId = accounts.ownerProgram;
  62. return new web3.TransactionInstruction({
  63. programId,
  64. keys,
  65. data,
  66. });
  67. }