{"version":3,"file":"balances.mjs","names":["account.loadAccount","account.balance","predictAccount.hasPosition"],"sources":["../../../src/predict/reads/balances.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { Transaction } from '@mysten/sui/transactions';\nimport type { GeneratedConfig } from '../config/generated.js';\nimport { deriveAccountWrapperIdFrom } from '../tx/common.js';\nimport { accountMoveCalls as account } from '../../account.js';\nimport * as predictAccount from '../../contracts/deepbook_predict/predict_account.js';\nimport { inspectReturns, type ReadClient } from './inspect.js';\nimport { parseU64LE } from './parse.js';\n\n// An owner's stored account balance for `coinType` (the deployment's quote coin,\n// USDC on testnet, unless the caller asks for another). Chains `account::load_account(wrapper)` →\n// `account::balance<T>(account, root, clock)`; the u64 is command 1's return —\n// see packages/account/sources/account.move:{80,86}. The clock is auto-injected by\n// the generated `balance` wrapper; the wrapper id is derived off-chain (no read).\nexport async function accountBalance(\n\tclient: ReadClient,\n\tconfig: GeneratedConfig,\n\towner: string,\n\tcoinType: string,\n): Promise<bigint> {\n\tconst tx = new Transaction();\n\tconst acct = tx.add(\n\t\taccount.loadAccount({ config, arguments: { self: deriveAccountWrapperIdFrom(config, owner) } }),\n\t);\n\ttx.add(account.balance({ config, typeArguments: [coinType], arguments: { self: acct } }));\n\tconst cmds = await inspectReturns(client, tx);\n\treturn parseU64LE(cmds[1][0]);\n}\n\n// Whether the owner's account still holds `orderId` on `marketId`. The cheap\n// on-chain validator for app-stored order ids (stale after a full close or a\n// partial-close replacement — see RedeemReceipt.replacementOrderId). Chains\n// `account::load_account(wrapper)` → `predict_account::has_position(account,\n// market_id, order_id)` — see packages/predict/sources/predict_account.move:85.\nexport async function hasPosition(\n\tclient: ReadClient,\n\tconfig: GeneratedConfig,\n\towner: string,\n\tmarketId: string,\n\torderId: bigint,\n): Promise<boolean> {\n\tconst tx = new Transaction();\n\tconst acct = tx.add(\n\t\taccount.loadAccount({ config, arguments: { self: deriveAccountWrapperIdFrom(config, owner) } }),\n\t);\n\ttx.add(\n\t\tpredictAccount.hasPosition({\n\t\t\tconfig,\n\t\t\targuments: { account: acct, expiryMarketId: marketId, orderId },\n\t\t}),\n\t);\n\tconst cmds = await inspectReturns(client, tx);\n\treturn (cmds[1][0][0] ?? 0) !== 0; // BCS bool: 1 byte\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,eACrB,QACA,QACA,OACA,UACkB;CAClB,MAAM,KAAK,IAAI,aAAa;CAC5B,MAAM,OAAO,GAAG,IACfA,YAAoB;EAAE;EAAQ,WAAW,EAAE,MAAM,2BAA2B,QAAQ,MAAM,EAAE;EAAE,CAAC,CAC/F;AACD,IAAG,IAAIC,QAAgB;EAAE;EAAQ,eAAe,CAAC,SAAS;EAAE,WAAW,EAAE,MAAM,MAAM;EAAE,CAAC,CAAC;AAEzF,QAAO,YADM,MAAM,eAAe,QAAQ,GAAG,EACtB,GAAG,GAAG;;AAQ9B,eAAsB,YACrB,QACA,QACA,OACA,UACA,SACmB;CACnB,MAAM,KAAK,IAAI,aAAa;CAC5B,MAAM,OAAO,GAAG,IACfD,YAAoB;EAAE;EAAQ,WAAW,EAAE,MAAM,2BAA2B,QAAQ,MAAM,EAAE;EAAE,CAAC,CAC/F;AACD,IAAG,IACFE,cAA2B;EAC1B;EACA,WAAW;GAAE,SAAS;GAAM,gBAAgB;GAAU;GAAS;EAC/D,CAAC,CACF;AAED,UADa,MAAM,eAAe,QAAQ,GAAG,EAChC,GAAG,GAAG,MAAM,OAAO"}