{"version":3,"file":"findCollateralByAddress.cjs","sources":["../../../../../src/plugins/collateralModule/operations/findCollateralByAddress.ts"],"sourcesContent":["import { PublicKey } from '@solana/web3.js';\n\nimport { Collateral, toCollateral } from '../models';\nimport { toCollateralAccount } from '../accounts';\nimport {\n  Operation,\n  OperationHandler,\n  OperationScope,\n  useOperation,\n} from '../../../types';\nimport { Convergence } from '../../../Convergence';\nimport { collateralMintCache } from '../cache';\n\nconst Key = 'FindCollateralByAddressOperation' as const;\n\n/**\n * Finds Collateral by a given address.\n *\n * ```ts\n * const collateral = await convergence\n *   .collateral()\n *   .findByAddress({ address: user.publicKey });\n * ```\n *\n * @group Operations\n * @category Constructors\n */\nexport const findCollateralByAddressOperation =\n  useOperation<FindCollateralByAddressOperation>(Key);\n\n/**\n * @group Operations\n * @category Types\n */\nexport type FindCollateralByAddressOperation = Operation<\n  typeof Key,\n  FindCollateralByAddressInput,\n  FindCollateralByAddressOutput\n>;\n\n/**\n * @group Operations\n * @category Inputs\n */\nexport type FindCollateralByAddressInput = {\n  /** The address of the Collateral account. */\n  address: PublicKey;\n};\n\n/**\n * @group Operations\n * @category Outputs\n */\nexport type FindCollateralByAddressOutput = Collateral;\n\n/**\n * @group Operations\n * @category Handlers\n */\nexport const findCollateralByAddressOperationHandler: OperationHandler<FindCollateralByAddressOperation> =\n  {\n    handle: async (\n      operation: FindCollateralByAddressOperation,\n      convergence: Convergence,\n      scope: OperationScope\n    ): Promise<FindCollateralByAddressOutput> => {\n      const { commitment } = scope;\n      const { address } = operation.input;\n      scope.throwIfCanceled();\n\n      const collateralMint = await collateralMintCache.get(convergence);\n\n      const account = await convergence.rpc().getAccount(address, commitment);\n      const collateralModel = toCollateral(\n        toCollateralAccount(account),\n        collateralMint\n      );\n      scope.throwIfCanceled();\n\n      return collateralModel;\n    },\n  };\n"],"names":["Key","findCollateralByAddressOperation","useOperation","findCollateralByAddressOperationHandler","handle","_handle","_asyncToGenerator","_regeneratorRuntime","mark","_callee","operation","convergence","scope","commitment","address","collateralMint","account","collateralModel","wrap","_callee$","_context","prev","next","input","throwIfCanceled","collateralMintCache","get","sent","rpc","getAccount","toCollateral","toCollateralAccount","abrupt","stop","_x","_x2","_x3","apply","arguments"],"mappings":";;;;;;;;;;AAaA,IAAMA,GAAG,GAAG,kCAA2C,CAAA;;AAEvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACaC,gCAAgC,GAC3CC,sBAAY,CAAmCF,GAAG,EAAC;;AAErD;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACO,IAAMG,uCAA2F,GACtG;EACEC,MAAM,EAAA,YAAA;AAAA,IAAA,IAAAC,OAAA,GAAAC,0CAAA,eAAAC,4CAAA,EAAAC,CAAAA,IAAA,CAAE,SAAAC,OACNC,CAAAA,SAA2C,EAC3CC,WAAwB,EACxBC,KAAqB,EAAA;MAAA,IAAAC,UAAA,EAAAC,OAAA,EAAAC,cAAA,EAAAC,OAAA,EAAAC,eAAA,CAAA;AAAA,MAAA,OAAAV,4CAAA,EAAA,CAAAW,IAAA,CAAA,SAAAC,SAAAC,QAAA,EAAA;AAAA,QAAA,OAAA,CAAA,EAAA,QAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAE,IAAA;AAAA,UAAA,KAAA,CAAA;YAEbT,UAAU,GAAKD,KAAK,CAApBC,UAAU,CAAA;AACVC,YAAAA,OAAO,GAAKJ,SAAS,CAACa,KAAK,CAA3BT,OAAO,CAAA;YACfF,KAAK,CAACY,eAAe,EAAE,CAAA;AAACJ,YAAAA,QAAA,CAAAE,IAAA,GAAA,CAAA,CAAA;AAAA,YAAA,OAEKG,yBAAmB,CAACC,GAAG,CAACf,WAAW,CAAC,CAAA;AAAA,UAAA,KAAA,CAAA;YAA3DI,cAAc,GAAAK,QAAA,CAAAO,IAAA,CAAA;AAAAP,YAAAA,QAAA,CAAAE,IAAA,GAAA,CAAA,CA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