forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.cjs.map
More file actions
1 lines (1 loc) · 4.18 KB
/
Copy pathmodels.cjs.map
File metadata and controls
1 lines (1 loc) · 4.18 KB
1
{"version":3,"sources":["../src/models/common.ts"],"names":[],"mappings":";;;AA2EA,IAAM,sBAAA,GAAyB,eAAA;AAYxB,SAAS,qBAAqB,KAAA,EAAiC;AACpE,EAAA,IACE,OAAO,MAAM,MAAA,KAAW,QAAA,IACxB,CAAC,sBAAA,CAAuB,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EACzC;AACA,IAAA,MAAM,IAAI,UAAA;AAAA,MACR,CAAA,yDAAA,EAA4D,IAAA,CAAK,SAAA,CAAU,KAAA,CAAM,MAAM,CAAC,CAAA,CAAA;AAAA,KAC1F;AAAA,EACF;AACA,EAAA,MAAM,CAAC,WAAW,EAAA,EAAI,WAAA,GAAc,EAAE,CAAA,GAAI,KAAA,CAAM,MAAA,CAAO,KAAA,CAAM,GAAG,CAAA;AAChE,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,OAAA,CAAQ,WAAA,EAAa,EAAE,CAAA;AAC9C,EAAA,MAAM,QAAA,GAAW,YAAY,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,CAAE,MAAA,CAAO,GAAG,GAAG,CAAA;AACtD,EAAA,OAAO,EAAE,GAAG,KAAA,EAAO,MAAA,EAAQ,GAAG,KAAK,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,EAAG;AACpD","file":"models.cjs","sourcesContent":["export interface AuditMetadata {\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface PaginationQuery {\n limit?: number;\n cursor?: string;\n}\n\n/**\n * Represents a monetary amount and currency/asset identifier within Lily Protocol\n * and the underlying Stellar network.\n *\n * All amounts must be formatted as base-10 decimal strings (e.g. `'10.50'`) rather than\n * JavaScript numbers to prevent floating-point precision loss and truncation errors.\n *\n * ### Stellar Asset Semantics:\n * - **Native Asset (`XLM`):** Omit `assetIssuer` (or set to `undefined`). Native Stellar Lumens\n * have no issuing account.\n * - **Issued Assets (e.g. `USDC`, `EURC`):** Specify `assetCode` (1-12 alphanumeric chars) and\n * `assetIssuer` (56-character Stellar public key / G-address).\n * - **Precision:** Stellar supports up to 7 decimal places (1 stroop = `0.0000001`).\n *\n * @example\n * ```ts\n * // Native Stellar Lumens\n * const nativeAmount: MoneyAmount = {\n * assetCode: 'XLM',\n * amount: '25.5000000',\n * };\n *\n * // Issued asset with issuer public key\n * const usdcAmount: MoneyAmount = {\n * assetCode: 'USDC',\n * assetIssuer: 'GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN',\n * amount: '100.00',\n * };\n * ```\n */\nexport interface MoneyAmount {\n /**\n * The asset code representing the currency or token.\n *\n * For the native network asset, use `'XLM'`. For credit/issued assets, use a 1-to-12 character\n * alphanumeric code (Alpha4: 1-4 chars like `'USDC'`; Alpha12: 5-12 chars).\n */\n assetCode: string;\n\n /**\n * The 56-character Stellar public key (G-address) of the issuing account.\n *\n * - **Native asset (`XLM`):** Must be omitted or `undefined`.\n * - **Issued assets:** Required to uniquely identify the asset on Stellar (alongside `assetCode`),\n * linking to the issuer's account and home domain SEP-1 metadata.\n */\n assetIssuer?: string;\n\n /**\n * The monetary quantity formatted strictly as a base-10 decimal string (e.g., `'10.50'`, `'0.0000001'`).\n *\n * Floating-point numbers (`number`) and exponential notation (e.g., `'1e-5'`) are prohibited\n * to avoid floating-point rounding/truncation bugs. Precision should match the asset's scale,\n * up to Stellar's maximum 7 decimal places (1 stroop = 0.0000001).\n */\n amount: string;\n}\n\nexport type ResourceStatus =\n | 'pending'\n | 'active'\n | 'inactive'\n | 'failed'\n | 'paused';\n\nconst DECIMAL_AMOUNT_PATTERN = /^\\d+(\\.\\d+)?$/;\n\n/**\n * Normalizes a decimal string amount to exactly two decimal places.\n *\n * Leading zeros are stripped and the fractional part is truncated (not\n * rounded) to two digits and padded with trailing zeros, e.g.\n * `'0075.5'` becomes `'75.50'`. The input object is not mutated.\n *\n * Throws a `RangeError` when the amount is not a base-10 decimal string\n * (e.g. exponential notation like `'1e-5'` or a JavaScript number).\n */\nexport function normalizeMoneyAmount(input: MoneyAmount): MoneyAmount {\n if (\n typeof input.amount !== 'string' ||\n !DECIMAL_AMOUNT_PATTERN.test(input.amount)\n ) {\n throw new RangeError(\n `MoneyAmount.amount must be a base-10 decimal string, got ${JSON.stringify(input.amount)}.`,\n );\n }\n const [wholeRaw = '', fractionRaw = ''] = input.amount.split('.');\n const whole = wholeRaw.replace(/^0+(?=\\d)/, '');\n const fraction = fractionRaw.slice(0, 2).padEnd(2, '0');\n return { ...input, amount: `${whole}.${fraction}` };\n}\n"]}