{
  "version": 3,
  "sources": ["../src/utils/units.ts"],
  "sourcesContent": [
    "/**\n * Format a bigint value with decimal places.\n * @example formatUnits(1000000n, 6) → \"1.0\"\n * @example formatUnits(1500000n, 6) → \"1.5\"\n */\nexport function formatUnits(\n\tvalue: bigint | number | string,\n\tdecimals: number,\n): string {\n\tlet v = BigInt(value);\n\n\tconst negative = v < 0n;\n\tif (negative) v = -v;\n\n\tconst divisor = 10n ** BigInt(decimals);\n\tconst integer = (v / divisor).toString();\n\tlet fraction = (v % divisor).toString().padStart(decimals, \"0\");\n\n\t// Trim trailing zeros, but keep at least one decimal\n\tfraction = fraction.replace(/0+$/, \"\") || \"0\";\n\n\tconst result = `${integer}.${fraction}`;\n\treturn negative ? `-${result}` : result;\n}\n\n/**\n * Parse a decimal string into a bigint with the given number of decimals.\n * @example parseUnits(\"1.5\", 6) → 1500000n\n * @example parseUnits(\"1\", 6) → 1000000n\n */\nconst DECIMAL_STRING = /^-?\\d+(\\.\\d+)?$/;\n\nexport function parseUnits(value: string | number, decimals: number): bigint {\n\tif (typeof value === \"number\" && !Number.isFinite(value)) {\n\t\tthrow new RangeError(`Cannot parse ${value} as a decimal amount`);\n\t}\n\t// Numbers small or large enough to print in exponent form (1e-7, 1e21)\n\t// go through toFixed so the digits survive. A number the fixed form\n\t// cannot hold exactly (too many decimals, or too small for one unit) is\n\t// refused rather than rounded, so amounts never shrink silently.\n\tlet str = typeof value === \"number\" ? value.toFixed(decimals) : value.trim();\n\tif (!DECIMAL_STRING.test(str)) {\n\t\tthrow new RangeError(\n\t\t\t`Cannot parse \"${value}\" as a decimal amount: expected digits with an optional fraction, like \"1.5\"`,\n\t\t);\n\t}\n\tif (typeof value === \"number\" && Number(str) !== value) {\n\t\tthrow new RangeError(\n\t\t\t`Cannot parse ${value} with ${decimals} decimals: pass the amount as a string to keep every digit`,\n\t\t);\n\t}\n\n\tconst negative = str.startsWith(\"-\");\n\tif (negative) str = str.slice(1);\n\n\tconst [integer = \"\", fraction = \"\"] = str.split(\".\");\n\n\tif (fraction.length > decimals) {\n\t\tthrow new Error(\n\t\t\t`Too many decimal places: \"${value}\" has ${fraction.length} decimals, max is ${decimals}`,\n\t\t);\n\t}\n\n\tconst padded = fraction.padEnd(decimals, \"0\");\n\tconst result = BigInt(integer + padded);\n\treturn negative ? -result : result;\n}\n\n/**\n * Format microSTX to STX string (6 decimals).\n * @example formatStx(1000000n) → \"1.0\"\n */\nexport function formatStx(microStx: bigint | number | string): string {\n\treturn formatUnits(microStx, 6);\n}\n\n/**\n * Parse STX string to microSTX bigint (6 decimals).\n * @example parseStx(\"1.5\") → 1500000n\n */\nexport function parseStx(stx: string | number): bigint {\n\treturn parseUnits(stx, 6);\n}\n"
  ],
  "mappings": ";AAKO,SAAS,WAAW,CAC1B,OACA,UACS;AAAA,EACT,IAAI,IAAI,OAAO,KAAK;AAAA,EAEpB,MAAM,WAAW,IAAI;AAAA,EACrB,IAAI;AAAA,IAAU,IAAI,CAAC;AAAA,EAEnB,MAAM,UAAU,OAAO,OAAO,QAAQ;AAAA,EACtC,MAAM,WAAW,IAAI,SAAS,SAAS;AAAA,EACvC,IAAI,YAAY,IAAI,SAAS,SAAS,EAAE,SAAS,UAAU,GAAG;AAAA,EAG9D,WAAW,SAAS,QAAQ,OAAO,EAAE,KAAK;AAAA,EAE1C,MAAM,SAAS,GAAG,WAAW;AAAA,EAC7B,OAAO,WAAW,IAAI,WAAW;AAAA;AAQlC,IAAM,iBAAiB;AAEhB,SAAS,UAAU,CAAC,OAAwB,UAA0B;AAAA,EAC5E,IAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,GAAG;AAAA,IACzD,MAAM,IAAI,WAAW,gBAAgB,2BAA2B;AAAA,EACjE;AAAA,EAKA,IAAI,MAAM,OAAO,UAAU,WAAW,MAAM,QAAQ,QAAQ,IAAI,MAAM,KAAK;AAAA,EAC3E,IAAI,CAAC,eAAe,KAAK,GAAG,GAAG;AAAA,IAC9B,MAAM,IAAI,WACT,i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