{"version":3,"file":"amount-Bd1Whvv5-25_jSyYY.cjs","names":["BaseError","ContractFunctionRevertedError","InvalidAmount"],"sources":["../../adapter-evm-core/dist/amount-Bd1Whvv5.mjs"],"sourcesContent":["import { BaseError, ContractFunctionRevertedError, decodeErrorResult } from \"viem\";\nimport { InvalidAmount } from \"@openzeppelin/ui-types\";\n\n//#region src/shared/revert-info.ts\n/**\n* Shared viem revert-info extraction.\n*\n* Capability error mappers (ERC-3643, ERC-4626, …) classify a raw execution failure into a\n* typed `RICapabilityError`. They all need the same signals out of the raw error: the\n* top-level messages, and — when it is a viem error — the structured revert `reason`, the\n* decoded custom-error `errorName`, and the raw 4-byte selector reached by walking the error\n* chain. This module owns that extraction so each mapper only supplies its keyword policy.\n*\n* Custom-error contracts: when the executor's viem instance carried the contract ABI, the\n* decoded name flows through `data.errorName`. When it did not (name absent but raw revert\n* bytes present), the caller's optional `customErrorAbi` is used to decode the name; failing\n* that, the bare 4-byte selector is surfaced for diagnosis.\n*\n* @module shared/revert-info\n*/\n/** Builtin Solidity error names viem decodes; not treated as custom-error names. */\nconst BUILTIN_ERROR_NAMES = new Set([\"Error\", \"Panic\"]);\n/** Best-effort decode of raw revert bytes against a vendored custom-error ABI. */\nfunction decodeCustomError(raw, customErrorAbi) {\n\tif (customErrorAbi.length === 0) return void 0;\n\ttry {\n\t\treturn decodeErrorResult({\n\t\t\tabi: customErrorAbi,\n\t\t\tdata: raw\n\t\t}).errorName;\n\t} catch {\n\t\treturn;\n\t}\n}\n/**\n* Pull every available signal out of a raw execution error: top-level messages, and — when\n* it is a viem error — the structured revert `reason`, decoded custom-error `errorName`, and\n* raw selector reached by walking the error chain.\n*\n* @param error - The underlying execution error.\n* @param customErrorAbi - Optional vendored custom-error ABI for name recovery when viem\n*   could not decode the error itself. Defaults to empty (string-revert contracts).\n*/\nfunction extractRevertInfo(error, customErrorAbi = []) {\n\tconst texts = [];\n\tif (error.message) texts.push(error.message);\n\tconst short = error.shortMessage;\n\tif (short) texts.push(short);\n\tlet errorName;\n\tlet selector;\n\tif (error instanceof BaseError) {\n\t\tconst revert = error.walk((e) => e instanceof ContractFunctionRevertedError);\n\t\tif (revert instanceof ContractFunctionRevertedError) {\n\t\t\tif (revert.reason) texts.push(revert.reason);\n\t\t\tconst decodedName = revert.data?.errorName;\n\t\t\tif (decodedName && !BUILTIN_ERROR_NAMES.has(decodedName)) errorName = decodedName;\n\t\t\tif (!errorName && revert.raw && revert.raw !== \"0x\") {\n\t\t\t\terrorName = decodeCustomError(revert.raw, customErrorAbi);\n\t\t\t\tif (!errorName) selector = revert.signature ?? revert.raw.slice(0, 10);\n\t\t\t}\n\t\t}\n\t}\n\tif (errorName) texts.push(errorName);\n\treturn {\n\t\terrorName,\n\t\tselector,\n\t\tsearchText: texts.join(\" \").toLowerCase()\n\t};\n}\n/** Whether `text` includes any of the given needles. */\nconst includesAny = (text, needles) => needles.some((needle) => text.includes(needle));\n\n//#endregion\n//#region src/shared/amount.ts\n/**\n* Shared base-unit amount codec.\n*\n* Chain-agnostic capability interfaces exchange token/share quantities as base-unit\n* decimal `string`s (FR-003a). This module is the single conversion + validation\n* boundary between those strings and the native `bigint` used by viem.\n*\n* A valid base-unit amount is a non-negative integer with no decimal point, sign,\n* whitespace, or scientific notation (e.g. `'1000000000000000000'`). Anything else is\n* rejected with {@link InvalidAmount} **before** any RPC or transaction submission.\n*\n* Reused by the ERC-3643, ERC-4626, and IRS capability services.\n*\n* @module shared/amount\n*/\n/** Canonical base-unit amount: one or more decimal digits, nothing else. */\nconst BASE_UNIT_PATTERN = /^\\d+$/;\n/**\n* Classifies why an amount string is not a valid base-unit decimal, for actionable errors.\n*/\nfunction classifyInvalidAmount(value) {\n\tif (value.length === 0) return \"empty\";\n\tif (/\\s/.test(value)) return \"whitespace\";\n\tif (value.startsWith(\"-\")) return \"negative\";\n\tif (value.startsWith(\"+\")) return \"signed\";\n\tif (value.includes(\".\")) return \"fractional\";\n\tif (/e/i.test(value)) return \"scientific-notation\";\n\treturn \"not-an-integer\";\n}\n/**\n* Parse a base-unit decimal `string` into a `bigint`.\n*\n* @param value - The base-unit amount string (non-negative integer, no decimal/sign/exponent).\n* @param contractAddress - Optional contract address for error context.\n* @returns The amount as a `bigint`.\n* @throws {InvalidAmount} When `value` is not a non-negative base-unit decimal string.\n*/\nfunction parseAmount(value, contractAddress) {\n\tif (typeof value !== \"string\" || !BASE_UNIT_PATTERN.test(value)) {\n\t\tconst reason = classifyInvalidAmount(typeof value === \"string\" ? value : String(value));\n\t\tthrow new InvalidAmount(`Invalid base-unit amount \"${value}\" (${reason}); expected a non-negative integer string.`, String(value), reason, contractAddress);\n\t}\n\treturn BigInt(value);\n}\n/**\n* Format a non-negative `bigint` as a base-unit decimal `string`.\n*\n* @param value - The amount as a `bigint` (must be non-negative).\n* @param contractAddress - Optional contract address for error context.\n* @returns The base-unit decimal string.\n* @throws {InvalidAmount} When `value` is negative.\n*/\nfunction formatAmount(value, contractAddress) {\n\tif (typeof value !== \"bigint\" || value < 0n) throw new InvalidAmount(`Invalid base-unit amount \"${value}\" (negative); expected a non-negative integer.`, String(value), \"negative\", contractAddress);\n\treturn value.toString();\n}\n\n//#endregion\nexport { includesAny as i, parseAmount as n, extractRevertInfo as r, formatAmount as t };\n//# sourceMappingURL=amount-Bd1Whvv5.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAM,sBAAsB,IAAI,IAAI,CAAC,SAAS,QAAQ,CAAC;;AAEvD,SAAS,kBAAkB,KAAK,gBAAgB;AAC/C,KAAI,eAAe,WAAW,EAAG,QAAO,KAAK;AAC7C,KAAI;AACH,qCAAyB;GACxB,KAAK;GACL,MAAM;GACN,CAAC,CAAC;SACI;AACP;;;;;;;;;;;;AAYF,SAAS,kBAAkB,OAAO,iBAAiB,EAAE,EAAE;CACtD,MAAM,QAAQ,EAAE;AAChB,KAAI,MAAM,QAAS,OAAM,KAAK,MAAM,QAAQ;CAC5C,MAAM,QAAQ,MAAM;AACpB,KAAI,MA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