@piprail/sdk 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/{algorand-AA3WXKW4.js → algorand-6J3IABVF.js} +12 -11
  3. package/dist/{algorand-FCEECDG6.cjs → algorand-QU6G2DQZ.cjs} +43 -42
  4. package/dist/{aptos-LY67Q6QF.js → aptos-DHOMTBLZ.js} +11 -10
  5. package/dist/{aptos-GHJPO6JJ.cjs → aptos-LFTQGBBK.cjs} +41 -40
  6. package/dist/{chunk-MWBT7MCE.cjs → chunk-GYM46G5L.cjs} +22 -4
  7. package/dist/{chunk-SC2ZYDHD.js → chunk-PAMKCWVW.js} +22 -4
  8. package/dist/index.cjs +505 -234
  9. package/dist/index.d.cts +281 -12
  10. package/dist/index.d.ts +281 -12
  11. package/dist/index.js +302 -31
  12. package/dist/{ledger-mF_SoiDB.d.ts → ledger-uFtXlIHY.d.cts} +31 -1
  13. package/dist/{ledger-mF_SoiDB.d.cts → ledger-uFtXlIHY.d.ts} +31 -1
  14. package/dist/{near-FZBUICCS.js → near-5PXTVQ47.js} +14 -5
  15. package/dist/{near-6KAQVVG2.cjs → near-YNNK7RW7.cjs} +39 -30
  16. package/dist/node.d.cts +2 -2
  17. package/dist/node.d.ts +2 -2
  18. package/dist/{solana-ELUWO6N5.js → solana-HITVI3HF.js} +22 -7
  19. package/dist/{solana-MYF4HBO4.cjs → solana-N3UCNCYE.cjs} +54 -39
  20. package/dist/{stellar-ASP2THL2.js → stellar-2QT6YYKN.js} +4 -4
  21. package/dist/{stellar-CRWBSX4E.cjs → stellar-Y3SQN7S5.cjs} +23 -23
  22. package/dist/{sui-Y4RLKKE2.cjs → sui-4AL4E6XU.cjs} +35 -27
  23. package/dist/{sui-FZIKZNVI.js → sui-FV5L6WF5.js} +20 -12
  24. package/dist/{ton-7GKCTC5H.js → ton-5FWDQ4QR.js} +18 -7
  25. package/dist/{ton-AOR3EURW.cjs → ton-5HDVOTMR.cjs} +33 -22
  26. package/dist/{tron-BMCWN5SS.js → tron-AZDY7BMQ.js} +10 -10
  27. package/dist/{tron-OMXB6EW2.cjs → tron-TX2B4N2A.cjs} +39 -39
  28. package/dist/{xrpl-Y6SQNYLC.cjs → xrpl-5TYDLQFS.cjs} +31 -31
  29. package/dist/{xrpl-DD7TJL5L.js → xrpl-UJL5J7CY.js} +13 -13
  30. package/package.json +1 -1
@@ -9,7 +9,7 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkMWBT7MCEcjs = require('./chunk-MWBT7MCE.cjs');
12
+ var _chunkGYM46G5Lcjs = require('./chunk-GYM46G5L.cjs');
13
13
 
14
14
  // src/drivers/aptos/index.ts
15
15
  var _tssdk = require('@aptos-labs/ts-sdk');
@@ -58,14 +58,14 @@ async function payAptos(params) {
58
58
  const res = await client.signSubmit({ signer, transaction });
59
59
  return res.hash;
60
60
  } catch (err) {
61
- if (err instanceof _chunkMWBT7MCEcjs.InsufficientFundsError) throw err;
61
+ if (err instanceof _chunkGYM46G5Lcjs.InsufficientFundsError) throw err;
62
62
  if (isAptosAffordability(err)) {
63
- throw new (0, _chunkMWBT7MCEcjs.InsufficientFundsError)(
63
+ throw new (0, _chunkGYM46G5Lcjs.InsufficientFundsError)(
64
64
  err instanceof Error ? err.message : "Insufficient APT/token balance for the payment.",
65
65
  { cause: err }
66
66
  );
67
67
  }
68
- throw _nullishCoalesce(_chunkMWBT7MCEcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
68
+ throw _nullishCoalesce(_chunkGYM46G5Lcjs.toInsufficientFundsError.call(void 0, err), () => ( err));
69
69
  }
70
70
  }
71
71
  function isAptosAffordability(err) {
@@ -103,24 +103,24 @@ function parseAddr(addr) {
103
103
  async function payExactAptos(input) {
104
104
  const { client, sender, accept } = input;
105
105
  if (accept.asset === "native") {
106
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
106
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
107
107
  "Aptos exact is Fungible-Asset only (a primary_fungible_store transfer); native APT is not exact-payable. Pay via onchain-proof."
108
108
  );
109
109
  }
110
110
  const feePayer = accept.extra.feePayer;
111
111
  if (!feePayer) {
112
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)("Aptos exact rail must advertise extra.feePayer (the gas sponsor address).");
112
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)("Aptos exact rail must advertise extra.feePayer (the gas sponsor address).");
113
113
  }
114
114
  const feePayerAddr = parseAddr(feePayer);
115
- if (!feePayerAddr) throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`Aptos exact: extra.feePayer "${feePayer}" is not a valid Aptos address.`);
115
+ if (!feePayerAddr) throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(`Aptos exact: extra.feePayer "${feePayer}" is not a valid Aptos address.`);
116
116
  const payToAddr = parseAddr(accept.payTo);
