@circle-fin/app-kit 1.15.3 → 1.17.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 (60) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +5 -2
  3. package/borrow.cjs +28146 -0
  4. package/borrow.cjs.map +1 -0
  5. package/borrow.d.cts +10752 -0
  6. package/borrow.d.mts +10752 -0
  7. package/borrow.d.ts +10752 -0
  8. package/borrow.mjs +28118 -0
  9. package/borrow.mjs.map +1 -0
  10. package/bridge.cjs +2084 -328
  11. package/bridge.d.cts +121 -18
  12. package/bridge.d.mts +121 -18
  13. package/bridge.d.ts +121 -18
  14. package/bridge.mjs +2084 -328
  15. package/chains.cjs +78 -7
  16. package/chains.d.cts +2 -0
  17. package/chains.d.mts +2 -0
  18. package/chains.d.ts +2 -0
  19. package/chains.mjs +78 -7
  20. package/context.cjs +1 -0
  21. package/context.d.cts +121 -18
  22. package/context.d.mts +121 -18
  23. package/context.d.ts +121 -18
  24. package/context.mjs +1 -0
  25. package/earn.cjs +5322 -3219
  26. package/earn.d.cts +1149 -984
  27. package/earn.d.mts +1149 -984
  28. package/earn.d.ts +1149 -984
  29. package/earn.mjs +5322 -3219
  30. package/estimateBridge.cjs +2082 -326
  31. package/estimateBridge.d.cts +121 -18
  32. package/estimateBridge.d.mts +121 -18
  33. package/estimateBridge.d.ts +121 -18
  34. package/estimateBridge.mjs +2082 -326
  35. package/estimateSwap.cjs +8817 -6974
  36. package/estimateSwap.d.cts +169 -18
  37. package/estimateSwap.d.mts +169 -18
  38. package/estimateSwap.d.ts +169 -18
  39. package/estimateSwap.mjs +8822 -6979
  40. package/index.cjs +33149 -20719
  41. package/index.d.cts +23174 -2736
  42. package/index.d.mts +23174 -2736
  43. package/index.d.ts +23174 -2736
  44. package/index.mjs +33090 -20713
  45. package/package.json +17 -7
  46. package/server.cjs +133 -12
  47. package/server.d.cts +29 -10
  48. package/server.d.mts +29 -10
  49. package/server.d.ts +29 -10
  50. package/server.mjs +133 -12
  51. package/swap.cjs +8817 -6974
  52. package/swap.d.cts +169 -18
  53. package/swap.d.mts +169 -18
  54. package/swap.d.ts +169 -18
  55. package/swap.mjs +8822 -6979
  56. package/unifiedBalance.cjs +528 -138
  57. package/unifiedBalance.d.cts +108 -11
  58. package/unifiedBalance.d.mts +108 -11
  59. package/unifiedBalance.d.ts +108 -11
  60. package/unifiedBalance.mjs +528 -138
package/server.mjs CHANGED
@@ -633,6 +633,34 @@ class KitError extends Error {
633
633
  }
634
634
  };
635
635
 
