{"version":3,"file":"transfer-policy.mjs","names":["transferPolicy._new","transferPolicy.withdraw"],"sources":["../../src/tx/transfer-policy.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';\n\nimport type { ObjectArgument } from '../types/index.js';\nimport * as transferPolicy from '../contracts/0x2/transfer_policy.js';\n\n/**\n * Call the `transfer_policy::new` function to create a new transfer policy.\n * Returns `transferPolicyCap`\n */\nexport function createTransferPolicy(\n\ttx: Transaction,\n\titemType: string,\n\tpublisher: ObjectArgument,\n): TransactionObjectArgument {\n\tconst [policy, policyCap] = tx.add(\n\t\ttransferPolicy._new({\n\t\t\targuments: [publisher],\n\t\t\ttypeArguments: [itemType],\n\t\t}),\n\t);\n\n\ttx.moveCall({\n\t\ttarget: '0x2::transfer::public_share_object',\n\t\targuments: [policy],\n\t\ttypeArguments: [`0x2::transfer_policy::TransferPolicy<${itemType}>`],\n\t});\n\n\treturn policyCap;\n}\n\n/**\n * Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.\n */\nexport function withdrawFromPolicy(\n\ttx: Transaction,\n\titemType: string,\n\tpolicy: ObjectArgument,\n\tpolicyCap: ObjectArgument,\n\tamount?: string | bigint | null,\n): TransactionObjectArgument {\n\t// Convert string to bigint if needed for the generated function\n\tconst amountArg: bigint | null = amount\n\t\t? typeof amount === 'string'\n\t\t\t? BigInt(amount)\n\t\t\t: amount\n\t\t: null;\n\n\tconst [profits] = tx.add(\n\t\ttransferPolicy.withdraw({\n\t\t\targuments: [policy, policyCap, amountArg],\n\t\t\ttypeArguments: [itemType],\n\t\t}),\n\t);\n\n\treturn profits;\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,qBACf,IACA,UACA,WAC4B;CAC5B,MAAM,CAAC,QAAQ,aAAa,GAAG,IAC9BA,KAAoB;EACnB,WAAW,CAAC,UAAU;EACtB,eAAe,CAAC,SAAS;EACzB,CAAC,CACF;AAED,IAAG,SAAS;EACX,QAAQ;EACR,WAAW,CAAC,OAAO;EACnB,eAAe,CAAC,wCAAwC,SAAS,GAAG;EACpE,CAAC;AAEF,QAAO;;;;;AAMR,SAAgB,mBACf,IACA,UACA,QACA,WACA,QAC4B;CAE5B,MAAM,YAA2B,SAC9B,OAAO,WAAW,WACjB,OAAO,OAAO,GACd,SACD;CAEH,MAAM,CAAC,WAAW,GAAG,IACpBC,SAAwB;EACvB,WAAW;GAAC;GAAQ;GAAW;GAAU;EACzC,eAAe,CAAC,SAAS;EACzB,CAAC,CACF;AAED,QAAO"}