117
- if (!payToAddr) throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`Aptos exact: payTo "${accept.payTo}" is not a valid Aptos address.`);
117
+ if (!payToAddr) throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(`Aptos exact: payTo "${accept.payTo}" is not a valid Aptos address.`);
118
118
  const metadataAddr = parseAddr(accept.asset);
119
- if (!metadataAddr) throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`Aptos exact: asset "${accept.asset}" is not a valid FA metadata address.`);
119
+ if (!metadataAddr) throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(`Aptos exact: asset "${accept.asset}" is not a valid FA metadata address.`);
120
120
  const senderAddr = parseAddr(sender);
121
- if (!senderAddr) throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(`Aptos exact: payer "${sender}" is not a valid Aptos address.`);
121
+ if (!senderAddr) throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(`Aptos exact: payer "${sender}" is not a valid Aptos address.`);
122
122
  if (feePayerAddr.equals(senderAddr)) {
123
- throw new (0, _chunkMWBT7MCEcjs.UnsupportedSchemeError)(
123
+ throw new (0, _chunkGYM46G5Lcjs.UnsupportedSchemeError)(
124
124
  "Aptos exact: the fee payer must differ from the payer \u2014 the buyer must pay ZERO APT (the sponsor pays gas)."
125
125
  );
126
126
  }
@@ -158,16 +158,16 @@ function argBytes(arg) {
158
158
  async function verifyAndSettleExactAptos(input) {
159
159
  const { client, feePayerAddr, payload, accept } = input;
160
160
  const railFeePayer = accept.extra.feePayer;
161
- if (!railFeePayer) throw new (0, _chunkMWBT7MCEcjs.SettlementError)("Aptos exact: rail is missing extra.feePayer.");
161
+ if (!railFeePayer) throw new (0, _chunkGYM46G5Lcjs.SettlementError)("Aptos exact: rail is missing extra.feePayer.");
162
162
  if (railFeePayer !== feePayerAddr) {
163
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)("Aptos exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
163
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)("Aptos exact: the gate relayer address does not match the rail extra.feePayer \u2014 misconfigured rail.");
164
164
  }
165
- if (accept.asset === "native") throw new (0, _chunkMWBT7MCEcjs.SettlementError)("Aptos exact: native APT is not exact-payable (misconfigured rail).");
165
+ if (accept.asset === "native") throw new (0, _chunkGYM46G5Lcjs.SettlementError)("Aptos exact: native APT is not exact-payable (misconfigured rail).");
166
166
  const railFeePayerAddr = parseAddr(railFeePayer);
167
167
  const railPayTo = parseAddr(accept.payTo);
168
168
  const railMetadata = parseAddr(accept.asset);
169
169
  if (!railFeePayerAddr || !railPayTo || !railMetadata) {
170
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)("Aptos exact: rail feePayer/payTo/asset is not a valid Aptos address (misconfigured rail).");
170
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)("Aptos exact: rail feePayer/payTo/asset is not a valid Aptos address (misconfigured rail).");
171
171
  }
172
172
  let tx;
173
173
  let senderAuth;