636
+ /**
637
+ * Render an object value for an error message without letting the rendering
638
+ * itself throw.
639
+ *
640
+ * `JSON.stringify` rejects `BigInt` and circular structures, and a rejected
641
+ * value is exactly the kind of thing a validation error is built from: an
642
+ * on-chain read or a receipt log carries `bigint` fields, so serializing one
643
+ * naively replaces the intended error with a `TypeError`.
644
+ *
645
+ * @param value - The value to render.
646
+ * @returns A JSON string with `bigint` fields stringified, or
647
+ * `'[unserializable object]'` if serialization still fails.
648
+ * @throws Never; serialization failures are caught and rendered as a fallback string.
649
+ * @example
650
+ * ```typescript
651
+ * import { describeObjectValue } from '@core/errors'
652
+ *
653
+ * describeObjectValue({ amount: 1n })
654
+ * // '{"amount":"1"}'
655
+ * ```
656
+ */ function describeObjectValue(value) {
657
+ try {
658
+ return JSON.stringify(value, (_key, entry)=>typeof entry === 'bigint' ? entry.toString() : entry);
659
+ } catch {
660
+ return '[unserializable object]';
661
+ }
662
+ }
663
+
636
664
  /**
637
665
  * Creates error for general validation failure.
638
666
  *
@@ -655,7 +683,7 @@ class KitError extends Error {
655
683
  * // Message: "Validation failed for 'chainId': 999 - Unsupported chain ID"
656
684
  *
657
685
  * throw createValidationFailedError('config', { invalid: true }, 'Missing required properties')
658
- * // Message: "Validation failed for 'config': [object Object] - Missing required properties"
686
+ * // Message: "Validation failed for 'config': {"invalid":true} - Missing required properties"
659
687
  * ```
660
688
  */ function createValidationFailedError(field, value, reason) {
661
689
  // Convert value to string for display, handling different types appropriately
@@ -663,7 +691,7 @@ class KitError extends Error {
663
691
  if (typeof value === 'string') {
664
692
  valueString = `'${value}'`;
665
693
  } else if (typeof value === 'object' && value !== null) {
666
- valueString = JSON.stringify(value);
694
+ valueString = describeObjectValue(value);
667
695
  } else {
668
696
  valueString = String(value);
669
697
  }
@@ -1184,6 +1212,8 @@ var SwapChain;
1184
1212
  SwapChain["HyperEVM"] = "HyperEVM";
1185
1213
  SwapChain["Monad"] = "Monad";
1186
1214
  SwapChain["Arc"] = "Arc";
1215
+ SwapChain["Cronos"] = "Cronos";
1216
+ SwapChain["Morph"] = "Morph";
1187
1217
  // Testnet chains with swap support
1188
1218
  SwapChain["Arc_Testnet"] = "Arc_Testnet";
1189
1219
  })(SwapChain || (SwapChain = {}));
@@ -1315,6 +1345,11 @@ var EarnChain;
1315
1345
  "Arc",
1316
1346
  "Arc_Testnet"
1317
1347
  ];
1348
+ var BorrowChain;
1349
+ (function(BorrowChain) {
1350
+ BorrowChain["Arc"] = "Arc";
1351
+ BorrowChain["Arc_Testnet"] = "Arc_Testnet";
1352
+ })(BorrowChain || (BorrowChain = {}));
1318
1353
 
1319
1354
  /**
1320
1355
  * Helper function to define a chain with proper TypeScript typing.
@@ -1657,6 +1692,29 @@ var EarnChain;
1657
1692
  * on EVM-compatible testnet chains. Use this address for testnet adapter
1658
1693
  * integrations (e.g., Arc Testnet).
1659
1694
  */ const ADAPTER_CONTRACT_EVM_TESTNET = '0xBBD70b01a1CAbc96d5b7b129Ae1AAabdf50dd40b';
