{"version":3,"file":"transferSubdomain.cjs","sources":["../../../src/bindings/transferSubdomain.ts"],"sourcesContent":["import { Address, GetAccountInfoApi, IInstruction, Rpc } from \"@solana/kit\";\r\n\r\nimport { NAME_PROGRAM_ADDRESS } from \"../constants/addresses\";\r\nimport { getDomainAddress } from \"../domain/getDomainAddress\";\r\nimport { InvalidSubdomainError } from \"../errors\";\r\nimport { TransferInstruction } from \"../instructions/transferInstruction\";\r\nimport { RegistryState } from \"../states/registry\";\r\n\r\ninterface TransferSubdomainParams {\r\n  rpc: Rpc<GetAccountInfoApi>;\r\n  subdomain: string;\r\n  newOwner: Address;\r\n  isParentOwnerSigner?: boolean;\r\n  currentOwner?: Address;\r\n}\r\n\r\n/**\r\n * Transfers a subdomain to a new owner.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `rpc`: An RPC interface implementing GetAccountInfoApi.\r\n *   - `subdomain`: The subdomain to transfer. This can include or omit the .sol suffix\r\n *     (e.g., 'something.sns.sol' or 'something.sns').\r\n *   - `newOwner`: The address of the new owner.\r\n *   - `isParentOwnerSigner`: (Optional) Specifies if the parent domain owner is a signer\r\n *     for this transaction.\r\n *   - `currentOwner`: (Optional) The current owner of the subdomain. If not provided, it\r\n *     will be resolved automatically. This is useful for building transactions when the subdomain\r\n *     does not yet exist.\r\n * @returns A promise that resolves to the transfer subdomain instruction.\r\n */\r\nexport const transferSubdomain = async ({\r\n  rpc,\r\n  subdomain,\r\n  newOwner,\r\n  isParentOwnerSigner,\r\n  currentOwner,\r\n}: TransferSubdomainParams): Promise<IInstruction> => {\r\n  const {\r\n    domainAddress,\r\n    isSub,\r\n    parentAddress: _parentAddress,\r\n  } = await getDomainAddress({ domain: subdomain });\r\n\r\n  if (!isSub || !_parentAddress) {\r\n    throw new InvalidSubdomainError(\"The subdomain is not valid\");\r\n  }\r\n\r\n  if (!currentOwner) {\r\n    const registry = await RegistryState.retrieve(rpc, domainAddress);\r\n    currentOwner = registry.owner;\r\n  }\r\n\r\n  let parentAddress: Address | undefined = undefined;\r\n  let parentOwner: Address | undefined = undefined;\r\n\r\n  if (isParentOwnerSigner) {\r\n    parentAddress = _parentAddress;\r\n    parentOwner = (await RegistryState.retrieve(rpc, _parentAddress)).owner;\r\n  }\r\n\r\n  const ix = new TransferInstruction({ newOwner }).getInstruction(\r\n    NAME_PROGRAM_ADDRESS,\r\n    domainAddress,\r\n    currentOwner,\r\n    undefined,\r\n    parentAddress,\r\n    parentOwner\r\n  );\r\n\r\n  return ix;\r\n};\r\n"],"names":["async","rpc","subdomain","newOwner","isParentOwnerSigner","currentOwner","domainAddress","isSub","parentAddress","_parentAddress","getDomainAddress","domain","InvalidSubdomainError","RegistryState","retrieve","owner","parentOwner","TransferInstruction","getInstruction","NAME_PROGRAM_ADDRESS","undefined"],"mappings":"mPA+BiCA,OAC/BC,MACAC,YACAC,WACAC,sBACAC,mBAEA,MAAMC,cACJA,EAAaC,MACbA,EACAC,cAAeC,SACPC,mBAAiB,CAAEC,OAAQT,IAErC,IAAKK,IAAUE,EACb,MAAM,IAAIG,EAAqBA,sBAAC,8BAGlC,IAAKP,EAAc,CAEjBA,SADuBQ,EAAAA,cAAcC,SAASb,EAAKK,IAC3BS,MAG1B,IAAIP,EACAQ,EAEAZ,IACFI,EAAgBC,EAChBO,SAAqBH,EAAaA,cAACC,SAASb,EAAKQ,IAAiBM,OAYpE,OATW,IAAIE,EAAAA,oBAAoB,CAAEd,aAAYe,eAC/CC,EAAoBA,qBACpBb,EACAD,OACAe,EACAZ,EACAQ,EAGO"}