{"version":3,"file":"context.mjs","names":[],"sources":["../../src/queries/context.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { DeepBookCompatibleClient } from '../client.js';\nimport type { BalanceManagerContract } from '../transactions/balanceManager.js';\nimport type { DeepBookContract } from '../transactions/deepbook.js';\nimport type { MarginManagerContract } from '../transactions/marginManager.js';\nimport type { MarginPoolContract } from '../transactions/marginPool.js';\nimport type { MarginRegistryContract } from '../transactions/marginRegistry.js';\nimport type { MarginTPSLContract } from '../transactions/marginTPSL.js';\nimport type { DeepBookConfig } from '../utils/config.js';\n\nexport interface QueryContext {\n\tclient: DeepBookCompatibleClient;\n\tconfig: DeepBookConfig;\n\taddress: string;\n\tbalanceManager: BalanceManagerContract;\n\tdeepBook: DeepBookContract;\n\tmarginManager: MarginManagerContract;\n\tmarginPool: MarginPoolContract;\n\tmarginRegistry: MarginRegistryContract;\n\tmarginTPSL: MarginTPSLContract;\n}\n\nexport function formatTokenAmount(rawAmount: bigint, scalar: number, decimals: number): string {\n\tconst scalarBigInt = BigInt(scalar);\n\tconst integerPart = rawAmount / scalarBigInt;\n\tconst fractionalPart = rawAmount % scalarBigInt;\n\n\tif (fractionalPart === 0n) {\n\t\treturn integerPart.toString();\n\t}\n\n\tconst scalarDigits = scalar.toString().length - 1;\n\tconst fractionalStr = fractionalPart.toString().padStart(scalarDigits, '0');\n\tconst truncated = fractionalStr.slice(0, decimals);\n\tconst trimmed = truncated.replace(/0+$/, '');\n\n\tif (!trimmed) {\n\t\treturn integerPart.toString();\n\t}\n\n\treturn `${integerPart}.${trimmed}`;\n}\n"],"mappings":";AAwBA,SAAgB,kBAAkB,WAAmB,QAAgB,UAA0B;CAC9F,MAAM,eAAe,OAAO,OAAO;CACnC,MAAM,cAAc,YAAY;CAChC,MAAM,iBAAiB,YAAY;AAEnC,KAAI,mBAAmB,GACtB,QAAO,YAAY,UAAU;CAG9B,MAAM,eAAe,OAAO,UAAU,CAAC,SAAS;CAGhD,MAAM,UAFgB,eAAe,UAAU,CAAC,SAAS,cAAc,IAAI,CAC3C,MAAM,GAAG,SAAS,CACxB,QAAQ,OAAO,GAAG;AAE5C,KAAI,CAAC,QACJ,QAAO,YAAY,UAAU;AAG9B,QAAO,GAAG,YAAY,GAAG"}