1695
+ /**
1696
+ * The sender-preserving batching contract on Arc (`Multicall3From`).
1697
+ *
1698
+ * This predeploy batches calls like the ubiquitous Multicall3, but routes each
1699
+ * subcall through Arc's `CallFrom` precompile
1700
+ * (`0x1800000000000000000000000000000000000003`), which executes on behalf of
1701
+ * the transaction's original sender. Every target therefore sees the calling
1702
+ * EOA as `msg.sender`, which is what makes a plain, un-upgraded EOA capable of
1703
+ * an atomic batch on Arc.
1704
+ *
1705
+ * Deployed at the same address on Arc Testnet and Arc Mainnet.
1706
+ *
1707
+ * @see https://docs.arc.io/arc/concepts/batched-transactions
1708
+ */ const BATCHER_CONTRACT_ARC_TESTNET = '0x522fAf9A91c41c443c66765030741e4AaCe147D0';
1709
+ /**
1710
+ * The sender-preserving batching contract on Arc Mainnet (`Multicall3From`).
1711
+ *
1712
+ * See {@link BATCHER_CONTRACT_ARC_TESTNET} for how this contract works.
1713
+ * Requires Arc's Zero7 hardfork, which activates the `CallFrom` precompile
1714
+ * this contract depends on.
1715
+ *
1716
+ * @see https://docs.arc.io/arc/concepts/batched-transactions
1717
+ */ const BATCHER_CONTRACT_ARC_MAINNET = '0x522fAf9A91c41c443c66765030741e4AaCe147D0';
1660
1718
  /**
1661
1719
  * The GatewayWallet contract address for EVM mainnet networks.
1662
1720
  *
@@ -1796,7 +1854,10 @@ var EarnChain;
1796
1854
  },
1797
1855
  kitContracts: {
1798
1856
  bridge: BRIDGE_CONTRACT_EVM_MAINNET,
1799
- adapter: ADAPTER_CONTRACT_EVM_MAINNET
1857
+ adapter: ADAPTER_CONTRACT_EVM_MAINNET,
1858
+ // Arc is the only chain with a sender-preserving batcher, because it
1859
+ // takes a precompile rather than an ordinary contract to build one.
1860
+ senderPreservingBatcher: BATCHER_CONTRACT_ARC_MAINNET
1800
1861
  },
1801
1862
  gateway: {
1802
1863
  domain: 26,
@@ -1867,7 +1928,10 @@ var EarnChain;
1867
1928
  },
1868
1929
  kitContracts: {
1869
1930
  bridge: BRIDGE_CONTRACT_EVM_TESTNET,
1870
- adapter: ADAPTER_CONTRACT_EVM_TESTNET
1931
+ adapter: ADAPTER_CONTRACT_EVM_TESTNET,
1932
+ // Arc is the only chain with a sender-preserving batcher, because it
1933
+ // takes a precompile rather than an ordinary contract to build one.
1934
+ senderPreservingBatcher: BATCHER_CONTRACT_ARC_TESTNET
1871
1935
  },
1872
1936
  gateway: {
1873
1937
  domain: 26,
@@ -2482,7 +2546,8 @@ var EarnChain;
2482
2546
  }
2483
2547
  },
2484
2548
  kitContracts: {
2485
- bridge: BRIDGE_CONTRACT_EVM_MAINNET
2549
+ bridge: BRIDGE_CONTRACT_EVM_MAINNET,
2550
+ adapter: ADAPTER_CONTRACT_EVM_MAINNET
2486
2551
  }
2487
2552
  });
2488
2553
 
@@ -3351,7 +3416,8 @@ var EarnChain;
3351
3416
  }
3352
3417
  },
3353
3418
  kitContracts: {
3354
- bridge: BRIDGE_CONTRACT_EVM_MAINNET
3419
+ bridge: BRIDGE_CONTRACT_EVM_MAINNET,
3420
+ adapter: ADAPTER_CONTRACT_EVM_MAINNET
3355
3421
  }
3356
3422
  });
3357
3423
 
@@ -5285,7 +5351,8 @@ var EarnChain;
5285
5351
  cctpx: z.any().optional(),
5286
5352
  kitContracts: z.object({
5287
5353
  bridge: z.string().optional(),
5288
- adapter: z.string().optional()
5354
+ adapter: z.string().optional(),
5355
+ senderPreservingBatcher: z.string().optional()
5289
5356
  }).optional(),
5290
5357
  gateway: gatewayConfigSchema.optional()
5291
5358
  });
@@ -5396,8 +5463,8 @@ var EarnChain;
5396
5463
  * Zod schema for validating swap-specific chain identifiers.
5397
5464
  *
5398
5465
  * Validates chains based on:
5399
- * - CCTPv2 support (adapter contract deployed)
5400
- * - Mainnet only (no testnets)
5466
+ * - Membership in the SwapChain enum
5467
+ * - Mainnet or explicitly allowlisted testnet
5401
5468
  * - At least one supported token available
5402
5469
  *
5403
5470
  */ z.union([
@@ -5481,6 +5548,38 @@ var EarnChain;
5481
5548
  message: `"${chain.chain}" is not a supported earn chain. ` + `Supported chains: ${Object.values(EarnChain).join(', ')}`
5482
5549
  }))
5483
5550
  ]);
