{"version":3,"file":"transferInstruction.cjs","sources":["../../../src/instructions/transferInstruction.ts"],"sourcesContent":["import {\r\n  AccountMeta,\r\n  AccountRole,\r\n  Address,\r\n  Instruction,\r\n  ReadonlyUint8Array,\r\n} from \"@solana/kit\";\r\nimport { serialize } from \"borsh\";\r\n\r\nimport { addressCodec } from \"../codecs\";\r\nimport { DEFAULT_ADDRESS } from \"../constants/addresses\";\r\n\r\n/**\r\n * Input for transferring an SNS name-registry account.\r\n *\r\n * @example\r\n * ```ts\r\n * const params: TransferInstructionParams = { newOwner };\r\n * ```\r\n */\r\nexport interface TransferInstructionParams {\r\n  /** New registry owner. */\r\n  newOwner: Address;\r\n}\r\n\r\n/** Builder for the SNS name-registry transfer instruction. */\r\nexport class TransferInstruction {\r\n  /** Instruction discriminator. */\r\n  tag: number;\r\n  /** Encoded new owner address. */\r\n  encodedNewOwnerAddress: ReadonlyUint8Array;\r\n\r\n  static schema = {\r\n    struct: {\r\n      tag: \"u8\",\r\n      encodedNewOwnerAddress: { array: { type: \"u8\", len: 32 } },\r\n    },\r\n  };\r\n\r\n  constructor(obj: TransferInstructionParams) {\r\n    this.tag = 2;\r\n    this.encodedNewOwnerAddress = addressCodec.encode(obj.newOwner);\r\n  }\r\n\r\n  serialize(): Uint8Array {\r\n    return serialize(TransferInstruction.schema, this);\r\n  }\r\n\r\n  getInstruction(\r\n    programAddress: Address,\r\n    domainAddress: Address,\r\n    currentOwner: Address,\r\n    classAddress?: Address,\r\n    parentAddress?: Address,\r\n    parentOwner?: Address\r\n  ): Instruction {\r\n    const data = this.serialize();\r\n\r\n    const accounts: AccountMeta[] = [\r\n      {\r\n        address: domainAddress,\r\n        role: AccountRole.WRITABLE,\r\n      },\r\n      {\r\n        address: parentOwner ? parentOwner : currentOwner,\r\n        role: AccountRole.READONLY_SIGNER,\r\n      },\r\n    ];\r\n\r\n    if (classAddress) {\r\n      accounts.push({\r\n        address: classAddress,\r\n        role: AccountRole.READONLY_SIGNER,\r\n      });\r\n    }\r\n\r\n    if (parentOwner && parentAddress) {\r\n      if (!classAddress) {\r\n        accounts.push({\r\n          address: DEFAULT_ADDRESS,\r\n          role: AccountRole.READONLY,\r\n        });\r\n      }\r\n\r\n      accounts.push({\r\n        address: parentAddress,\r\n        role: AccountRole.READONLY,\r\n      });\r\n    }\r\n\r\n    return {\r\n      programAddress,\r\n      accounts,\r\n      data,\r\n    };\r\n  }\r\n}\r\n"],"names":["addressCodec","serialize","AccountRole","DEFAULT_ADDRESS"],"mappings":";;;;;;;;;AAyBA;MACa,mBAAmB,CAAA;;AAE9B,IAAA,GAAG;;AAEH,IAAA,sBAAsB;IAEtB,OAAO,MAAM,GAAG;AACd,QAAA,MAAM,EAAE;AACN,YAAA,GAAG,EAAE,IAAI;AACT,YAAA,sBAAsB,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE;AAC3D,SAAA;KACF;AAED,IAAA,WAAA,CAAY,GAA8B,EAAA;AACxC,QAAA,IAAI,CAAC,GAAG,GAAG,CAAC;QACZ,IAAI,CAAC,sBAAsB,GAAGA,mBAAY,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;;IAGjE,SAAS,GAAA;QACP,OAAOC,eAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC;;IAGpD,cAAc,CACZ,cAAuB,EACvB,aAAsB,EACtB,YAAqB,EACrB,YAAsB,EACtB,aAAuB,EACvB,WAAqB,EAAA;AAErB,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,EAAE;AAE7B,QAAA,MAAM,QAAQ,GAAkB;AAC9B,YAAA;AACE,gBAAA,OAAO,EAAE,aAAa;gBACtB,IAAI,EAAEC,eAAW,CAAC,QAAQ;AAC3B,aAAA;AACD,YAAA;gBACE,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,YAAY;gBACjD,IAAI,EAAEA,eAAW,CAAC,eAAe;AAClC,aAAA;SACF;Q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