@@ -241,7 +241,7 @@ async function verifyAndSettleExactAptos(input) {
241
241
  try {
242
242
  feePayerAuth = client.signAsFeePayer({ transaction: tx });
243
243
  } catch (err) {
244
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(`Aptos exact settle: the gate could not sign as fee payer (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
244
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(`Aptos exact settle: the gate could not sign as fee payer (${shorten(err instanceof Error ? err.message : String(err))}).`, { cause: err });
245
245
  }
246
246
  if (senderAuth instanceof _tssdk.AccountAuthenticatorEd25519) {
247
247
  try {
@@ -264,7 +264,7 @@ async function verifyAndSettleExactAptos(input) {
264
264
  if (/signature|invalid.*auth|INVALID_SIGNATURE/i.test(m)) return fail("signature_invalid", `Settle rejected \u2014 bad signature: ${shorten(m)}.`);
265
265
  if (/SEQUENCE_NUMBER_TOO_OLD|already.*(committed|ledger)|duplicate/i.test(m)) return fail("tx_already_used", `This payment was already settled: ${shorten(m)}.`);
266
266
  if (/EXPIRED|expired|TOO_NEW/i.test(m)) return fail("payment_expired", `Settle rejected \u2014 expired/stale: ${shorten(m)}.`);
267
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(
267
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(
268
268
  `Aptos exact settle: the transaction failed to submit (${shorten(m)}). The buyer's signed transaction is still valid \u2014 fund/fix the fee payer (${railFeePayer}) and the buyer can re-present it.`,
269
269
  { cause: err }
270
270
  );
@@ -273,10 +273,10 @@ async function verifyAndSettleExactAptos(input) {
273
273
  try {
274
274
  confirmed = await client.waitForConfirmation(hash);
275
275
  } catch (err) {
276
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
276
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but confirmation read failed (${shorten(err instanceof Error ? err.message : String(err))}). It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`, { cause: err });
277
277
  }
278
278
  if (confirmed === null) {
279
- throw new (0, _chunkMWBT7MCEcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
279
+ throw new (0, _chunkGYM46G5Lcjs.SettlementError)(`Aptos exact settle: submitted ${hash} but it did not confirm in time. It likely landed \u2014 re-verify before re-presenting; do NOT re-pay.`);
280
280
  }
281
281
  if (!confirmed.success) {
282
282
  return fail("tx_reverted", `Settle tx ${hash} reverted on-chain (a post-simulate race).`);
@@ -312,15 +312,16 @@ async function verifyAptos(params) {
312
312
  if (!tx.success) {
313
313
  return { ok: false, error: "tx_reverted", detail: `Aptos tx ${hash} did not succeed.` };
314
314
  }
315
- if (typeof tx.timestampSeconds === "number") {
316
- const ageSeconds = Math.floor(Date.now() / 1e3) - tx.timestampSeconds;
317
- if (ageSeconds > accept.maxTimeoutSeconds) {
318
- return {
319
- ok: false,
320
- error: "payment_expired",
321
- detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
322
- };
323
- }
315
+ if (!Number.isFinite(tx.timestampSeconds)) {
316
+ return { ok: false, error: "payment_expired", detail: `Cannot bound the age of Aptos tx ${hash} (no/invalid timestamp) \u2014 failing closed.` };
317
+ }
318
+ const ageSeconds = Math.floor(Date.now() / 1e3) - tx.timestampSeconds;
319
+ if (!Number.isFinite(ageSeconds) || ageSeconds > accept.maxTimeoutSeconds) {
320
+ return {
321
+ ok: false,
322
+ error: "payment_expired",
323
+ detail: `Payment is ${ageSeconds}s old; max allowed is ${accept.maxTimeoutSeconds}s.`
324
+ };
324
325
  }
325
326
  let wantStore;
326
327
  try {
@@ -371,13 +372,13 @@ function txNotFound(hash) {
371
372
 
372
373
  function assertAptosWallet(wallet, network) {
373
374
  if (typeof wallet !== "object" || wallet === null) {
374
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
375
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
375
376
  `chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
376
377
  );
377
378
  }
378
- _chunkMWBT7MCEcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Aptos");
379
+ _chunkGYM46G5Lcjs.assertNoLegacyWalletKey.call(void 0, wallet, "Aptos");
379
380
  if (!("key" in wallet) && !("account" in wallet)) {
380
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
381
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
381
382
  `chain ${network} is Aptos; wallet must be { key } (ed25519-priv-0x\u2026) or { account }.`
382
383
  );
383
384
  }
@@ -389,13 +390,13 @@ function resolveAptosAccount(config) {
389
390
  try {
390
391
  return _tssdk.Account.fromPrivateKey({ privateKey: new (0, _tssdk.Ed25519PrivateKey)(config.key) });
391
392
  } catch (cause) {
392
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
393
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
393
394
  "Aptos wallet { key } is not a valid ed25519 secret (ed25519-priv-0x\u2026 or 0x\u2026 hex).",
394
395
  { cause }
395
396
  );
396
397
  }
397
398
  }
398
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
399
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)("Aptos wallet needs { key } (ed25519-priv-0x\u2026) or { account }.");
399
400
  }