5551
+ /**
5552
+ * Zod schema for validating Borrow-specific chain identifiers.
5553
+ *
5554
+ * Validate that the provided chain is supported for Borrow Kit's loan
5555
+ * operations. Unlike {@link earnChainIdentifierSchema}, this includes Arc
5556
+ * mainnet as well as Arc Testnet.
5557
+ *
5558
+ * Accept a BorrowChain enum value, a matching string literal, or a
5559
+ * ChainDefinition for a supported chain.
5560
+ *
5561
+ * @example
5562
+ * ```typescript
5563
+ * import { borrowChainIdentifierSchema } from '@core/chains'
5564
+ * import { Arc, BorrowChain } from '@core/chains'
5565
+ *
5566
+ * // Valid
5567
+ * borrowChainIdentifierSchema.parse(BorrowChain.Arc)
5568
+ * borrowChainIdentifierSchema.parse('Arc')
5569
+ * borrowChainIdentifierSchema.parse(Arc)
5570
+ *
5571
+ * // Invalid (throws ZodError)
5572
+ * borrowChainIdentifierSchema.parse('Solana')
5573
+ * ```
5574
+ */ z.union([
5575
+ z.string().refine((val)=>val in BorrowChain, (val)=>({
5576
+ message: `"${val}" is not a supported borrow chain. ` + `Supported chains: ${Object.values(BorrowChain).join(', ')}`
5577
+ })),
5578
+ z.nativeEnum(BorrowChain),
5579
+ chainDefinitionSchema.refine((chain)=>chain.chain in BorrowChain, (chain)=>({
5580
+ message: `"${chain.chain}" is not a supported borrow chain. ` + `Supported chains: ${Object.values(BorrowChain).join(', ')}`
5581
+ }))
5582
+ ]);
5484
5583
  // Widened views so `.includes()` accepts arbitrary strings under strict TS.
5485
5584
  const EARN_BRIDGE_SOURCE_CHAIN_VALUES = EARN_BRIDGE_SOURCE_BLOCKCHAINS;
5486
5585
  const EARN_BRIDGE_DESTINATION_CHAIN_VALUES = EARN_BRIDGE_DESTINATION_BLOCKCHAINS;
