{"version":3,"file":"transferDomain.cjs","sources":["../../../src/bindings/transferDomain.ts"],"sourcesContent":["import { Address, GetAccountInfoApi, IInstruction, Rpc } from \"@solana/kit\";\r\n\r\nimport { NAME_PROGRAM_ADDRESS } from \"../constants/addresses\";\r\nimport { TransferInstruction } from \"../instructions/transferInstruction\";\r\nimport { RegistryState } from \"../states/registry\";\r\nimport { deriveAddress } from \"../utils/deriveAddress\";\r\n\r\ninterface TransferDomainParams {\r\n  rpc: Rpc<GetAccountInfoApi>;\r\n  domain: string;\r\n  newOwner: Address;\r\n  classAddress?: Address;\r\n  parentAddress?: Address;\r\n  parentOwner?: Address;\r\n}\r\n\r\n/**\r\n * Transfers a domain 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 *   - `domain`: The name of the domain to be transferred.\r\n *   - `newOwner`: The address of the new owner of the domain.\r\n *   - `classAddress`: (Optional) The address of the class associated with the domain.\r\n *   - `parentAddress`: (Optional) The address of the parent domain.\r\n *   - `parentOwner`: (Optional) The address of the parent domain owner.\r\n * @returns A promise that resolves to the transfer domain instruction.\r\n */\r\nexport const transferDomain = async ({\r\n  rpc,\r\n  domain,\r\n  newOwner,\r\n  classAddress,\r\n  parentAddress,\r\n  parentOwner,\r\n}: TransferDomainParams): Promise<IInstruction> => {\r\n  const domainAddress = await deriveAddress(\r\n    domain,\r\n    parentAddress,\r\n    classAddress\r\n  );\r\n\r\n  const currentOwner =\r\n    classAddress || (await RegistryState.retrieve(rpc, domainAddress)).owner;\r\n\r\n  const transferInstr = new TransferInstruction({ newOwner }).getInstruction(\r\n    NAME_PROGRAM_ADDRESS,\r\n    domainAddress,\r\n    currentOwner,\r\n    classAddress,\r\n    parentAddress,\r\n    parentOwner\r\n  );\r\n\r\n  return transferInstr;\r\n};\r\n"],"names":["async","rpc","domain","newOwner","classAddress","parentAddress","parentOwner","domainAddress","deriveAddress","currentOwner","RegistryState","retrieve","owner","TransferInstruction","getInstruction","NAME_PROGRAM_ADDRESS"],"mappings":"iNA4B8BA,OAC5BC,MACAC,SACAC,WACAC,eACAC,gBACAC,kBAEA,MAAMC,QAAsBC,EAAAA,cAC1BN,EACAG,EACAD,GAGIK,EACJL,UAAuBM,EAAAA,cAAcC,SAASV,EAAKM,IAAgBK,MAWrE,OATsB,IAAIC,EAAAA,oBAAoB,CAAEV,aAAYW,eAC1DC,EAAoBA,qBACpBR,EACAE,EACAL,EACAC,EACAC,EAGkB"}