400
401
 
401
402
  // src/drivers/aptos/index.ts
@@ -467,16 +468,16 @@ function makeAptosNetwork(preset, rpcUrl) {
467
468
  const info = preset.tokens[token.toUpperCase()];
468
469
  if (!info) {
469
470
  const known = Object.keys(preset.tokens).join(", ") || "(none built in)";
470
- throw new (0, _chunkMWBT7MCEcjs.UnknownTokenError)(
471
+ throw new (0, _chunkGYM46G5Lcjs.UnknownTokenError)(
471
472
  `token "${token}" isn't built in for Aptos (known: ${known}). Pass { metadata, decimals } for a custom Fungible Asset, or use 'native'.`
472
473
  );
473
474
  }
474
475
  return { asset: info.metadata, decimals: info.decimals, symbol: info.symbol };
475
476
  }
476
- _chunkMWBT7MCEcjs.rejectForeignToken.call(void 0, token, "aptos", network);
477
+ _chunkGYM46G5Lcjs.rejectForeignToken.call(void 0, token, "aptos", network);
477
478
  const t = token;
478
479
  if (!t.metadata || typeof t.decimals !== "number") {
479
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
480
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
480
481
  `chain ${network} is Aptos; a custom token must be { metadata, decimals }.`
481
482
  );
482
483
  }
@@ -503,7 +504,7 @@ function makeAptosNetwork(preset, rpcUrl) {
503
504
  valid = false;
504
505
  }