@@ -6102,11 +6201,13 @@ const swapTokenEnumSchema = z.enum([
6102
6201
  [Blockchain.Arbitrum]: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',
6103
6202
  [Blockchain.Avalanche]: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
6104
6203
  [Blockchain.Celo]: '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e',
6204
+ [Blockchain.Cronos]: '0x66e428c3f67a68878562e79A0234c1F83c208770',
6105
6205
  [Blockchain.Ethereum]: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
6106
6206
  [Blockchain.HyperEVM]: '0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb',
6107
6207
  [Blockchain.Ink]: '0x0200C29006150606B650577BBE7B6248F58470c1',
6108
6208
  [Blockchain.Linea]: '0xA219439258ca9da29E9Cc4cE5596924745e12B93',
6109
6209
  [Blockchain.Monad]: '0xe7cd86e13AC4309349F30B3435a9d337750fC82D',
6210
+ [Blockchain.Morph]: '0xe7cd86e13AC4309349F30B3435a9d337750fC82D',
6110
6211
  [Blockchain.NEAR]: 'usdt.tether-token.near',
6111
6212
  [Blockchain.Optimism]: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58',
6112
6213
  [Blockchain.Polkadot_Asset_Hub]: '1984',
@@ -6165,6 +6266,7 @@ const swapTokenEnumSchema = z.enum([
6165
6266
  [Blockchain.Arbitrum]: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
6166
6267
  [Blockchain.Avalanche]: '0xd586E7F844cEa2F87f50152665BCbc2C279D8d70',
6167
6268
  [Blockchain.Base]: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb',
6269
+ [Blockchain.Cronos]: '0xF2001B145b43032AAF5Ee2884e456CCd805F677D',
6168
6270
  [Blockchain.Ethereum]: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
6169
6271
  [Blockchain.Linea]: '0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5',
6170
6272
  [Blockchain.Optimism]: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
@@ -6227,7 +6329,9 @@ const swapTokenEnumSchema = z.enum([
6227
6329
  [Blockchain.Arbitrum]: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
6228
6330
  [Blockchain.Avalanche]: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB',
6229
6331
  [Blockchain.Base]: '0x4200000000000000000000000000000000000006',
6332
+ [Blockchain.Cronos]: '0xe44Fd7fCb2b1581822D0c862B68222998a0c299a',
6230
6333
  [Blockchain.Ethereum]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
6334
+ [Blockchain.Morph]: '0x5300000000000000000000000000000000000011',
6231
6335
  [Blockchain.Optimism]: '0x4200000000000000000000000000000000000006',
6232
6336
  [Blockchain.Polygon]: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
6233
6337
  [Blockchain.Solana]: '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs'
@@ -6246,6 +6350,7 @@ const swapTokenEnumSchema = z.enum([
6246
6350
  locators: {
6247
6351
  [Blockchain.Ethereum]: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
6248
6352
  [Blockchain.Arbitrum]: '0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f',
6353
+ [Blockchain.Cronos]: '0x062E66477Faf219F25D27dCED647BF57C3107d52',
6249
6354
  [Blockchain.Avalanche]: '0x50b7545627a5162F82A992c33b87aDc75187B218'
6250
6355
  }
6251
6356
  };
@@ -8644,7 +8749,7 @@ const swapTokenEnumSchema = z.enum([
8644
8749
  return kit;
8645
8750
  }
8646
8751
 
8647
- var version = "1.0.2";
8752
+ var version = "1.0.4";
8648
8753
  var pkg = {
8649
8754
  version: version};
8650
8755
 
@@ -9280,7 +9385,7 @@ function isAbortLikeError(err) {
9280
9385
  currency: z.string().min(1).optional(),
9281
9386
  email: z.string().email().optional(),
9282
9387
  assets: onrampAssetSelectionSchema.optional(),
9283
- metadata: z.record(z.string(), z.unknown()).optional()
9388
+ metadata: z.record(z.string(), z.string()).optional()
9284
9389
  });
9285
9390
 
9286
9391
  /**
@@ -9442,7 +9547,7 @@ function isAbortLikeError(err) {
9442
9547
  const widgetUrl = mergeAssetParams(existingWidgetUrl, composedWidgetUrl, assetParams);
9443
9548
  const traceId = typeof session['traceId'] === 'string' ? session['traceId'] : ctx.invocation.traceId;
9444
9549
  // Outbound allow-list. We deliberately rebuild the result from the
9445
- // exact fields the client kit consumes rather than spreading
9550
+ // exact fields the host and client kit consume rather than spreading
9446
9551
  // `...session`. Inbound parsing stays schema-free for forward-compat
9447
9552
  // (an additive upstream field must never break minting), but the
9448
9553
  // server→browser hop is a trust boundary: any internal identifier,
@@ -9461,6 +9566,11 @@ function isAbortLikeError(err) {
9461
9566
  if (typeof session['expiresAt'] === 'string') {
9462
9567
  normalised['expiresAt'] = session['expiresAt'];
9463
9568
  }
9569
+ // From the response only. No fallback to `params.metadata`.
9570
+ const metadata = readMetadataEcho(session['metadata']);
9571
+ if (metadata !== undefined) {
9572
+ normalised['metadata'] = metadata;
9573
+ }
9464
9574
  if (widgetUrl === undefined) {
9465
9575
  // `widgetUrl` is required on `MintedOnrampSession` (guaranteed
9466
9576
  // present). If neither the API returned one nor a `sessionToken`
@@ -9497,6 +9607,17 @@ function isAbortLikeError(err) {
9497
9607
  }
9498
9608
  return url.toString();
9499
9609
  }
9610
+ /**
9611
+ * Copy a plain-object, string-valued `metadata` echo, or drop it whole.
9612
+ *
9613
+ * @internal
9614
+ */ function readMetadataEcho(value) {
9615
+ if (value === null || typeof value !== 'object' || Object.getPrototypeOf(value) !== Object.prototype) {
9616
+ return undefined;
9617
+ }
9618
+ const entries = Object.entries(value);
9619
+ return entries.every(([, entry])=>typeof entry === 'string') ? Object.fromEntries(entries) : undefined;
9620
+ }
9500
9621
  /**
9501
9622
  * Translate the SDK parameter shape into the wallets-api request body.
9502
9623
  *