505
506
  if (!valid || evmLike) {
506
- throw new (0, _chunkMWBT7MCEcjs.WrongFamilyError)(
507
+ throw new (0, _chunkGYM46G5Lcjs.WrongFamilyError)(
507
508
  `chain ${network} is Aptos, but payTo "${payTo}" is not a valid Aptos address (0x + 32 bytes).`
508
509
  );
509
510
  }
@@ -525,12 +526,12 @@ function makeAptosNetwork(preset, rpcUrl) {
525
526
  const tx = await aptos.waitForTransaction({ transactionHash: ref });
526
527
  return { height: String(_nullishCoalesce(tx.version, () => ( "0"))) };
527
528
  } catch (err) {
528
- throw new (0, _chunkMWBT7MCEcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
529
+ throw new (0, _chunkGYM46G5Lcjs.ConfirmationTimeoutError)(`Aptos tx ${ref} did not finalize in time.`, { cause: err });
529
530
  }
530
531
  },
531
532
  async estimateCost(accept) {
532
533
  if (accept.scheme === "exact") {
533
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
534
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
534
535
  symbol: APT_SYMBOL,
535
536
  decimals: APT_DECIMALS,
536
537
  fee: 0n,
@@ -538,7 +539,7 @@ function makeAptosNetwork(preset, rpcUrl) {
538
539
  detail: "gasless \u2014 the fee payer (facilitator/relayer) sponsors gas; the buyer pays 0 APT"
539
540
  });
540
541
  }
541
- return _chunkMWBT7MCEcjs.nativeCost.call(void 0, {
542
+ return _chunkGYM46G5Lcjs.nativeCost.call(void 0, {
542
543
  symbol: APT_SYMBOL,
543
544
  decimals: APT_DECIMALS,
544
545
  fee: 100000n,
@@ -40,10 +40,12 @@ var MaxRetriesExceededError = (_class5 = class extends PipRailError {
40
40
  /**
41
41
  * The proof ref — recover with it, don't re-pay. Its meaning depends on the
42
42
  * scheme: for `onchain-proof` it's the already-broadcast transaction ref
43
- * (re-verify or re-submit it). For a standard `exact` rail it's the EIP-3009
44
- * authorization NONCE (a `0x…` 32-byte value, NOT a tx hash) — re-PRESENT the
45
- * same signed authorization, never re-sign a fresh nonce; check the token's
46
- * `authorizationState(from, nonce)` before assuming it didn't settle.
43
+ * (re-verify or re-submit it). For a standard `exact` rail it's the authorization's
44
+ * single-use marker (NOT a tx hash) — re-PRESENT the same signed authorization, never
45
+ * re-sign a fresh nonce, and verify it on-chain before assuming it didn't settle. On
46
+ * EVM that marker is the EIP-3009 NONCE (a `0x…` value), checked via the token's
47
+ * `authorizationState(from, nonce)`; the non-EVM `exact` rails key off their own marker
48
+ * (Solana tx signature, Algorand group id, Aptos account sequence number, NEAR access-key nonce).
47
49
  */
48
50
 
49
51
  constructor(message, options) {
@@ -141,8 +143,23 @@ function assertValidDecimals(decimals, fn) {
141
143
  );
142
144
  }
143
145
  }
146
+ function expandScientific(value) {
147
+ const m = /^(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(value);
148
+ if (!m) return value;
149
+ const [, whole = "", frac = "", expStr = "0"] = m;
150
+ const exp = Number(expStr);
151
+ if (!Number.isFinite(exp) || Math.abs(exp) > 1e3) {
152
+ throw new Error(`expandScientific: exponent out of range in "${value}".`);
153
+ }
154
+ const digits = whole + frac;
155
+ const pointPos = whole.length + exp;
156
+ if (pointPos <= 0) return `0.${"0".repeat(-pointPos)}${digits}`;
157
+ if (pointPos >= digits.length) return digits + "0".repeat(pointPos - digits.length);
158
+ return `${digits.slice(0, pointPos)}.${digits.slice(pointPos)}`;
159
+ }
144
160
  function parseUnits(value, decimals) {
145
161
  assertValidDecimals(decimals, "parseUnits");
162
+ value = expandScientific(value);
146
163
  if (!/^\d+(\.\d+)?$/.test(value)) {
147
164
  throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
148
165
  }
@@ -157,6 +174,7 @@ function parseUnits(value, decimals) {
157
174
  }
158
175
  function floorUnits(value, decimals) {
159
176
  assertValidDecimals(decimals, "floorUnits");
177
+ value = expandScientific(value);
160
178
  if (!/^\d+(\.\d+)?$/.test(value)) {
161
179
  throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
162
180
  }
@@ -40,10 +40,12 @@ var MaxRetriesExceededError = class extends PipRailError {
40
40
  /**
41
41
  * The proof ref — recover with it, don't re-pay. Its meaning depends on the
42
42
  * scheme: for `onchain-proof` it's the already-broadcast transaction ref
43
- * (re-verify or re-submit it). For a standard `exact` rail it's the EIP-3009
44
- * authorization NONCE (a `0x…` 32-byte value, NOT a tx hash) — re-PRESENT the
45
- * same signed authorization, never re-sign a fresh nonce; check the token's
46
- * `authorizationState(from, nonce)` before assuming it didn't settle.
43
+ * (re-verify or re-submit it). For a standard `exact` rail it's the authorization's
44
+ * single-use marker (NOT a tx hash) — re-PRESENT the same signed authorization, never
45
+ * re-sign a fresh nonce, and verify it on-chain before assuming it didn't settle. On
46
+ * EVM that marker is the EIP-3009 NONCE (a `0x…` value), checked via the token's
47
+ * `authorizationState(from, nonce)`; the non-EVM `exact` rails key off their own marker
48
+ * (Solana tx signature, Algorand group id, Aptos account sequence number, NEAR access-key nonce).
47
49
  */
48
50
  ref;
49
51
  constructor(message, options) {
@@ -141,8 +143,23 @@ function assertValidDecimals(decimals, fn) {
141
143
  );
142
144
  }
143
145
  }
146
+ function expandScientific(value) {
147
+ const m = /^(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/.exec(value);
148
+ if (!m) return value;
149
+ const [, whole = "", frac = "", expStr = "0"] = m;
150
+ const exp = Number(expStr);
151
+ if (!Number.isFinite(exp) || Math.abs(exp) > 1e3) {
152
+ throw new Error(`expandScientific: exponent out of range in "${value}".`);
153
+ }
154
+ const digits = whole + frac;
155
+ const pointPos = whole.length + exp;
156
+ if (pointPos <= 0) return `0.${"0".repeat(-pointPos)}${digits}`;
157
+ if (pointPos >= digits.length) return digits + "0".repeat(pointPos - digits.length);
158
+ return `${digits.slice(0, pointPos)}.${digits.slice(pointPos)}`;
159
+ }
144
160
  function parseUnits(value, decimals) {
145
161
  assertValidDecimals(decimals, "parseUnits");
162
+ value = expandScientific(value);
146
163
  if (!/^\d+(\.\d+)?$/.test(value)) {
147
164
  throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
148
165
  }
@@ -157,6 +174,7 @@ function parseUnits(value, decimals) {
157
174
  }
158
175
  function floorUnits(value, decimals) {
159
176
  assertValidDecimals(decimals, "floorUnits");
177
+ value = expandScientific(value);
160
178
  if (!/^\d+(\.\d+)?$/.test(value)) {
161
179
  throw new Error(`floorUnits: "${value}" is not a non-negative decimal amount.`);
162
180
  }