@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/earn.d.ts CHANGED
@@ -551,8 +551,23 @@ interface CCTPXChainConfig {
551
551
  * const contractType: KitContractType = 'bridge' // Valid
552
552
  * const invalidType: KitContractType = 'invalid' // TypeScript error
553
553
  * ```
554
- */
555
- type KitContractType = 'bridge' | 'adapter';
554
+ *
555
+ * @remarks
556
+ * `'senderPreservingBatcher'` carries a stricter requirement than the others,
557
+ * because setting it wrong fails silently rather than loudly. It must name a
558
+ * batching contract that preserves the calling EOA as `msg.sender` in every
559
+ * subcall — on Arc, the `Multicall3From` predeploy, which achieves that
560
+ * through the `CallFrom` precompile. The name is deliberately more specific
561
+ * than "batcher": the ubiquitous Multicall3 at
562
+ * `0xcA11bde05977b3631167028862bE2a173976CA11` has the same ABI and the same
563
+ * selectors but does **not** qualify, since each subcall would arrive as the
564
+ * Multicall3 contract, so a batched `approve` would grant an allowance from
565
+ * the batcher's own balance rather than from the user's — a field named just
566
+ * `batcher` would make that misconfiguration look valid. Leave
567
+ * `senderPreservingBatcher` unset on any chain lacking one; an unset field
568
+ * simply means callers fall back to submitting calls one at a time.
569
+ */
570
+ type KitContractType = 'bridge' | 'adapter' | 'senderPreservingBatcher';
556
571
  /**
557
572
  * Configuration for Gateway v1 contracts.
558
573
  *
@@ -884,10 +899,10 @@ declare enum Blockchain {
884
899
  *
885
900
  * Unlike the full {@link Blockchain} enum, SwapChain includes mainnet
886
901
  * networks and explicitly whitelisted testnets (e.g., {@link Arc_Testnet})
887
- * where adapter contracts are deployed (CCTPv2 support).
902
+ * where Adapter contracts are deployed.
888
903
  *
889
904
  * Dynamic validation via {@link isSwapSupportedChain} ensures chains
890
- * automatically work when adapter contracts and supported tokens are deployed.
905
+ * automatically work when Adapter contracts and supported tokens are deployed.
891
906
  *
892
907
  * @example
893
908
  * ```typescript
@@ -927,20 +942,22 @@ declare enum SwapChain {
927
942
  HyperEVM = "HyperEVM",
928
943
  Monad = "Monad",
929
944
  Arc = "Arc",
945
+ Cronos = "Cronos",
946
+ Morph = "Morph",
930
947
  Arc_Testnet = "Arc_Testnet"
931
948
  }
932
949
  /**
933
950
  * Chain definition that supports swap operations.
934
951
  *
935
952
  * @remarks
936
- * Expanded from 4 to ~18 supported chains based on:
937
- * - CCTPv2 support (adapter contract deployed)
953
+ * Expanded from 4 to supported mainnets and whitelisted testnets based on:
954
+ * - A deployed Adapter contract, configured directly or through CCTP v2
938
955
  * - Mainnet chains plus whitelisted testnets (e.g., Arc Testnet)
939
956
  *
940
957
  * Use `isSwapSupportedChain()` for runtime validation.
941
958
  */
942
959
  type SwapChainDefinition = ChainDefinition & {
943
- chain: Blockchain.Ethereum | Blockchain.Base | Blockchain.Polygon | Blockchain.Solana | Blockchain.Arbitrum | Blockchain.Optimism | Blockchain.Avalanche | Blockchain.Linea | Blockchain.Ink | Blockchain.World_Chain | Blockchain.Unichain | Blockchain.Plume | Blockchain.Sei | Blockchain.Sonic | Blockchain.XDC | Blockchain.HyperEVM | Blockchain.Monad | Blockchain.Arc | Blockchain.Arc_Testnet;
960
+ chain: Blockchain.Ethereum | Blockchain.Base | Blockchain.Polygon | Blockchain.Solana | Blockchain.Arbitrum | Blockchain.Optimism | Blockchain.Avalanche | Blockchain.Linea | Blockchain.Ink | Blockchain.World_Chain | Blockchain.Unichain | Blockchain.Plume | Blockchain.Sei | Blockchain.Sonic | Blockchain.XDC | Blockchain.HyperEVM | Blockchain.Monad | Blockchain.Arc | Blockchain.Cronos | Blockchain.Morph | Blockchain.Arc_Testnet;
944
961
  };
945
962
  /**
946
963
  * Chain identifier accepted by swap operations.
@@ -1436,8 +1453,13 @@ type PreparedChainRequest = EvmPreparedChainRequest | SolanaPreparedChainRequest
1436
1453
  * Parameters for preparing an EVM contract execution.
1437
1454
  */
1438
1455
  type EvmPreparedChainRequestParams = {
1439
- /** The type of the prepared execution. */
1440
- type: 'evm';
1456
+ /**
1457
+ * The type of the prepared execution. Optional here because EVM is the
1458
+ * only chain type `Adapter.prepare()` implementations narrow their param
1459
+ * type to in practice — callers that only ever prepare EVM requests can
1460
+ * omit it rather than repeat a discriminator that never varies for them.
1461
+ */
1462
+ type?: 'evm';
1441
1463
  /** The ABI of the contract. */
1442
1464
  abi: Abi | string[];
1443
1465
  /** The address of the contract. */
@@ -2716,6 +2738,57 @@ interface EarnActionMap {
2716
2738
  readonly claimRewards: ExecuteEarnParams;
2717
2739
  }
2718
2740
 
2741
+ /** Permit standards accepted by Borrow Adapter executions. */
2742
+ declare enum BorrowPermitType {
2743
+ /** Tokens must be approved separately. */
2744
+ NONE = 0,
2745
+ /** EIP-2612 permit calldata accompanies the token input. */
2746
+ EIP2612 = 1
2747
+ }
2748
+ /** Token input forwarded by Borrow Kit to the Adapter Contract. */
2749
+ interface BorrowTokenInput {
2750
+ readonly permitType: BorrowPermitType;
2751
+ readonly token: `0x${string}`;
2752
+ readonly amount: bigint;
2753
+ readonly permitCalldata: `0x${string}`;
2754
+ }
2755
+ /** A single instruction in a Circle-signed Borrow execution. */
2756
+ interface BorrowInstruction {
2757
+ readonly target: `0x${string}`;
2758
+ readonly data: `0x${string}`;
2759
+ readonly value: string | bigint;
2760
+ readonly tokenIn: `0x${string}`;
2761
+ readonly amountToApprove: string | bigint;
2762
+ readonly tokenOut: `0x${string}`;
2763
+ readonly minTokenOut: string | bigint;
2764
+ }
2765
+ /** A token recipient in a Circle-signed Borrow execution. */
2766
+ interface BorrowTokenRecipient {
2767
+ readonly token: `0x${string}`;
2768
+ readonly beneficiary: `0x${string}`;
2769
+ }
2770
+ /** Circle-signed Borrow parameters forwarded to the Adapter Contract. */
2771
+ interface BorrowExecutionParams {
2772
+ readonly instructions: readonly BorrowInstruction[];
2773
+ readonly tokens: readonly BorrowTokenRecipient[];
2774
+ readonly execId: string | bigint;
2775
+ readonly deadline: string | bigint;
2776
+ readonly metadata: `0x${string}`;
2777
+ }
2778
+ /** Parameters for a service-signed Borrow Adapter execution. */
2779
+ interface ExecuteBorrowParams extends ActionParameters {
2780
+ readonly executeParams: BorrowExecutionParams;
2781
+ readonly tokenInputs: BorrowTokenInput[];
2782
+ readonly signature: `0x${string}`;
2783
+ }
2784
+ /** Borrow actions supported by EVM adapters. */
2785
+ interface BorrowActionMap {
2786
+ /** Execute a Circle-signed partial loan repayment. */
2787
+ readonly repay: ExecuteBorrowParams;
2788
+ /** Execute a Circle-signed borrow. */
2789
+ readonly execute: ExecuteBorrowParams;
2790
+ }
2791
+
2719
2792
  /**
2720
2793
  * Single instruction to execute within the Adapter Contract.
2721
2794
  *
@@ -3672,6 +3745,8 @@ interface NativeActionMap {
3672
3745
  * @see {@link ActionPayload} for extracting payload types
3673
3746
  */
3674
3747
  interface ActionMap {
3748
+ /** Borrow operations that execute service-signed payloads. */
3749
+ readonly borrow: BorrowActionMap;
3675
3750
  /** CCTP-specific operations with automatic address resolution. */
3676
3751
  readonly cctp: CCTPActionMap;
3677
3752
  /** CCTPx operations (CrossChainTokenService) for cross-chain transfers of registered tokens (Circle-issued or otherwise). */
@@ -3691,6 +3766,7 @@ interface ActionMap {
3691
3766
  /** Earn operations that execute service-signed payloads via the adapter contract. */
3692
3767
  readonly earn: EarnActionMap;
3693
3768
  }
3769
+
3694
3770
  /**
3695
3771
  * Determine if a type represents an action parameter object (leaf node).
3696
3772
  *
@@ -5578,1209 +5654,1274 @@ interface InvocationMeta {
5578
5654
  }
5579
5655
 
5580
5656
  /**
5581
- * Transfer speed options for cross-chain operations.
5657
+ * Type definitions for the Amount system.
5582
5658
  *
5583
- * Defines the available speed modes for CCTPv2 transfers, affecting
5584
- * both transfer time and potential fee implications.
5659
+ * @remarks
5660
+ * This module defines the core types for type-safe token amount handling.
5661
+ * Amounts are immutable value objects that carry the raw bigint value
5662
+ * and decimal precision. Token identity (symbol, address) is managed
5663
+ * separately by the token registry.
5664
+ *
5665
+ * @packageDocumentation
5585
5666
  */
5586
- declare enum TransferSpeed {
5587
- /** Fast burn mode - reduces transfer time but may have different fee implications */
5588
- FAST = "FAST",
5589
- /** Standard burn mode - normal transfer time with standard fees */
5590
- SLOW = "SLOW"
5591
- }
5592
5667
  /**
5593
- * Context object representing a wallet and signing authority on a specific blockchain network.
5594
- *
5595
- * Combines a wallet or contract address, the blockchain it resides on, and the adapter (signer)
5596
- * responsible for authorizing transactions. Used to specify the source or destination in cross-chain
5597
- * transfer operations.
5668
+ * An immutable token amount value.
5598
5669
  *
5599
5670
  * @remarks
5600
- * The `adapter` (signer) and `address` do not always have to belong to the same entity. For example,
5601
- * in minting or withdrawal scenarios, the signing adapter may authorize a transaction that credits
5602
- * funds to a different recipient address. This context is essential for cross-chain operations,
5603
- * ensuring that both the address and the associated adapter are correctly paired with the intended
5604
- * blockchain, but not necessarily with each other.
5671
+ * Amounts are pure numeric value objects containing the raw bigint value
5672
+ * (in smallest units) and decimal precision. They are immutable - all
5673
+ * math operations return new Amount instances.
5674
+ *
5675
+ * Token identity (symbol, contract address) is intentionally NOT included.
5676
+ * This separation ensures developers explicitly source token metadata from
5677
+ * the token registry, preventing incorrect symbol display.
5605
5678
  *
5606
5679
  * @example
5607
5680
  * ```typescript
5608
- * import type { WalletContext } from '@core/provider'
5609
- * import { adapter, blockchain } from './setup'
5610
- *
5611
- * const wallet: WalletContext = {
5612
- * adapter,
5613
- * address: '0x1234...abcd',
5614
- * chain: blockchain,
5681
+ * const amount: Amount = {
5682
+ * raw: 1_000_000n, // 1 token in smallest units (e.g., 1 USDC)
5683
+ * decimals: 6,
5615
5684
  * }
5616
5685
  * ```
5617
5686
  */
5618
- interface WalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
5619
- /**
5620
- * The chain definition type to use for the wallet context.
5621
- *
5622
- * @defaultValue ChainDefinition
5623
- */
5624
- TChainDefinition extends ChainDefinition = ChainDefinition> {
5625
- /**
5626
- * The adapter (signer) for the wallet on the specified chain.
5627
- *
5628
- * Responsible for authorizing transactions and signing messages on behalf of the wallet or
5629
- * for a different recipient, depending on the use case.
5630
- */
5631
- adapter: Adapter<TAdapterCapabilities>;
5687
+ interface Amount$1 {
5632
5688
  /**
5633
- * The wallet or contract address.
5634
- *
5635
- * Must be a valid address format for the specified blockchain. May differ from the adapter's
5636
- * own address in scenarios such as relayed transactions or third-party minting.
5689
+ * The raw value in smallest units (e.g., wei for ETH, micro-units for USDC).
5637
5690
  */
5638
- address: string;
5691
+ readonly raw: bigint;
5639
5692
  /**
5640
- * The blockchain network where the wallet or contract address resides.
5693
+ * Number of decimal places for this token.
5641
5694
  *
5642
- * Determines the context and format for the address and adapter.
5695
+ * @remarks
5696
+ * Common values:
5697
+ * - USDC/USDT: 6
5698
+ * - ETH/ERC-20: 18
5643
5699
  */
5644
- chain: TChainDefinition;
5700
+ readonly decimals: number;
5645
5701
  }
5646
5702
  /**
5647
- * Wallet context for bridge destinations with optional custom recipient.
5648
- *
5649
- * Extends WalletContext to support scenarios where the recipient address
5650
- * differs from the signer address (e.g., bridging to a third-party wallet).
5651
- * The signer address is used for transaction authorization, while the
5652
- * recipient address specifies where the minted funds should be sent.
5653
- *
5654
- * @typeParam TAdapterCapabilities - The adapter capabilities type to use for the wallet context.
5655
- * @typeParam TChainDefinition - The chain definition type to use for the wallet context.
5656
- *
5657
- * @example
5658
- * ```typescript
5659
- * import type { DestinationWalletContext } from '@core/provider'
5660
- * import { adapter, blockchain } from './setup'
5703
+ * Configuration for creating amounts.
5661
5704
  *
5662
- * // Bridge to a custom recipient address
5663
- * const destination: DestinationWalletContext = {
5664
- * adapter,
5665
- * address: '0x1234...abcd', // Signer address
5666
- * chain: blockchain,
5667
- * recipientAddress: '0x9876...fedc' // Custom recipient
5668
- * }
5669
- * ```
5705
+ * @remarks
5706
+ * Specifies the decimal precision for the amount. Typically obtained
5707
+ * from the token registry.
5670
5708
  */
5671
- interface DestinationWalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
5709
+ interface AmountConfig {
5710
+ /**
5711
+ * Number of decimal places.
5712
+ */
5713
+ decimals: number;
5714
+ }
5672
5715
  /**
5673
- * The chain definition type to use for the wallet context.
5674
- *
5675
- * @defaultValue ChainDefinition
5716
+ * Options for formatting amounts as human-readable strings.
5676
5717
  */
5677
- TChainDefinition extends ChainDefinition = ChainDefinition> extends WalletContext<TAdapterCapabilities, TChainDefinition> {
5718
+ interface FormatOptions {
5678
5719
  /**
5679
- * Optional custom recipient address for minted funds.
5680
- *
5681
- * When provided, minted tokens will be sent to this address instead of
5682
- * the address specified in the wallet context. The wallet context address
5683
- * is still used for transaction signing and authorization.
5720
+ * Locale for number formatting.
5684
5721
  *
5685
- * Must be a valid address format for the specified blockchain.
5722
+ * @defaultValue 'en-US'
5686
5723
  */
5687
- recipientAddress?: string;
5724
+ locale?: string;
5688
5725
  /**
5689
- * Whether Circle's relayer submits the destination transaction.
5726
+ * Minimum fraction digits to display.
5690
5727
  *
5691
- * How an omitted value resolves, and whether an explicit `false` is accepted,
5692
- * is provider-specific.
5728
+ * @defaultValue 0
5693
5729
  */
5694
- useForwarder?: boolean;
5730
+ minimumFractionDigits?: number;
5695
5731
  /**
5696
- * Optional destination dApp deposit action for a fast cross-chain transfer.
5732
+ * Maximum fraction digits to display.
5697
5733
  *
5698
- * When set, the burned USDC is minted to Circle's GenericExecutor on the
5699
- * destination chain, which calls the registered dApp (for example, a Gateway
5700
- * `depositFor`) in the same relayed flow. Consumed by the CCTP v2 provider's
5701
- * executor-deposit path; requires `useForwarder: true`.
5734
+ * @defaultValue decimals
5735
+ */
5736
+ maximumFractionDigits?: number;
5737
+ /**
5738
+ * Use grouping separators (e.g., 1,000,000).
5702
5739
  *
5703
- * @see {@link BridgeDepositAction}
5740
+ * @defaultValue true
5704
5741
  */
5705
- deposit?: BridgeDepositAction;
5742
+ useGrouping?: boolean;
5706
5743
  }
5707
5744
  /**
5708
- * Destination dApp deposit action for a fast cross-chain transfer.
5709
- *
5710
- * When present on a bridge destination, the CCTP v2 provider routes the
5711
- * transfer through Circle's GenericExecutor: the burned USDC is minted to the
5712
- * executor on the destination chain, which then calls the registered dApp (for
5713
- * example, a Gateway `depositFor`) in the same relayed flow. Encoded into
5714
- * executor hookData via `buildDepositForGenericExecutorPayload`.
5715
- *
5716
- * @example
5717
- * ```typescript
5718
- * import type { BridgeDepositAction } from '@core/provider'
5745
+ * Options for parsing human-readable strings to amounts.
5719
5746
  *
5720
- * const deposit: BridgeDepositAction = {
5721
- * dappId: 'gateway_deposit',
5722
- * params: ['0xTokenMessengerWithFees', '0xDepositAccount', 0n],
5723
- * }
5724
- * ```
5747
+ * @remarks
5748
+ * Currently only supports '.' as the decimal separator (en-US style).
5725
5749
  */
5726
- interface BridgeDepositAction {
5750
+ interface ParseOptions {
5727
5751
  /**
5728
- * Registered dApp identifier the GenericExecutor invokes on the destination
5729
- * chain (for example, `'gateway_deposit'`).
5752
+ * Number of decimal places.
5730
5753
  */
5731
- dappId: string;
5754
+ decimals: number;
5732
5755
  /**
5733
- * Positional arguments for the dApp function, in ABI order. Dynamic amount
5734
- * slots are filled in by the executor from the minted amount.
5756
+ * Whether to allow negative values.
5757
+ *
5758
+ * @defaultValue false
5735
5759
  */
5736
- params: readonly unknown[];
5760
+ allowNegative?: boolean;
5737
5761
  }
5738
5762
  /**
5739
- * Parameters for executing a cross-chain bridge operation.
5763
+ * Result of comparing two amounts.
5740
5764
  */
5741
- interface BridgeParams$1<TFromCapabilities extends AdapterCapabilities = AdapterCapabilities, TToCapabilities extends AdapterCapabilities = AdapterCapabilities,
5765
+ type ComparisonResult = -1 | 0 | 1;
5742
5766
  /**
5743
- * The chain definition type to use for the wallet context.
5767
+ * Types that can be converted to an Amount.
5744
5768
  *
5745
- * @defaultValue ChainDefinition
5769
+ * @remarks
5770
+ * - `bigint`: Raw value (requires config with decimals)
5771
+ * - `string`: Human-readable (e.g., "100.50")
5772
+ * - `number`: Human-readable (e.g., 100.5) - beware of precision!
5773
+ * - `Amount`: Existing amount or plain object with Amount shape
5746
5774
  */
5747
- TChainDefinition extends ChainDefinition = ChainDefinition,
5775
+ type AmountLike = bigint | string | number | Amount$1;
5748
5776
  /**
5749
- * The token type the provider accepts.
5750
- *
5751
- * @defaultValue 'USDC'
5777
+ * JSON representation of an Amount.
5752
5778
  *
5753
5779
  * @remarks
5754
- * The default preserves the original USDC-only contract for consumers that
5755
- * omit the token type. Providers that accept a different token type pass
5756
- * `TToken` explicitly.
5780
+ * Used for serialization. The `raw` value is stringified since JSON
5781
+ * does not support bigint natively.
5757
5782
  *
5758
5783
  * @example
5759
5784
  * ```typescript
5760
- * // Default — TToken resolves to 'USDC'
5761
- * type DefaultParams = BridgeParams // params.token is typed as 'USDC'
5762
- *
5763
- * // Provider that identifies tokens by a hex string template literal
5764
- * type HexTokenParams = BridgeParams<
5765
- * AdapterCapabilities,
5766
- * AdapterCapabilities,
5767
- * ChainDefinition,
5768
- * `0x${string}`
5769
- * > // params.token is typed as `0x${string}`
5785
+ * const json: AmountJSON = {
5786
+ * raw: "1500000",
5787
+ * decimals: 6,
5788
+ * formatted: "1.5"
5789
+ * }
5770
5790
  * ```
5771
5791
  */
5772
- TToken extends string = 'USDC'> {
5773
- /** The source adapter containing wallet and chain information */
5774
- source: WalletContext<TFromCapabilities, TChainDefinition>;
5775
- /** The destination adapter containing wallet and chain information */
5776
- destination: DestinationWalletContext<TToCapabilities, TChainDefinition>;
5777
- /** The amount to transfer (as a string to avoid precision issues) */
5778
- amount: string;
5779
- /** The token to transfer (provider-defined; defaults to `'USDC'`) */
5780
- token: TToken;
5781
- /** Bridge configuration (e.g., fast burn settings) */
5782
- config: BridgeConfig;
5783
- /**
5784
- * Optional server-signed quote to reuse, typically the
5785
- * {@link EstimateResult.quote} returned by an earlier `estimate` call.
5786
- *
5787
- * When present and still valid, a provider with a server-signed quote
5788
- * model may reuse it instead of fetching a fresh quote, so the fee the
5789
- * caller was quoted is the fee they pay. Providers decide when a reused
5790
- * quote is still valid (e.g. freshness, fee token, speed); an unusable or
5791
- * mismatched quote is ignored and a fresh one is fetched. Transfer
5792
- * parameters are validated by the provider's on-chain contract, so a quote
5793
- * reused for a different transfer is rejected there rather than silently.
5794
- * Providers without a quote model ignore this field entirely, and do so
5795
- * silently — nothing verifies that a quote reached the provider that issued
5796
- * it, because the route is matched to a provider only after these
5797
- * parameters are validated. A quote is meaningful only on the route that
5798
- * produced it.
5799
- *
5800
- * Typed `unknown`: a caller reaches `bridge` through a provider-agnostic
5801
- * surface, so this shared type names no provider's shape. It is public
5802
- * input in any case, and is validated before any field is read — by the
5803
- * provider that serves the route, or by the kit for routes it prices
5804
- * itself. Treat it as opaque and pass it back unmodified.
5805
- *
5806
- * This is a `bridge` input. A quote is an output of `estimate`, not an
5807
- * input to it — `estimate` always returns a freshly-priced quote, and a
5808
- * provider may reject a quote passed to `estimate` rather than ignore it.
5809
- */
5810
- quote?: unknown;
5811
- /**
5812
- * Optional invocation metadata for tracing and correlation.
5813
- *
5814
- * When provided, the `traceId` is used to correlate all events emitted during
5815
- * the bridge operation. If not provided, an OpenTelemetry-compatible traceId
5816
- * will be auto-generated.
5817
- */
5818
- invocationMeta?: InvocationMeta;
5792
+ interface AmountJSON {
5793
+ /** The raw value as a string (bigint serialized). */
5794
+ raw: string;
5795
+ /** Number of decimal places. */
5796
+ decimals: number;
5797
+ /** Human-readable formatted value. */
5798
+ formatted: string;
5819
5799
  }
5800
+
5820
5801
  /**
5821
- * Configuration options for customizing bridge behavior.
5802
+ * Minimal fields required for internal Amount operations.
5822
5803
  *
5823
5804
  * @remarks
5824
- * This interface is currently incomplete and will be expanded in future versions
5825
- * to include additional configuration options such as slippage tolerance,
5826
- * deadline settings, and other bridge parameters.
5805
+ * This internal type mirrors the public {@link Amount} interface shape but exists
5806
+ * separately to avoid circular dependencies. Internal modules (math, comparison,
5807
+ * formatting) import this lightweight type instead of the full Amount class.
5827
5808
  *
5809
+ * The Amount class implements this interface, so internal helpers can operate
5810
+ * on either Amount instances or plain objects with the same shape.
5811
+ *
5812
+ * @see {@link ../types.ts#Amount} for the public interface
5813
+ * @internal
5828
5814
  */
5829
- interface BridgeConfig {
5815
+ interface AmountFields {
5816
+ readonly raw: bigint;
5817
+ readonly decimals: number;
5818
+ }
5819
+
5820
+ /**
5821
+ * Fluent Amount class for type-safe token amount handling.
5822
+ *
5823
+ * @remarks
5824
+ * The `Amount` class provides an immutable, fluent API for working with token
5825
+ * amounts. It wraps a raw bigint value with decimal precision and provides
5826
+ * chainable methods for math, comparison, and formatting.
5827
+ *
5828
+ * Token identity (symbol, contract address) is intentionally NOT included.
5829
+ * This ensures developers explicitly source token metadata from the token
5830
+ * registry, preventing incorrect symbol display.
5831
+ *
5832
+ * @example
5833
+ * ```typescript
5834
+ * import { Amount } from '@core/amounts'
5835
+ *
5836
+ * // Create from raw value or parse from string
5837
+ * const a = Amount.of(1_000_000n, { decimals: 6 })
5838
+ * const b = Amount.parse('0.5', { decimals: 6 })
5839
+ *
5840
+ * // Fluent operations
5841
+ * const result = a.add(b).mul(2n).sub(Amount.parse('0.25', { decimals: 6 }))
5842
+ *
5843
+ * // Comparisons and formatting
5844
+ * a.gt(b) // true
5845
+ * a.toString() // "1"
5846
+ *
5847
+ * // For display with symbol, combine with token registry:
5848
+ * // `${amount.toString()} ${token.symbol}`
5849
+ * ```
5850
+ *
5851
+ * @packageDocumentation
5852
+ */
5853
+
5854
+ /**
5855
+ * An immutable token amount with fluent API methods.
5856
+ *
5857
+ * @remarks
5858
+ * The `Amount` class provides a type-safe, ergonomic way to work with token
5859
+ * amounts. It combines the raw bigint value with decimal precision and
5860
+ * provides chainable methods for:
5861
+ *
5862
+ * - **Math operations**: add, sub, mul, div, abs, neg
5863
+ * - **Comparisons**: eq, lt, lte, gt, gte, cmp, min, max
5864
+ * - **Predicates**: isZero, isPositive, isNegative
5865
+ * - **Formatting**: formatted, toString, toJSON
5866
+ * - **Conversion**: toDecimals
5867
+ *
5868
+ * All operations return new Amount instances - the class is immutable.
5869
+ *
5870
+ * Token identity (symbol) is intentionally excluded. Source token metadata
5871
+ * from the token registry for display purposes.
5872
+ */
5873
+ declare class Amount implements AmountFields {
5874
+ /** The raw value in smallest units (e.g., wei for ETH, micro-units for USDC). */
5875
+ readonly raw: bigint;
5876
+ /** Number of decimal places for this token. */
5877
+ readonly decimals: number;
5878
+ private constructor();
5830
5879
  /**
5831
- * The transfer speed mode for CCTPv2 transfers.
5880
+ * Create an Amount from a raw bigint value.
5832
5881
  *
5833
- * Controls whether to use fast burn mode (FAST) or standard mode (SLOW).
5834
- * Fast burn may reduce transfer time but could have different fee implications.
5882
+ * @param raw - The raw value in smallest units.
5883
+ * @param config - Configuration with decimals.
5884
+ * @returns A new immutable Amount instance.
5885
+ * @throws KitError If raw is not a bigint or decimals is invalid.
5835
5886
  *
5836
- * @defaultValue TransferSpeed.FAST
5887
+ * @example
5888
+ * ```typescript
5889
+ * // Get decimals from token registry
5890
+ * const amount = Amount.of(1_000_000n, { decimals: 6 })
5891
+ * ```
5837
5892
  */
5838
- transferSpeed?: TransferSpeed | `${TransferSpeed}` | undefined;
5893
+ static of(raw: bigint, config: AmountConfig): Amount;
5839
5894
  /**
5840
- * Enable or disable EIP-5792 batched transaction execution.
5841
- *
5842
- * When `true` (or `undefined` / omitted), the bridge will attempt to batch
5843
- * the approve and burn calls into a single `wallet_sendCalls` request if
5844
- * the connected wallet supports it. Set to `false` to explicitly opt out
5845
- * and always use the sequential approve -> burn flow.
5895
+ * Parse a human-readable string or number into an Amount.
5846
5896
  *
5847
- * @defaultValue `undefined` (batching attempted when the wallet supports it)
5897
+ * @param input - The input to parse (e.g., "100.50" or 100.5).
5898
+ * @param options - Parse options including decimals.
5899
+ * @returns A new immutable Amount instance.
5900
+ * @throws KitError If input is invalid or parsing fails.
5848
5901
  *
5849
5902
  * @example
5850
5903
  * ```typescript
5851
- * const config: BridgeConfig = {
5852
- * batchTransactions: false, // force sequential flow
5853
- * }
5904
+ * const amount = Amount.parse('100.50', { decimals: 6 })
5854
5905
  * ```
5855
5906
  */
5856
- batchTransactions?: boolean | undefined;
5907
+ static parse(input: string | number, options: ParseOptions): Amount;
5857
5908
  /**
5858
- * The maximum fee to pay for the burn operation.
5909
+ * Convert any AmountLike value to an Amount.
5859
5910
  *
5860
- * Provide the amount as a base-10 numeric string representing the
5861
- * token amount in human-readable format. For example: to set a maximum
5862
- * fee of 1 USDC, pass `"1"`. Decimal values are supported (e.g., `"0.5"`
5863
- * for half a USDC).
5911
+ * @param input - The input (bigint, string, number, or existing Amount).
5912
+ * @param config - Configuration (required for non-Amount inputs).
5913
+ * @returns A new immutable Amount instance.
5914
+ * @throws KitError If conversion fails or config is missing.
5864
5915
  *
5865
- * @defaultValue `"0"`
5916
+ * @remarks
5917
+ * When providing a `number` input, very large or small values may be
5918
+ * converted to exponential notation (e.g., `1e21`), which is not supported.
5919
+ * For such values, provide a `string` representation instead.
5866
5920
  *
5867
5921
  * @example
5868
5922
  * ```typescript
5869
- * import type { BridgeConfig, TransferSpeed } from '@core/provider'
5870
- *
5871
- * const config: BridgeConfig = {
5872
- * transferSpeed: TransferSpeed.FAST,
5873
- * maxFee: "1", // 1 USDC maximum fee
5874
- * customFee: {
5875
- * value: "0.5", // 0.5 USDC developer fee
5876
- * recipientAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0"
5877
- * }
5878
- * }
5923
+ * Amount.from(1_000_000n, { decimals: 6 }) // from bigint
5924
+ * Amount.from('1.00', { decimals: 6 }) // from string
5925
+ * Amount.from(existingAmount) // pass-through
5879
5926
  * ```
5880
5927
  */
5881
- maxFee?: string;
5928
+ static from(input: AmountLike, config?: AmountConfig): Amount;
5882
5929
  /**
5883
- * The custom fee to charge for the transfer.
5930
+ * Create a zero Amount with the given configuration.
5884
5931
  *
5885
- * Whatever value you provide here is **added on top of the transfer amount**. The user must have
5886
- * enough balance for `amount + customFee`, and the wallet signs for that total on the source
5887
- * chain. The custom fee is split automatically:
5932
+ * @param config - Configuration with decimals.
5933
+ * @returns A zero Amount instance.
5888
5934
  *
5889
- * - 10% routes to Circle.
5890
- * - 90% routes to your `recipientAddress`.
5935
+ * @example
5936
+ * ```typescript
5937
+ * const zero = Amount.zero({ decimals: 6 })
5938
+ * ```
5939
+ */
5940
+ static zero(config: AmountConfig): Amount;
5941
+ /**
5942
+ * Check if a value is an Amount-like object.
5891
5943
  *
5892
- * The original transfer amount proceeds through CCTPv2 unchanged, and the protocol fee (1–14 bps
5893
- * in FAST mode, 0% in STANDARD) is taken from that transfer amount.
5944
+ * @param value - The value to check.
5945
+ * @returns True if the value has Amount shape (raw: bigint, decimals: number).
5894
5946
  *
5895
5947
  * @example
5896
5948
  * ```typescript
5897
- * import type { BridgeConfig } from '@core/provider'
5949
+ * Amount.isAmount({ raw: 1000000n, decimals: 6 }) // true
5950
+ * Amount.isAmount({ value: 100 }) // false
5951
+ * ```
5952
+ */
5953
+ static isAmount(value: unknown): value is {
5954
+ raw: bigint;
5955
+ decimals: number;
5956
+ };
5957
+ /**
5958
+ * Sum an array of Amounts.
5898
5959
  *
5899
- * const config: BridgeConfig = {
5900
- * customFee: {
5901
- * value: '5', // 5 USDC developer fee
5902
- * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
5903
- * },
5904
- * }
5960
+ * @param amounts - The amounts to sum (must have same decimals).
5961
+ * @returns A new Amount with the total sum.
5962
+ * @throws KitError If amounts array is empty or decimals don't match.
5905
5963
  *
5906
- * // Fee flow for a 100 USDC transfer with 5 USDC custom fee:
5907
- * // Source chain (Ethereum):
5908
- * // - Wallet debits: 105 USDC total (100 transfer + 5 custom fee)
5909
- * // - Custom fee split: 0.5 USDC (10%) → Circle, 4.5 USDC (90%) → your recipientAddress
5910
- * // - Amount sent to CCTPv2: 100 USDC (unchanged)
5911
- * //
5912
- * // Destination chain (Base):
5913
- * // - CCTPv2 FAST fee (example: 1 bps): ~0.01 USDC deducted
5914
- * // - User receives: ~99.99 USDC
5915
- * //
5916
- * // Note: Actual CCTP fees vary by route (1-14 bps for FAST, 0 bps for STANDARD)
5964
+ * @example
5965
+ * ```typescript
5966
+ * const fee1 = Amount.parse('0.10', { decimals: 6 })
5967
+ * const fee2 = Amount.parse('0.25', { decimals: 6 })
5968
+ * const fee3 = Amount.parse('0.15', { decimals: 6 })
5969
+ *
5970
+ * const total = Amount.sum([fee1, fee2, fee3])
5971
+ * total.toString() // "0.5"
5917
5972
  * ```
5918
5973
  */
5919
- customFee?: CustomFee | undefined;
5974
+ static sum(amounts: readonly Amount[]): Amount;
5920
5975
  /**
5921
- * Which leg pays the protocol fee.
5976
+ * Deserialize an Amount from a JSON object.
5922
5977
  *
5923
- * `'source'` leaves the delivered amount unreduced; `'destination'` takes the
5924
- * fee from it. Omit it to let the routed provider decide — a provider rejects
5925
- * a value it cannot honour.
5978
+ * @param json - The JSON object (e.g., from `JSON.parse()`).
5979
+ * @returns A new Amount instance.
5980
+ * @throws KitError If the JSON structure is invalid.
5981
+ *
5982
+ * @example
5983
+ * ```typescript
5984
+ * const json = JSON.parse('{"raw":"1500000","decimals":6}')
5985
+ * const amount = Amount.fromJSON(json)
5986
+ * ```
5926
5987
  */
5927
- feePayment?: 'source' | 'destination' | undefined;
5928
- }
5929
- /**
5930
- * Custom fee configuration charged by the integrator.
5931
- *
5932
- * Use to charge an absolute fee on the source chain in human-readable
5933
- * token amounts.
5934
- *
5935
- * @remarks
5936
- * This is an absolute amount, not a percentage. The `recipientAddress` must be
5937
- * a valid address for the source chain of the transfer.
5938
- *
5939
- * @example
5940
- * ```typescript
5941
- * import type { CustomFee } from '@core/provider'
5942
- *
5943
- * const config: CustomFee = {
5944
- * value: '1', // 1 USDC
5945
- * recipientAddress: '0x1234567890123456789012345678901234567890',
5946
- * }
5947
- * ```
5948
- */
5949
- interface CustomFee {
5950
- /**
5951
- * The absolute fee to charge for the transfer.
5952
- *
5953
- * Provide the amount as a base-10 numeric string representing the token
5954
- * amount in human-readable format. For example: to charge 1 USDC, pass
5955
- * `"1"`. Decimal values are supported (e.g., `"0.5"` for half a USDC).
5956
- * This is not a percentage.
5957
- *
5958
- * Note: passing `"0"` results in no fee being charged.
5959
- */
5960
- value?: string | undefined;
5961
- /**
5962
- * The fee recipient for the bridge transfer.
5963
- *
5964
- * This is the address that will receive the fee on the source chain of the
5965
- * bridge transfer. The fee recipient address **must be a valid address for
5966
- * the source chain** of the bridge transfer.
5967
- *
5968
- * @remarks
5969
- * Circle automatically receives 10% of every custom fee; the remaining 90% is
5970
- * sent to this `recipientAddress`.
5971
- *
5972
- * For example: if bridging from Ethereum to Solana, pass an EVM address like
5973
- * `"0x1234567890123456789012345678901234567890"` because the source chain
5974
- * is Ethereum.
5975
- */
5976
- recipientAddress?: string | undefined;
5977
- }
5978
- /**
5979
- * Represents the context of an adapter used for cross-chain operations.
5980
- *
5981
- * An AdapterContext must always specify both the adapter and the chain explicitly.
5982
- * The address field behavior is determined by the adapter's address control model:
5983
- *
5984
- * - **Developer-controlled adapters**: The `address` field is required because
5985
- * each operation must explicitly specify which address to use.
5986
- * - **User-controlled adapters**: The `address` field is forbidden because
5987
- * the address is automatically resolved from the connected wallet or signer.
5988
- * - **Legacy adapters**: The `address` field remains optional for backward compatibility.
5989
- *
5990
- * This ensures clear, debuggable code where the intended chain is always visible at the call site,
5991
- * and address requirements are enforced at compile time based on adapter capabilities.
5992
- *
5993
- * @typeParam TAdapterCapabilities - The adapter capabilities type to derive address requirements from
5994
- * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
5995
- *
5996
- * @example
5997
- * ```typescript
5998
- * // Developer-controlled adapter (address required)
5999
- * const devContext: AdapterContext<{ addressContext: 'developer-controlled', supportedChains: [] }> = {
6000
- * adapter: myDevAdapter,
6001
- * chain: 'Ethereum',
6002
- * address: '0x123...' // Required
6003
- * }
6004
- *
6005
- * // User-controlled adapter (address forbidden)
6006
- * const userContext: AdapterContext<{ addressContext: 'user-controlled', supportedChains: [] }> = {
6007
- * adapter: myUserAdapter,
6008
- * chain: 'Ethereum'
6009
- * // address: '0x123...' // TypeScript error: not allowed
6010
- * }
6011
- * ```
6012
- */
6013
- type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = {
6014
- /** The adapter instance for blockchain operations */
6015
- adapter: Adapter<TAdapterCapabilities>;
6016
- /** The chain reference, which can be a ChainDefinition, Blockchain enum, or string literal */
6017
- chain: TChainIdentifier;
6018
- } & AddressField<ExtractAddressContext<TAdapterCapabilities>>;
6019
- /**
6020
- * Represents a bridge destination with an explicit custom recipient address.
6021
- *
6022
- * Extends {@link AdapterContext} with an additional `recipientAddress` field to specify
6023
- * a custom recipient that differs from the adapter's address. Use this when bridging to
6024
- * third-party wallets or smart contracts rather than the default address associated with
6025
- * the destination adapter.
6026
- *
6027
- * @typeParam TCapabilities - The adapter capabilities type for the destination adapter
6028
- * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6029
- *
6030
- * @remarks
6031
- * The `recipientAddress` must be a valid address format for the destination chain
6032
- * specified in the adapter context. The bridge provider validates address compatibility
6033
- * during the transfer preparation phase and will throw an error if the address format
6034
- * is invalid for the target chain.
6035
- *
6036
- * @example
6037
- * ```typescript
6038
- * import { BridgeDestinationWithAddress } from '@core/provider'
6039
- * import { ethereumAdapter } from './adapters'
6040
- *
6041
- * // Bridge to a custom recipient address on Ethereum
6042
- * const destination: BridgeDestinationWithAddress = {
6043
- * adapter: ethereumAdapter,
6044
- * chain: 'Ethereum',
6045
- * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0'
6046
- * }
6047
- * ```
6048
- */
6049
- type BridgeDestinationWithAddress<TCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = AdapterContext<TCapabilities, TChainIdentifier> & {
6050
- /**
6051
- * The custom recipient address on the destination chain.
6052
- *
6053
- * Must be a valid address format for the chain specified in this adapter context.
6054
- * This address will receive the bridged funds instead of the adapter's default address.
6055
- */
6056
- recipientAddress: string;
6057
- };
6058
- /**
6059
- * Forwarder-only destination without an adapter.
6060
- *
6061
- * Used when Circle's Forwarder handles the mint transaction and no destination
6062
- * adapter is available. Requires both `useForwarder: true` and a `recipientAddress`.
6063
- *
6064
- * When using this destination type:
6065
- * - The mint step completes when the IRIS API confirms `forwardState === 'CONFIRMED'`
6066
- * - No on-chain transaction confirmation is performed (no adapter available)
6067
- * - The mint step's `data` field will be undefined (no transaction receipt)
6068
- *
6069
- * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6070
- *
6071
- * @example
6072
- * ```typescript
6073
- * // Forwarder-only destination (no adapter needed)
6074
- * const dest: ForwarderDestination = {
6075
- * chain: 'Base',
6076
- * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
6077
- * useForwarder: true
6078
- * }
6079
- * ```
6080
- */
6081
- interface ForwarderDestination<TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> {
6082
- /** The destination chain where USDC will be minted */
6083
- chain: TChainIdentifier;
6084
- /** The recipient address that will receive the minted USDC */
6085
- recipientAddress: string;
6086
- /** Must be true for forwarder-only destinations */
6087
- useForwarder: true;
6088
- }
6089
- /**
6090
- * Union type representing a bridge destination.
6091
- *
6092
- * Supports multiple destination configurations:
6093
- * - {@link AdapterContext}: Standard destination with adapter (for default recipient)
6094
- * - {@link BridgeDestinationWithAddress}: Destination with adapter and custom recipient
6095
- * - {@link ForwarderDestination}: Forwarder-only destination without adapter (requires recipientAddress)
6096
- *
6097
- * When `useForwarder` is enabled with an adapter, Circle's Orbit relayer handles the mint
6098
- * transaction and the adapter is used to wait for transaction confirmation.
6099
- *
6100
- * When `useForwarder` is enabled without an adapter (ForwarderDestination), the mint step
6101
- * completes when the IRIS API confirms `forwardState === 'CONFIRMED'` without on-chain
6102
- * confirmation.
6103
- *
6104
- * @typeParam TAdapterCapabilities - The adapter capabilities type for the destination adapter
6105
- * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6106
- *
6107
- * @example
6108
- * ```typescript
6109
- * // Standard destination with adapter
6110
- * const dest1: BridgeDestination = { adapter, chain: 'Base' }
6111
- *
6112
- * // Destination with adapter and custom recipient
6113
- * const dest2: BridgeDestination = { adapter, chain: 'Base', recipientAddress: '0x...' }
6114
- *
6115
- * // Destination with forwarder enabled (adapter for tx confirmation)
6116
- * const dest3: BridgeDestination = { adapter, chain: 'Base', useForwarder: true }
6117
- *
6118
- * // Forwarder-only destination (no adapter, requires recipientAddress)
6119
- * const dest4: BridgeDestination = { chain: 'Base', useForwarder: true, recipientAddress: '0x...' }
6120
- * ```
6121
- */
6122
- type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = ((AdapterContext<TAdapterCapabilities, TChainIdentifier> | BridgeDestinationWithAddress<TAdapterCapabilities, TChainIdentifier>) & {
6123
- /**
6124
- * Enable Circle's relayer to submit the destination transaction.
6125
- *
6126
- * Where the relay fee is charged depends on the route and on
6127
- * {@link BridgeConfig.feePayment}: it may be taken from the amount that
6128
- * arrives, or priced into a quote the source transaction pays.
6129
- *
6130
- * Whether the option is required, optional, or refused depends on the
6131
- * routed provider and the rest of the config.
6132
- */
6133
- useForwarder?: boolean;
6134
- }) | ForwarderDestination<TChainIdentifier>;
6135
-
6136
- /**
6137
- * Type definitions for the Amount system.
6138
- *
6139
- * @remarks
6140
- * This module defines the core types for type-safe token amount handling.
6141
- * Amounts are immutable value objects that carry the raw bigint value
6142
- * and decimal precision. Token identity (symbol, address) is managed
6143
- * separately by the token registry.
6144
- *
6145
- * @packageDocumentation
6146
- */
6147
- /**
6148
- * An immutable token amount value.
6149
- *
6150
- * @remarks
6151
- * Amounts are pure numeric value objects containing the raw bigint value
6152
- * (in smallest units) and decimal precision. They are immutable - all
6153
- * math operations return new Amount instances.
6154
- *
6155
- * Token identity (symbol, contract address) is intentionally NOT included.
6156
- * This separation ensures developers explicitly source token metadata from
6157
- * the token registry, preventing incorrect symbol display.
6158
- *
6159
- * @example
6160
- * ```typescript
6161
- * const amount: Amount = {
6162
- * raw: 1_000_000n, // 1 token in smallest units (e.g., 1 USDC)
6163
- * decimals: 6,
6164
- * }
6165
- * ```
6166
- */
6167
- interface Amount$1 {
6168
- /**
6169
- * The raw value in smallest units (e.g., wei for ETH, micro-units for USDC).
6170
- */
6171
- readonly raw: bigint;
5988
+ static fromJSON(json: unknown): Amount;
6172
5989
  /**
6173
- * Number of decimal places for this token.
5990
+ * Compare this Amount with another.
6174
5991
  *
6175
- * @remarks
6176
- * Common values:
6177
- * - USDC/USDT: 6
6178
- * - ETH/ERC-20: 18
6179
- */
6180
- readonly decimals: number;
6181
- }
6182
- /**
6183
- * Configuration for creating amounts.
6184
- *
6185
- * @remarks
6186
- * Specifies the decimal precision for the amount. Typically obtained
6187
- * from the token registry.
6188
- */
6189
- interface AmountConfig {
6190
- /**
6191
- * Number of decimal places.
6192
- */
6193
- decimals: number;
6194
- }
6195
- /**
6196
- * Options for formatting amounts as human-readable strings.
6197
- */
6198
- interface FormatOptions {
6199
- /**
6200
- * Locale for number formatting.
5992
+ * @param other - The Amount to compare with.
5993
+ * @returns -1 if this is less than other, 0 if equal, 1 if this is greater.
5994
+ * @throws KitError If amounts have different decimals.
6201
5995
  *
6202
- * @defaultValue 'en-US'
5996
+ * @example
5997
+ * ```typescript
5998
+ * const a = Amount.parse('1.5', { decimals: 6 })
5999
+ * const b = Amount.parse('2.0', { decimals: 6 })
6000
+ * a.compare(b) // -1
6001
+ * ```
6203
6002
  */
6204
- locale?: string;
6003
+ compare(other: Amount): ComparisonResult;
6205
6004
  /**
6206
- * Minimum fraction digits to display.
6005
+ * Check if this Amount equals another.
6207
6006
  *
6208
- * @defaultValue 0
6209
- */
6210
- minimumFractionDigits?: number;
6211
- /**
6212
- * Maximum fraction digits to display.
6007
+ * @param other - The Amount to compare with.
6008
+ * @returns True if the raw values are equal.
6009
+ * @throws KitError If amounts have different decimals.
6213
6010
  *
6214
- * @defaultValue decimals
6011
+ * @example
6012
+ * ```typescript
6013
+ * const a = Amount.parse('1.5', { decimals: 6 })
6014
+ * const b = Amount.parse('1.5', { decimals: 6 })
6015
+ * a.eq(b) // true
6016
+ * ```
6215
6017
  */
6216
- maximumFractionDigits?: number;
6018
+ eq(other: Amount): boolean;
6217
6019
  /**
6218
- * Use grouping separators (e.g., 1,000,000).
6020
+ * Check if this Amount is less than another.
6219
6021
  *
6220
- * @defaultValue true
6221
- */
6222
- useGrouping?: boolean;
6223
- }
6224
- /**
6225
- * Options for parsing human-readable strings to amounts.
6226
- *
6227
- * @remarks
6228
- * Currently only supports '.' as the decimal separator (en-US style).
6229
- */
6230
- interface ParseOptions {
6231
- /**
6232
- * Number of decimal places.
6233
- */
6234
- decimals: number;
6235
- /**
6236
- * Whether to allow negative values.
6022
+ * @param other - The Amount to compare with.
6023
+ * @returns True if this.raw is less than other.raw.
6024
+ * @throws KitError If amounts have different decimals.
6237
6025
  *
6238
- * @defaultValue false
6239
- */
6240
- allowNegative?: boolean;
6241
- }
6242
- /**
6243
- * Result of comparing two amounts.
6244
- */
6245
- type ComparisonResult = -1 | 0 | 1;
6246
- /**
6247
- * Types that can be converted to an Amount.
6248
- *
6249
- * @remarks
6250
- * - `bigint`: Raw value (requires config with decimals)
6251
- * - `string`: Human-readable (e.g., "100.50")
6252
- * - `number`: Human-readable (e.g., 100.5) - beware of precision!
6253
- * - `Amount`: Existing amount or plain object with Amount shape
6254
- */
6255
- type AmountLike = bigint | string | number | Amount$1;
6256
- /**
6257
- * JSON representation of an Amount.
6258
- *
6259
- * @remarks
6260
- * Used for serialization. The `raw` value is stringified since JSON
6261
- * does not support bigint natively.
6262
- *
6263
- * @example
6264
- * ```typescript
6265
- * const json: AmountJSON = {
6266
- * raw: "1500000",
6267
- * decimals: 6,
6268
- * formatted: "1.5"
6269
- * }
6270
- * ```
6271
- */
6272
- interface AmountJSON {
6273
- /** The raw value as a string (bigint serialized). */
6274
- raw: string;
6275
- /** Number of decimal places. */
6276
- decimals: number;
6277
- /** Human-readable formatted value. */
6278
- formatted: string;
6279
- }
6280
-
6281
- /**
6282
- * Minimal fields required for internal Amount operations.
6283
- *
6284
- * @remarks
6285
- * This internal type mirrors the public {@link Amount} interface shape but exists
6286
- * separately to avoid circular dependencies. Internal modules (math, comparison,
6287
- * formatting) import this lightweight type instead of the full Amount class.
6288
- *
6289
- * The Amount class implements this interface, so internal helpers can operate
6290
- * on either Amount instances or plain objects with the same shape.
6291
- *
6292
- * @see {@link ../types.ts#Amount} for the public interface
6293
- * @internal
6294
- */
6295
- interface AmountFields {
6296
- readonly raw: bigint;
6297
- readonly decimals: number;
6298
- }
6299
-
6300
- /**
6301
- * Fluent Amount class for type-safe token amount handling.
6302
- *
6303
- * @remarks
6304
- * The `Amount` class provides an immutable, fluent API for working with token
6305
- * amounts. It wraps a raw bigint value with decimal precision and provides
6306
- * chainable methods for math, comparison, and formatting.
6307
- *
6308
- * Token identity (symbol, contract address) is intentionally NOT included.
6309
- * This ensures developers explicitly source token metadata from the token
6310
- * registry, preventing incorrect symbol display.
6311
- *
6312
- * @example
6313
- * ```typescript
6314
- * import { Amount } from '@core/amounts'
6315
- *
6316
- * // Create from raw value or parse from string
6317
- * const a = Amount.of(1_000_000n, { decimals: 6 })
6318
- * const b = Amount.parse('0.5', { decimals: 6 })
6319
- *
6320
- * // Fluent operations
6321
- * const result = a.add(b).mul(2n).sub(Amount.parse('0.25', { decimals: 6 }))
6322
- *
6323
- * // Comparisons and formatting
6324
- * a.gt(b) // true
6325
- * a.toString() // "1"
6326
- *
6327
- * // For display with symbol, combine with token registry:
6328
- * // `${amount.toString()} ${token.symbol}`
6329
- * ```
6330
- *
6331
- * @packageDocumentation
6332
- */
6333
-
6334
- /**
6335
- * An immutable token amount with fluent API methods.
6336
- *
6337
- * @remarks
6338
- * The `Amount` class provides a type-safe, ergonomic way to work with token
6339
- * amounts. It combines the raw bigint value with decimal precision and
6340
- * provides chainable methods for:
6341
- *
6342
- * - **Math operations**: add, sub, mul, div, abs, neg
6343
- * - **Comparisons**: eq, lt, lte, gt, gte, cmp, min, max
6344
- * - **Predicates**: isZero, isPositive, isNegative
6345
- * - **Formatting**: formatted, toString, toJSON
6346
- * - **Conversion**: toDecimals
6347
- *
6348
- * All operations return new Amount instances - the class is immutable.
6349
- *
6350
- * Token identity (symbol) is intentionally excluded. Source token metadata
6351
- * from the token registry for display purposes.
6352
- */
6353
- declare class Amount implements AmountFields {
6354
- /** The raw value in smallest units (e.g., wei for ETH, micro-units for USDC). */
6355
- readonly raw: bigint;
6356
- /** Number of decimal places for this token. */
6357
- readonly decimals: number;
6358
- private constructor();
6026
+ * @example
6027
+ * ```typescript
6028
+ * const a = Amount.parse('1.0', { decimals: 6 })
6029
+ * const b = Amount.parse('2.0', { decimals: 6 })
6030
+ * a.lt(b) // true
6031
+ * ```
6032
+ */
6033
+ lt(other: Amount): boolean;
6359
6034
  /**
6360
- * Create an Amount from a raw bigint value.
6035
+ * Check if this Amount is less than or equal to another.
6361
6036
  *
6362
- * @param raw - The raw value in smallest units.
6363
- * @param config - Configuration with decimals.
6364
- * @returns A new immutable Amount instance.
6365
- * @throws KitError If raw is not a bigint or decimals is invalid.
6037
+ * @param other - The Amount to compare with.
6038
+ * @returns True if this.raw is less than or equal to other.raw.
6039
+ * @throws KitError If amounts have different decimals.
6366
6040
  *
6367
6041
  * @example
6368
6042
  * ```typescript
6369
- * // Get decimals from token registry
6370
- * const amount = Amount.of(1_000_000n, { decimals: 6 })
6043
+ * const a = Amount.parse('1.5', { decimals: 6 })
6044
+ * const b = Amount.parse('1.5', { decimals: 6 })
6045
+ * a.lte(b) // true
6371
6046
  * ```
6372
6047
  */
6373
- static of(raw: bigint, config: AmountConfig): Amount;
6048
+ lte(other: Amount): boolean;
6374
6049
  /**
6375
- * Parse a human-readable string or number into an Amount.
6050
+ * Check if this Amount is greater than another.
6376
6051
  *
6377
- * @param input - The input to parse (e.g., "100.50" or 100.5).
6378
- * @param options - Parse options including decimals.
6379
- * @returns A new immutable Amount instance.
6380
- * @throws KitError If input is invalid or parsing fails.
6052
+ * @param other - The Amount to compare with.
6053
+ * @returns True if this.raw is greater than other.raw.
6054
+ * @throws KitError If amounts have different decimals.
6381
6055
  *
6382
6056
  * @example
6383
6057
  * ```typescript
6384
- * const amount = Amount.parse('100.50', { decimals: 6 })
6058
+ * const a = Amount.parse('2.0', { decimals: 6 })
6059
+ * const b = Amount.parse('1.0', { decimals: 6 })
6060
+ * a.gt(b) // true
6385
6061
  * ```
6386
6062
  */
6387
- static parse(input: string | number, options: ParseOptions): Amount;
6063
+ gt(other: Amount): boolean;
6388
6064
  /**
6389
- * Convert any AmountLike value to an Amount.
6065
+ * Check if this Amount is greater than or equal to another.
6390
6066
  *
6391
- * @param input - The input (bigint, string, number, or existing Amount).
6392
- * @param config - Configuration (required for non-Amount inputs).
6393
- * @returns A new immutable Amount instance.
6394
- * @throws KitError If conversion fails or config is missing.
6067
+ * @param other - The Amount to compare with.
6068
+ * @returns True if this.raw is greater than or equal to other.raw.
6069
+ * @throws KitError If amounts have different decimals.
6395
6070
  *
6396
- * @remarks
6397
- * When providing a `number` input, very large or small values may be
6398
- * converted to exponential notation (e.g., `1e21`), which is not supported.
6399
- * For such values, provide a `string` representation instead.
6071
+ * @example
6072
+ * ```typescript
6073
+ * const a = Amount.parse('2.0', { decimals: 6 })
6074
+ * const b = Amount.parse('2.0', { decimals: 6 })
6075
+ * a.gte(b) // true
6076
+ * ```
6077
+ */
6078
+ gte(other: Amount): boolean;
6079
+ /**
6080
+ * Return the minimum of this Amount and another.
6081
+ *
6082
+ * @param other - The Amount to compare with.
6083
+ * @returns The smaller of the two amounts.
6084
+ * @throws KitError If amounts have different decimals.
6400
6085
  *
6401
6086
  * @example
6402
6087
  * ```typescript
6403
- * Amount.from(1_000_000n, { decimals: 6 }) // from bigint
6404
- * Amount.from('1.00', { decimals: 6 }) // from string
6405
- * Amount.from(existingAmount) // pass-through
6088
+ * const a = Amount.parse('1.0', { decimals: 6 })
6089
+ * const b = Amount.parse('2.0', { decimals: 6 })
6090
+ * a.min(b).toString() // "1"
6406
6091
  * ```
6407
6092
  */
6408
- static from(input: AmountLike, config?: AmountConfig): Amount;
6093
+ min(other: Amount): Amount;
6409
6094
  /**
6410
- * Create a zero Amount with the given configuration.
6095
+ * Return the maximum of this Amount and another.
6411
6096
  *
6412
- * @param config - Configuration with decimals.
6413
- * @returns A zero Amount instance.
6097
+ * @param other - The Amount to compare with.
6098
+ * @returns The larger of the two amounts.
6099
+ * @throws KitError If amounts have different decimals.
6414
6100
  *
6415
6101
  * @example
6416
6102
  * ```typescript
6417
- * const zero = Amount.zero({ decimals: 6 })
6103
+ * const a = Amount.parse('1.0', { decimals: 6 })
6104
+ * const b = Amount.parse('2.0', { decimals: 6 })
6105
+ * a.max(b).toString() // "2"
6418
6106
  * ```
6419
6107
  */
6420
- static zero(config: AmountConfig): Amount;
6108
+ max(other: Amount): Amount;
6421
6109
  /**
6422
- * Check if a value is an Amount-like object.
6110
+ * Add another Amount to this one.
6423
6111
  *
6424
- * @param value - The value to check.
6425
- * @returns True if the value has Amount shape (raw: bigint, decimals: number).
6112
+ * @param other - The Amount to add.
6113
+ * @returns A new Amount with the sum.
6114
+ * @throws KitError If amounts have different decimals.
6426
6115
  *
6427
6116
  * @example
6428
6117
  * ```typescript
6429
- * Amount.isAmount({ raw: 1000000n, decimals: 6 }) // true
6430
- * Amount.isAmount({ value: 100 }) // false
6118
+ * const a = Amount.parse('1.5', { decimals: 6 })
6119
+ * const b = Amount.parse('0.5', { decimals: 6 })
6120
+ * a.add(b).toString() // "2"
6431
6121
  * ```
6432
6122
  */
6433
- static isAmount(value: unknown): value is {
6434
- raw: bigint;
6435
- decimals: number;
6436
- };
6123
+ add(other: Amount): Amount;
6437
6124
  /**
6438
- * Sum an array of Amounts.
6125
+ * Subtract another Amount from this one.
6439
6126
  *
6440
- * @param amounts - The amounts to sum (must have same decimals).
6441
- * @returns A new Amount with the total sum.
6442
- * @throws KitError If amounts array is empty or decimals don't match.
6127
+ * @param other - The Amount to subtract.
6128
+ * @returns A new Amount with the difference.
6129
+ * @throws KitError If amounts have different decimals.
6443
6130
  *
6444
6131
  * @example
6445
6132
  * ```typescript
6446
- * const fee1 = Amount.parse('0.10', { decimals: 6 })
6447
- * const fee2 = Amount.parse('0.25', { decimals: 6 })
6448
- * const fee3 = Amount.parse('0.15', { decimals: 6 })
6133
+ * const a = Amount.parse('2.0', { decimals: 6 })
6134
+ * const b = Amount.parse('0.5', { decimals: 6 })
6135
+ * a.sub(b).toString() // "1.5"
6136
+ * ```
6137
+ */
6138
+ sub(other: Amount): Amount;
6139
+ /**
6140
+ * Multiply this Amount by a scalar.
6449
6141
  *
6450
- * const total = Amount.sum([fee1, fee2, fee3])
6451
- * total.toString() // "0.5"
6142
+ * @param multiplier - The scalar to multiply by (bigint or integer number).
6143
+ * @returns A new Amount with the product.
6144
+ *
6145
+ * @remarks
6146
+ * When using a `number` as a multiplier, precision is limited by standard
6147
+ * JavaScript floating-point capabilities (~15-17 significant digits). For
6148
+ * high-precision calculations, provide the multiplier as a `bigint`.
6149
+ *
6150
+ * @example
6151
+ * ```typescript
6152
+ * const a = Amount.parse('1.5', { decimals: 6 })
6153
+ * a.mul(2n).toString() // "3"
6154
+ * a.mul(3).toString() // "4.5"
6452
6155
  * ```
6453
6156
  */
6454
- static sum(amounts: readonly Amount[]): Amount;
6157
+ mul(multiplier: bigint | number): Amount;
6455
6158
  /**
6456
- * Deserialize an Amount from a JSON object.
6159
+ * Divide this Amount by a scalar.
6457
6160
  *
6458
- * @param json - The JSON object (e.g., from `JSON.parse()`).
6459
- * @returns A new Amount instance.
6460
- * @throws KitError If the JSON structure is invalid.
6161
+ * @param divisor - The scalar to divide by (bigint or integer number).
6162
+ * @returns A new Amount with the quotient (integer division).
6163
+ * @throws KitError If divisor is zero.
6164
+ *
6165
+ * @remarks
6166
+ * When using a `number` as a divisor, precision is limited by standard
6167
+ * JavaScript floating-point capabilities (~15-17 significant digits). For
6168
+ * high-precision calculations, provide the divisor as a `bigint`.
6461
6169
  *
6462
6170
  * @example
6463
6171
  * ```typescript
6464
- * const json = JSON.parse('{"raw":"1500000","decimals":6}')
6465
- * const amount = Amount.fromJSON(json)
6172
+ * const a = Amount.parse('6.0', { decimals: 6 })
6173
+ * a.div(2n).toString() // "3"
6174
+ * a.div(4).toString() // "1.5"
6466
6175
  * ```
6467
6176
  */
6468
- static fromJSON(json: unknown): Amount;
6177
+ div(divisor: bigint | number): Amount;
6469
6178
  /**
6470
- * Compare this Amount with another.
6179
+ * Get the absolute value of this Amount.
6471
6180
  *
6472
- * @param other - The Amount to compare with.
6473
- * @returns -1 if this is less than other, 0 if equal, 1 if this is greater.
6474
- * @throws KitError If amounts have different decimals.
6181
+ * @returns A new Amount with the absolute value.
6182
+ *
6183
+ * @example
6184
+ * ```typescript
6185
+ * const a = Amount.of(-1_500_000n, { decimals: 6 })
6186
+ * a.abs().toString() // "1.5"
6187
+ * ```
6188
+ */
6189
+ abs(): Amount;
6190
+ /**
6191
+ * Negate this Amount.
6192
+ *
6193
+ * @returns A new Amount with the negated value.
6475
6194
  *
6476
6195
  * @example
6477
6196
  * ```typescript
6478
6197
  * const a = Amount.parse('1.5', { decimals: 6 })
6479
- * const b = Amount.parse('2.0', { decimals: 6 })
6480
- * a.compare(b) // -1
6198
+ * a.neg().raw // -1_500_000n
6481
6199
  * ```
6482
6200
  */
6483
- compare(other: Amount): ComparisonResult;
6201
+ neg(): Amount;
6484
6202
  /**
6485
- * Check if this Amount equals another.
6203
+ * Check if this Amount is zero.
6486
6204
  *
6487
- * @param other - The Amount to compare with.
6488
- * @returns True if the raw values are equal.
6489
- * @throws KitError If amounts have different decimals.
6205
+ * @returns True if the raw value is 0n.
6206
+ *
6207
+ * @example
6208
+ * ```typescript
6209
+ * Amount.zero({ decimals: 6 }).isZero() // true
6210
+ * Amount.parse('0.001', { decimals: 6 }).isZero() // false
6211
+ * ```
6212
+ */
6213
+ isZero(): boolean;
6214
+ /**
6215
+ * Check if this Amount is positive.
6216
+ *
6217
+ * @returns True if the raw value is greater than 0n.
6218
+ *
6219
+ * @example
6220
+ * ```typescript
6221
+ * Amount.parse('1.0', { decimals: 6 }).isPositive() // true
6222
+ * Amount.zero({ decimals: 6 }).isPositive() // false
6223
+ * ```
6224
+ */
6225
+ isPositive(): boolean;
6226
+ /**
6227
+ * Check if this Amount is negative.
6228
+ *
6229
+ * @returns True if the raw value is less than 0n.
6230
+ *
6231
+ * @example
6232
+ * ```typescript
6233
+ * Amount.of(-1_000_000n, { decimals: 6 }).isNegative() // true
6234
+ * Amount.parse('1.0', { decimals: 6 }).isNegative() // false
6235
+ * ```
6236
+ */
6237
+ isNegative(): boolean;
6238
+ /**
6239
+ * Convert this Amount to a different decimal precision.
6240
+ *
6241
+ * @param newDecimals - The target number of decimal places.
6242
+ * @returns A new Amount with adjusted precision (or this if same precision).
6243
+ * @throws KitError If newDecimals is invalid.
6244
+ *
6245
+ * @example
6246
+ * ```typescript
6247
+ * // Scale up: 6 decimals → 18 decimals
6248
+ * const usdc = Amount.parse('1.5', { decimals: 6 })
6249
+ * const scaled = usdc.toDecimals(18)
6250
+ * scaled.raw // 1_500_000_000_000_000_000n
6251
+ *
6252
+ * // Scale down: 18 decimals → 6 decimals (truncates)
6253
+ * const eth = Amount.of(1_500_000_000_000_000_000n, { decimals: 18 })
6254
+ * eth.toDecimals(6).raw // 1_500_000n
6255
+ * ```
6256
+ */
6257
+ toDecimals(newDecimals: number): Amount;
6258
+ /**
6259
+ * Format this Amount as a human-readable string.
6260
+ *
6261
+ * @param options - Formatting options (locale, fraction digits, grouping).
6262
+ * @returns A formatted string (e.g., "1,000.50").
6263
+ *
6264
+ * @example
6265
+ * ```typescript
6266
+ * const a = Amount.parse('1000.5', { decimals: 6 })
6267
+ * a.formatted() // "1,000.5"
6268
+ * a.formatted({ minimumFractionDigits: 2 }) // "1,000.50"
6269
+ * a.formatted({ useGrouping: false }) // "1000.5"
6270
+ * ```
6271
+ */
6272
+ formatted(options?: FormatOptions): string;
6273
+ /**
6274
+ * Convert to a human-readable string.
6275
+ *
6276
+ * @returns A formatted string like "1.5".
6277
+ *
6278
+ * @remarks
6279
+ * For display with a token symbol, combine with the token registry:
6280
+ * ```typescript
6281
+ * `${amount.toString()} ${token.symbol}`
6282
+ * ```
6490
6283
  *
6491
6284
  * @example
6492
6285
  * ```typescript
6493
6286
  * const a = Amount.parse('1.5', { decimals: 6 })
6494
- * const b = Amount.parse('1.5', { decimals: 6 })
6495
- * a.eq(b) // true
6287
+ * a.toString() // "1.5"
6496
6288
  * ```
6497
6289
  */
6498
- eq(other: Amount): boolean;
6290
+ toString(): string;
6499
6291
  /**
6500
- * Check if this Amount is less than another.
6292
+ * Convert to a JSON-serializable object.
6501
6293
  *
6502
- * @param other - The Amount to compare with.
6503
- * @returns True if this.raw is less than other.raw.
6504
- * @throws KitError If amounts have different decimals.
6294
+ * @returns An object with raw (as string), decimals, and formatted value.
6505
6295
  *
6506
6296
  * @example
6507
6297
  * ```typescript
6508
- * const a = Amount.parse('1.0', { decimals: 6 })
6509
- * const b = Amount.parse('2.0', { decimals: 6 })
6510
- * a.lt(b) // true
6298
+ * const a = Amount.parse('1.5', { decimals: 6 })
6299
+ * a.toJSON()
6300
+ * // { raw: "1500000", decimals: 6, formatted: "1.5" }
6511
6301
  * ```
6512
6302
  */
6513
- lt(other: Amount): boolean;
6303
+ toJSON(): AmountJSON;
6304
+ }
6305
+
6306
+ /**
6307
+ * Transfer speed options for cross-chain operations.
6308
+ *
6309
+ * Defines the available speed modes for CCTPv2 transfers, affecting
6310
+ * both transfer time and potential fee implications.
6311
+ */
6312
+ declare enum TransferSpeed {
6313
+ /** Fast burn mode - reduces transfer time but may have different fee implications */
6314
+ FAST = "FAST",
6315
+ /** Standard burn mode - normal transfer time with standard fees */
6316
+ SLOW = "SLOW"
6317
+ }
6318
+ /**
6319
+ * Context object representing a wallet and signing authority on a specific blockchain network.
6320
+ *
6321
+ * Combines a wallet or contract address, the blockchain it resides on, and the adapter (signer)
6322
+ * responsible for authorizing transactions. Used to specify the source or destination in cross-chain
6323
+ * transfer operations.
6324
+ *
6325
+ * @remarks
6326
+ * The `adapter` (signer) and `address` do not always have to belong to the same entity. For example,
6327
+ * in minting or withdrawal scenarios, the signing adapter may authorize a transaction that credits
6328
+ * funds to a different recipient address. This context is essential for cross-chain operations,
6329
+ * ensuring that both the address and the associated adapter are correctly paired with the intended
6330
+ * blockchain, but not necessarily with each other.
6331
+ *
6332
+ * @example
6333
+ * ```typescript
6334
+ * import type { WalletContext } from '@core/provider'
6335
+ * import { adapter, blockchain } from './setup'
6336
+ *
6337
+ * const wallet: WalletContext = {
6338
+ * adapter,
6339
+ * address: '0x1234...abcd',
6340
+ * chain: blockchain,
6341
+ * }
6342
+ * ```
6343
+ */
6344
+ interface WalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
6345
+ /**
6346
+ * The chain definition type to use for the wallet context.
6347
+ *
6348
+ * @defaultValue ChainDefinition
6349
+ */
6350
+ TChainDefinition extends ChainDefinition = ChainDefinition> {
6514
6351
  /**
6515
- * Check if this Amount is less than or equal to another.
6516
- *
6517
- * @param other - The Amount to compare with.
6518
- * @returns True if this.raw is less than or equal to other.raw.
6519
- * @throws KitError If amounts have different decimals.
6352
+ * The adapter (signer) for the wallet on the specified chain.
6520
6353
  *
6521
- * @example
6522
- * ```typescript
6523
- * const a = Amount.parse('1.5', { decimals: 6 })
6524
- * const b = Amount.parse('1.5', { decimals: 6 })
6525
- * a.lte(b) // true
6526
- * ```
6354
+ * Responsible for authorizing transactions and signing messages on behalf of the wallet or
6355
+ * for a different recipient, depending on the use case.
6527
6356
  */
6528
- lte(other: Amount): boolean;
6357
+ adapter: Adapter<TAdapterCapabilities>;
6529
6358
  /**
6530
- * Check if this Amount is greater than another.
6359
+ * The wallet or contract address.
6531
6360
  *
6532
- * @param other - The Amount to compare with.
6533
- * @returns True if this.raw is greater than other.raw.
6534
- * @throws KitError If amounts have different decimals.
6361
+ * Must be a valid address format for the specified blockchain. May differ from the adapter's
6362
+ * own address in scenarios such as relayed transactions or third-party minting.
6363
+ */
6364
+ address: string;
6365
+ /**
6366
+ * The blockchain network where the wallet or contract address resides.
6535
6367
  *
6536
- * @example
6537
- * ```typescript
6538
- * const a = Amount.parse('2.0', { decimals: 6 })
6539
- * const b = Amount.parse('1.0', { decimals: 6 })
6540
- * a.gt(b) // true
6541
- * ```
6368
+ * Determines the context and format for the address and adapter.
6542
6369
  */
6543
- gt(other: Amount): boolean;
6370
+ chain: TChainDefinition;
6371
+ }
6372
+ /**
6373
+ * Wallet context for bridge destinations with optional custom recipient.
6374
+ *
6375
+ * Extends WalletContext to support scenarios where the recipient address
6376
+ * differs from the signer address (e.g., bridging to a third-party wallet).
6377
+ * The signer address is used for transaction authorization, while the
6378
+ * recipient address specifies where the minted funds should be sent.
6379
+ *
6380
+ * @typeParam TAdapterCapabilities - The adapter capabilities type to use for the wallet context.
6381
+ * @typeParam TChainDefinition - The chain definition type to use for the wallet context.
6382
+ *
6383
+ * @example
6384
+ * ```typescript
6385
+ * import type { DestinationWalletContext } from '@core/provider'
6386
+ * import { adapter, blockchain } from './setup'
6387
+ *
6388
+ * // Bridge to a custom recipient address
6389
+ * const destination: DestinationWalletContext = {
6390
+ * adapter,
6391
+ * address: '0x1234...abcd', // Signer address
6392
+ * chain: blockchain,
6393
+ * recipientAddress: '0x9876...fedc' // Custom recipient
6394
+ * }
6395
+ * ```
6396
+ */
6397
+ interface DestinationWalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
6398
+ /**
6399
+ * The chain definition type to use for the wallet context.
6400
+ *
6401
+ * @defaultValue ChainDefinition
6402
+ */
6403
+ TChainDefinition extends ChainDefinition = ChainDefinition> extends WalletContext<TAdapterCapabilities, TChainDefinition> {
6544
6404
  /**
6545
- * Check if this Amount is greater than or equal to another.
6405
+ * Optional custom recipient address for minted funds.
6546
6406
  *
6547
- * @param other - The Amount to compare with.
6548
- * @returns True if this.raw is greater than or equal to other.raw.
6549
- * @throws KitError If amounts have different decimals.
6407
+ * When provided, minted tokens will be sent to this address instead of
6408
+ * the address specified in the wallet context. The wallet context address
6409
+ * is still used for transaction signing and authorization.
6550
6410
  *
6551
- * @example
6552
- * ```typescript
6553
- * const a = Amount.parse('2.0', { decimals: 6 })
6554
- * const b = Amount.parse('2.0', { decimals: 6 })
6555
- * a.gte(b) // true
6556
- * ```
6411
+ * Must be a valid address format for the specified blockchain.
6557
6412
  */
6558
- gte(other: Amount): boolean;
6413
+ recipientAddress?: string;
6559
6414
  /**
6560
- * Return the minimum of this Amount and another.
6415
+ * Whether Circle's relayer submits the destination transaction.
6561
6416
  *
6562
- * @param other - The Amount to compare with.
6563
- * @returns The smaller of the two amounts.
6564
- * @throws KitError If amounts have different decimals.
6417
+ * How an omitted value resolves, and whether an explicit `false` is accepted,
6418
+ * is provider-specific.
6419
+ */
6420
+ useForwarder?: boolean;
6421
+ /**
6422
+ * Optional destination dApp deposit action for a fast cross-chain transfer.
6565
6423
  *
6566
- * @example
6567
- * ```typescript
6568
- * const a = Amount.parse('1.0', { decimals: 6 })
6569
- * const b = Amount.parse('2.0', { decimals: 6 })
6570
- * a.min(b).toString() // "1"
6571
- * ```
6424
+ * When set, the burned USDC is minted to Circle's GenericExecutor on the
6425
+ * destination chain, which calls the registered dApp (for example, a Gateway
6426
+ * `depositFor`) in the same relayed flow. Consumed by the CCTP v2 provider's
6427
+ * executor-deposit path; requires `useForwarder: true`.
6428
+ *
6429
+ * @see {@link BridgeDepositAction}
6572
6430
  */
6573
- min(other: Amount): Amount;
6431
+ deposit?: BridgeDepositAction;
6432
+ }
6433
+ /**
6434
+ * Destination dApp deposit action for a fast cross-chain transfer.
6435
+ *
6436
+ * When present on a bridge destination, the CCTP v2 provider routes the
6437
+ * transfer through Circle's GenericExecutor: the burned USDC is minted to the
6438
+ * executor on the destination chain, which then calls the registered dApp (for
6439
+ * example, a Gateway `depositFor`) in the same relayed flow. Encoded into
6440
+ * executor hookData via `buildDepositForGenericExecutorPayload`.
6441
+ *
6442
+ * @example
6443
+ * ```typescript
6444
+ * import type { BridgeDepositAction } from '@core/provider'
6445
+ *
6446
+ * const deposit: BridgeDepositAction = {
6447
+ * dappId: 'gateway_deposit',
6448
+ * params: ['0xTokenMessengerWithFees', '0xDepositAccount', 0n],
6449
+ * }
6450
+ * ```
6451
+ */
6452
+ interface BridgeDepositAction {
6453
+ /**
6454
+ * Registered dApp identifier the GenericExecutor invokes on the destination
6455
+ * chain (for example, `'gateway_deposit'`).
6456
+ */
6457
+ dappId: string;
6458
+ /**
6459
+ * Positional arguments for the dApp function, in ABI order. Dynamic amount
6460
+ * slots are filled in by the executor from the minted amount.
6461
+ */
6462
+ params: readonly unknown[];
6463
+ }
6464
+ /**
6465
+ * Parameters for executing a cross-chain bridge operation.
6466
+ */
6467
+ interface BridgeParams$1<TFromCapabilities extends AdapterCapabilities = AdapterCapabilities, TToCapabilities extends AdapterCapabilities = AdapterCapabilities,
6468
+ /**
6469
+ * The chain definition type to use for the wallet context.
6470
+ *
6471
+ * @defaultValue ChainDefinition
6472
+ */
6473
+ TChainDefinition extends ChainDefinition = ChainDefinition,
6474
+ /**
6475
+ * The token type the provider accepts.
6476
+ *
6477
+ * @defaultValue 'USDC'
6478
+ *
6479
+ * @remarks
6480
+ * The default preserves the original USDC-only contract for consumers that
6481
+ * omit the token type. Providers that accept a different token type pass
6482
+ * `TToken` explicitly.
6483
+ *
6484
+ * @example
6485
+ * ```typescript
6486
+ * // Default — TToken resolves to 'USDC'
6487
+ * type DefaultParams = BridgeParams // params.token is typed as 'USDC'
6488
+ *
6489
+ * // Provider that identifies tokens by a hex string template literal
6490
+ * type HexTokenParams = BridgeParams<
6491
+ * AdapterCapabilities,
6492
+ * AdapterCapabilities,
6493
+ * ChainDefinition,
6494
+ * `0x${string}`
6495
+ * > // params.token is typed as `0x${string}`
6496
+ * ```
6497
+ */
6498
+ TToken extends string = 'USDC'> {
6499
+ /** The source adapter containing wallet and chain information */
6500
+ source: WalletContext<TFromCapabilities, TChainDefinition>;
6501
+ /** The destination adapter containing wallet and chain information */
6502
+ destination: DestinationWalletContext<TToCapabilities, TChainDefinition>;
6503
+ /** The amount to transfer (as a string to avoid precision issues) */
6504
+ amount: string;
6505
+ /** The token to transfer (provider-defined; defaults to `'USDC'`) */
6506
+ token: TToken;
6507
+ /** Bridge configuration (e.g., fast burn settings) */
6508
+ config: BridgeConfig;
6574
6509
  /**
6575
- * Return the maximum of this Amount and another.
6576
- *
6577
- * @param other - The Amount to compare with.
6578
- * @returns The larger of the two amounts.
6579
- * @throws KitError If amounts have different decimals.
6510
+ * Optional server-signed quote to reuse, typically the
6511
+ * {@link EstimateResult.quote} returned by an earlier `estimate` call.
6580
6512
  *
6581
- * @example
6582
- * ```typescript
6583
- * const a = Amount.parse('1.0', { decimals: 6 })
6584
- * const b = Amount.parse('2.0', { decimals: 6 })
6585
- * a.max(b).toString() // "2"
6586
- * ```
6587
- */
6588
- max(other: Amount): Amount;
6589
- /**
6590
- * Add another Amount to this one.
6513
+ * When present and still valid, a provider with a server-signed quote
6514
+ * model may reuse it instead of fetching a fresh quote, so the fee the
6515
+ * caller was quoted is the fee they pay. Providers decide when a reused
6516
+ * quote is still valid (e.g. freshness, fee token, speed); an unusable or
6517
+ * mismatched quote is ignored and a fresh one is fetched. Transfer
6518
+ * parameters are validated by the provider's on-chain contract, so a quote
6519
+ * reused for a different transfer is rejected there rather than silently.
6520
+ * Providers without a quote model ignore this field entirely, and do so
6521
+ * silently — nothing verifies that a quote reached the provider that issued
6522
+ * it, because the route is matched to a provider only after these
6523
+ * parameters are validated. A quote is meaningful only on the route that
6524
+ * produced it.
6591
6525
  *
6592
- * @param other - The Amount to add.
6593
- * @returns A new Amount with the sum.
6594
- * @throws KitError If amounts have different decimals.
6526
+ * Typed `unknown`: a caller reaches `bridge` through a provider-agnostic
6527
+ * surface, so this shared type names no provider's shape. It is public
6528
+ * input in any case, and is validated before any field is read — by the
6529
+ * provider that serves the route, or by the kit for routes it prices
6530
+ * itself. Treat it as opaque and pass it back unmodified.
6595
6531
  *
6596
- * @example
6597
- * ```typescript
6598
- * const a = Amount.parse('1.5', { decimals: 6 })
6599
- * const b = Amount.parse('0.5', { decimals: 6 })
6600
- * a.add(b).toString() // "2"
6601
- * ```
6532
+ * This is a `bridge` input. A quote is an output of `estimate`, not an
6533
+ * input to it — `estimate` always returns a freshly-priced quote, and a
6534
+ * provider may reject a quote passed to `estimate` rather than ignore it.
6602
6535
  */
6603
- add(other: Amount): Amount;
6536
+ quote?: unknown;
6604
6537
  /**
6605
- * Subtract another Amount from this one.
6606
- *
6607
- * @param other - The Amount to subtract.
6608
- * @returns A new Amount with the difference.
6609
- * @throws KitError If amounts have different decimals.
6538
+ * Optional invocation metadata for tracing and correlation.
6610
6539
  *
6611
- * @example
6612
- * ```typescript
6613
- * const a = Amount.parse('2.0', { decimals: 6 })
6614
- * const b = Amount.parse('0.5', { decimals: 6 })
6615
- * a.sub(b).toString() // "1.5"
6616
- * ```
6540
+ * When provided, the `traceId` is used to correlate all events emitted during
6541
+ * the bridge operation. If not provided, an OpenTelemetry-compatible traceId
6542
+ * will be auto-generated.
6617
6543
  */
6618
- sub(other: Amount): Amount;
6544
+ invocationMeta?: InvocationMeta;
6545
+ }
6546
+ /**
6547
+ * Configuration options for customizing bridge behavior.
6548
+ *
6549
+ * @remarks
6550
+ * This interface is currently incomplete and will be expanded in future versions
6551
+ * to include additional configuration options such as slippage tolerance,
6552
+ * deadline settings, and other bridge parameters.
6553
+ *
6554
+ */
6555
+ interface BridgeConfig {
6619
6556
  /**
6620
- * Multiply this Amount by a scalar.
6621
- *
6622
- * @param multiplier - The scalar to multiply by (bigint or integer number).
6623
- * @returns A new Amount with the product.
6557
+ * The transfer speed mode for CCTPv2 transfers.
6624
6558
  *
6625
- * @remarks
6626
- * When using a `number` as a multiplier, precision is limited by standard
6627
- * JavaScript floating-point capabilities (~15-17 significant digits). For
6628
- * high-precision calculations, provide the multiplier as a `bigint`.
6559
+ * Controls whether to use fast burn mode (FAST) or standard mode (SLOW).
6560
+ * Fast burn may reduce transfer time but could have different fee implications.
6629
6561
  *
6630
- * @example
6631
- * ```typescript
6632
- * const a = Amount.parse('1.5', { decimals: 6 })
6633
- * a.mul(2n).toString() // "3"
6634
- * a.mul(3).toString() // "4.5"
6635
- * ```
6562
+ * @defaultValue TransferSpeed.FAST
6636
6563
  */
6637
- mul(multiplier: bigint | number): Amount;
6564
+ transferSpeed?: TransferSpeed | `${TransferSpeed}` | undefined;
6638
6565
  /**
6639
- * Divide this Amount by a scalar.
6566
+ * Enable or disable EIP-5792 batched transaction execution.
6640
6567
  *
6641
- * @param divisor - The scalar to divide by (bigint or integer number).
6642
- * @returns A new Amount with the quotient (integer division).
6643
- * @throws KitError If divisor is zero.
6568
+ * When `true` (or `undefined` / omitted), the bridge will attempt to batch
6569
+ * the approve and burn calls into a single `wallet_sendCalls` request if
6570
+ * the connected wallet supports it. Set to `false` to explicitly opt out
6571
+ * and always use the sequential approve -> burn flow.
6644
6572
  *
6645
- * @remarks
6646
- * When using a `number` as a divisor, precision is limited by standard
6647
- * JavaScript floating-point capabilities (~15-17 significant digits). For
6648
- * high-precision calculations, provide the divisor as a `bigint`.
6573
+ * @defaultValue `undefined` (batching attempted when the wallet supports it)
6649
6574
  *
6650
6575
  * @example
6651
6576
  * ```typescript
6652
- * const a = Amount.parse('6.0', { decimals: 6 })
6653
- * a.div(2n).toString() // "3"
6654
- * a.div(4).toString() // "1.5"
6577
+ * const config: BridgeConfig = {
6578
+ * batchTransactions: false, // force sequential flow
6579
+ * }
6655
6580
  * ```
6656
6581
  */
6657
- div(divisor: bigint | number): Amount;
6582
+ batchTransactions?: boolean | undefined;
6658
6583
  /**
6659
- * Get the absolute value of this Amount.
6660
- *
6661
- * @returns A new Amount with the absolute value.
6584
+ * The maximum fee to pay for the burn operation.
6662
6585
  *
6663
- * @example
6664
- * ```typescript
6665
- * const a = Amount.of(-1_500_000n, { decimals: 6 })
6666
- * a.abs().toString() // "1.5"
6667
- * ```
6668
- */
6669
- abs(): Amount;
6670
- /**
6671
- * Negate this Amount.
6586
+ * Provide the amount as a base-10 numeric string representing the
6587
+ * token amount in human-readable format. For example: to set a maximum
6588
+ * fee of 1 USDC, pass `"1"`. Decimal values are supported (e.g., `"0.5"`
6589
+ * for half a USDC).
6672
6590
  *
6673
- * @returns A new Amount with the negated value.
6591
+ * @defaultValue `"0"`
6674
6592
  *
6675
6593
  * @example
6676
6594
  * ```typescript
6677
- * const a = Amount.parse('1.5', { decimals: 6 })
6678
- * a.neg().raw // -1_500_000n
6595
+ * import type { BridgeConfig, TransferSpeed } from '@core/provider'
6596
+ *
6597
+ * const config: BridgeConfig = {
6598
+ * transferSpeed: TransferSpeed.FAST,
6599
+ * maxFee: "1", // 1 USDC maximum fee
6600
+ * customFee: {
6601
+ * value: "0.5", // 0.5 USDC developer fee
6602
+ * recipientAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0"
6603
+ * }
6604
+ * }
6679
6605
  * ```
6680
6606
  */
6681
- neg(): Amount;
6607
+ maxFee?: string;
6682
6608
  /**
6683
- * Check if this Amount is zero.
6609
+ * The custom fee to charge for the transfer.
6684
6610
  *
6685
- * @returns True if the raw value is 0n.
6611
+ * Whatever value you provide here is **added on top of the transfer amount**. The user must have
6612
+ * enough balance for `amount + customFee`, and the wallet signs for that total on the source
6613
+ * chain. The custom fee is split automatically:
6686
6614
  *
6687
- * @example
6688
- * ```typescript
6689
- * Amount.zero({ decimals: 6 }).isZero() // true
6690
- * Amount.parse('0.001', { decimals: 6 }).isZero() // false
6691
- * ```
6692
- */
6693
- isZero(): boolean;
6694
- /**
6695
- * Check if this Amount is positive.
6615
+ * - 10% routes to Circle.
6616
+ * - 90% routes to your `recipientAddress`.
6696
6617
  *
6697
- * @returns True if the raw value is greater than 0n.
6618
+ * The original transfer amount proceeds through CCTPv2 unchanged, and the protocol fee (1–14 bps
6619
+ * in FAST mode, 0% in STANDARD) is taken from that transfer amount.
6698
6620
  *
6699
6621
  * @example
6700
6622
  * ```typescript
6701
- * Amount.parse('1.0', { decimals: 6 }).isPositive() // true
6702
- * Amount.zero({ decimals: 6 }).isPositive() // false
6703
- * ```
6704
- */
6705
- isPositive(): boolean;
6706
- /**
6707
- * Check if this Amount is negative.
6623
+ * import type { BridgeConfig } from '@core/provider'
6708
6624
  *
6709
- * @returns True if the raw value is less than 0n.
6625
+ * const config: BridgeConfig = {
6626
+ * customFee: {
6627
+ * value: '5', // 5 USDC developer fee
6628
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
6629
+ * },
6630
+ * }
6710
6631
  *
6711
- * @example
6712
- * ```typescript
6713
- * Amount.of(-1_000_000n, { decimals: 6 }).isNegative() // true
6714
- * Amount.parse('1.0', { decimals: 6 }).isNegative() // false
6632
+ * // Fee flow for a 100 USDC transfer with 5 USDC custom fee:
6633
+ * // Source chain (Ethereum):
6634
+ * // - Wallet debits: 105 USDC total (100 transfer + 5 custom fee)
6635
+ * // - Custom fee split: 0.5 USDC (10%) → Circle, 4.5 USDC (90%) → your recipientAddress
6636
+ * // - Amount sent to CCTPv2: 100 USDC (unchanged)
6637
+ * //
6638
+ * // Destination chain (Base):
6639
+ * // - CCTPv2 FAST fee (example: 1 bps): ~0.01 USDC deducted
6640
+ * // - User receives: ~99.99 USDC
6641
+ * //
6642
+ * // Note: Actual CCTP fees vary by route (1-14 bps for FAST, 0 bps for STANDARD)
6715
6643
  * ```
6716
6644
  */
6717
- isNegative(): boolean;
6645
+ customFee?: CustomFee | undefined;
6718
6646
  /**
6719
- * Convert this Amount to a different decimal precision.
6720
- *
6721
- * @param newDecimals - The target number of decimal places.
6722
- * @returns A new Amount with adjusted precision (or this if same precision).
6723
- * @throws KitError If newDecimals is invalid.
6724
- *
6725
- * @example
6726
- * ```typescript
6727
- * // Scale up: 6 decimals → 18 decimals
6728
- * const usdc = Amount.parse('1.5', { decimals: 6 })
6729
- * const scaled = usdc.toDecimals(18)
6730
- * scaled.raw // 1_500_000_000_000_000_000n
6647
+ * Which leg pays the protocol fee.
6731
6648
  *
6732
- * // Scale down: 18 decimals → 6 decimals (truncates)
6733
- * const eth = Amount.of(1_500_000_000_000_000_000n, { decimals: 18 })
6734
- * eth.toDecimals(6).raw // 1_500_000n
6735
- * ```
6649
+ * `'source'` leaves the delivered amount unreduced; `'destination'` takes the
6650
+ * fee from it. Omit it to let the routed provider decide — a provider rejects
6651
+ * a value it cannot honour.
6736
6652
  */
6737
- toDecimals(newDecimals: number): Amount;
6653
+ feePayment?: 'source' | 'destination' | undefined;
6654
+ }
6655
+ /**
6656
+ * Custom fee configuration charged by the integrator.
6657
+ *
6658
+ * Use to charge an absolute fee on the source chain in human-readable
6659
+ * token amounts.
6660
+ *
6661
+ * @remarks
6662
+ * This is an absolute amount, not a percentage. The `recipientAddress` must be
6663
+ * a valid address for the source chain of the transfer.
6664
+ *
6665
+ * @example
6666
+ * ```typescript
6667
+ * import type { CustomFee } from '@core/provider'
6668
+ *
6669
+ * const config: CustomFee = {
6670
+ * value: '1', // 1 USDC
6671
+ * recipientAddress: '0x1234567890123456789012345678901234567890',
6672
+ * }
6673
+ * ```
6674
+ */
6675
+ interface CustomFee {
6738
6676
  /**
6739
- * Format this Amount as a human-readable string.
6677
+ * The absolute fee to charge for the transfer.
6740
6678
  *
6741
- * @param options - Formatting options (locale, fraction digits, grouping).
6742
- * @returns A formatted string (e.g., "1,000.50").
6679
+ * Provide the amount as a base-10 numeric string representing the token
6680
+ * amount in human-readable format. For example: to charge 1 USDC, pass
6681
+ * `"1"`. Decimal values are supported (e.g., `"0.5"` for half a USDC).
6682
+ * This is not a percentage.
6743
6683
  *
6744
- * @example
6745
- * ```typescript
6746
- * const a = Amount.parse('1000.5', { decimals: 6 })
6747
- * a.formatted() // "1,000.5"
6748
- * a.formatted({ minimumFractionDigits: 2 }) // "1,000.50"
6749
- * a.formatted({ useGrouping: false }) // "1000.5"
6750
- * ```
6684
+ * Note: passing `"0"` results in no fee being charged.
6751
6685
  */
6752
- formatted(options?: FormatOptions): string;
6686
+ value?: string | undefined;
6753
6687
  /**
6754
- * Convert to a human-readable string.
6688
+ * The fee recipient for the bridge transfer.
6755
6689
  *
6756
- * @returns A formatted string like "1.5".
6690
+ * This is the address that will receive the fee on the source chain of the
6691
+ * bridge transfer. The fee recipient address **must be a valid address for
6692
+ * the source chain** of the bridge transfer.
6757
6693
  *
6758
6694
  * @remarks
6759
- * For display with a token symbol, combine with the token registry:
6760
- * ```typescript
6761
- * `${amount.toString()} ${token.symbol}`
6762
- * ```
6695
+ * Circle automatically receives 10% of every custom fee; the remaining 90% is
6696
+ * sent to this `recipientAddress`.
6763
6697
  *
6764
- * @example
6765
- * ```typescript
6766
- * const a = Amount.parse('1.5', { decimals: 6 })
6767
- * a.toString() // "1.5"
6768
- * ```
6698
+ * For example: if bridging from Ethereum to Solana, pass an EVM address like
6699
+ * `"0x1234567890123456789012345678901234567890"` because the source chain
6700
+ * is Ethereum.
6769
6701
  */
6770
- toString(): string;
6702
+ recipientAddress?: string | undefined;
6703
+ }
6704
+ /**
6705
+ * Represents the context of an adapter used for cross-chain operations.
6706
+ *
6707
+ * An AdapterContext must always specify both the adapter and the chain explicitly.
6708
+ * The address field behavior is determined by the adapter's address control model:
6709
+ *
6710
+ * - **Developer-controlled adapters**: The `address` field is required because
6711
+ * each operation must explicitly specify which address to use.
6712
+ * - **User-controlled adapters**: The `address` field is forbidden because
6713
+ * the address is automatically resolved from the connected wallet or signer.
6714
+ * - **Legacy adapters**: The `address` field remains optional for backward compatibility.
6715
+ *
6716
+ * This ensures clear, debuggable code where the intended chain is always visible at the call site,
6717
+ * and address requirements are enforced at compile time based on adapter capabilities.
6718
+ *
6719
+ * @typeParam TAdapterCapabilities - The adapter capabilities type to derive address requirements from
6720
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6721
+ *
6722
+ * @example
6723
+ * ```typescript
6724
+ * // Developer-controlled adapter (address required)
6725
+ * const devContext: AdapterContext<{ addressContext: 'developer-controlled', supportedChains: [] }> = {
6726
+ * adapter: myDevAdapter,
6727
+ * chain: 'Ethereum',
6728
+ * address: '0x123...' // Required
6729
+ * }
6730
+ *
6731
+ * // User-controlled adapter (address forbidden)
6732
+ * const userContext: AdapterContext<{ addressContext: 'user-controlled', supportedChains: [] }> = {
6733
+ * adapter: myUserAdapter,
6734
+ * chain: 'Ethereum'
6735
+ * // address: '0x123...' // TypeScript error: not allowed
6736
+ * }
6737
+ * ```
6738
+ */
6739
+ type AdapterContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = {
6740
+ /** The adapter instance for blockchain operations */
6741
+ adapter: Adapter<TAdapterCapabilities>;
6742
+ /** The chain reference, which can be a ChainDefinition, Blockchain enum, or string literal */
6743
+ chain: TChainIdentifier;
6744
+ } & AddressField<ExtractAddressContext<TAdapterCapabilities>>;
6745
+ /**
6746
+ * Represents a bridge destination with an explicit custom recipient address.
6747
+ *
6748
+ * Extends {@link AdapterContext} with an additional `recipientAddress` field to specify
6749
+ * a custom recipient that differs from the adapter's address. Use this when bridging to
6750
+ * third-party wallets or smart contracts rather than the default address associated with
6751
+ * the destination adapter.
6752
+ *
6753
+ * @typeParam TCapabilities - The adapter capabilities type for the destination adapter
6754
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6755
+ *
6756
+ * @remarks
6757
+ * The `recipientAddress` must be a valid address format for the destination chain
6758
+ * specified in the adapter context. The bridge provider validates address compatibility
6759
+ * during the transfer preparation phase and will throw an error if the address format
6760
+ * is invalid for the target chain.
6761
+ *
6762
+ * @example
6763
+ * ```typescript
6764
+ * import { BridgeDestinationWithAddress } from '@core/provider'
6765
+ * import { ethereumAdapter } from './adapters'
6766
+ *
6767
+ * // Bridge to a custom recipient address on Ethereum
6768
+ * const destination: BridgeDestinationWithAddress = {
6769
+ * adapter: ethereumAdapter,
6770
+ * chain: 'Ethereum',
6771
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0'
6772
+ * }
6773
+ * ```
6774
+ */
6775
+ type BridgeDestinationWithAddress<TCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = AdapterContext<TCapabilities, TChainIdentifier> & {
6771
6776
  /**
6772
- * Convert to a JSON-serializable object.
6777
+ * The custom recipient address on the destination chain.
6773
6778
  *
6774
- * @returns An object with raw (as string), decimals, and formatted value.
6779
+ * Must be a valid address format for the chain specified in this adapter context.
6780
+ * This address will receive the bridged funds instead of the adapter's default address.
6781
+ */
6782
+ recipientAddress: string;
6783
+ };
6784
+ /**
6785
+ * Forwarder-only destination without an adapter.
6786
+ *
6787
+ * Used when Circle's Forwarder handles the mint transaction and no destination
6788
+ * adapter is available. Requires both `useForwarder: true` and a `recipientAddress`.
6789
+ *
6790
+ * When using this destination type:
6791
+ * - The mint step completes when the IRIS API confirms `forwardState === 'CONFIRMED'`
6792
+ * - No on-chain transaction confirmation is performed (no adapter available)
6793
+ * - The mint step's `data` field will be undefined (no transaction receipt)
6794
+ *
6795
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6796
+ *
6797
+ * @example
6798
+ * ```typescript
6799
+ * // Forwarder-only destination (no adapter needed)
6800
+ * const dest: ForwarderDestination = {
6801
+ * chain: 'Base',
6802
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
6803
+ * useForwarder: true
6804
+ * }
6805
+ * ```
6806
+ */
6807
+ interface ForwarderDestination<TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> {
6808
+ /** The destination chain where USDC will be minted */
6809
+ chain: TChainIdentifier;
6810
+ /** The recipient address that will receive the minted USDC */
6811
+ recipientAddress: string;
6812
+ /** Must be true for forwarder-only destinations */
6813
+ useForwarder: true;
6814
+ }
6815
+ /**
6816
+ * Union type representing a bridge destination.
6817
+ *
6818
+ * Supports multiple destination configurations:
6819
+ * - {@link AdapterContext}: Standard destination with adapter (for default recipient)
6820
+ * - {@link BridgeDestinationWithAddress}: Destination with adapter and custom recipient
6821
+ * - {@link ForwarderDestination}: Forwarder-only destination without adapter (requires recipientAddress)
6822
+ *
6823
+ * When `useForwarder` is enabled with an adapter, Circle's Orbit relayer handles the mint
6824
+ * transaction and the adapter is used to wait for transaction confirmation.
6825
+ *
6826
+ * When `useForwarder` is enabled without an adapter (ForwarderDestination), the mint step
6827
+ * completes when the IRIS API confirms `forwardState === 'CONFIRMED'` without on-chain
6828
+ * confirmation.
6829
+ *
6830
+ * @typeParam TAdapterCapabilities - The adapter capabilities type for the destination adapter
6831
+ * @typeParam TChainIdentifier - The chain identifier type constraint (defaults to ChainIdentifier)
6832
+ *
6833
+ * @example
6834
+ * ```typescript
6835
+ * // Standard destination with adapter
6836
+ * const dest1: BridgeDestination = { adapter, chain: 'Base' }
6837
+ *
6838
+ * // Destination with adapter and custom recipient
6839
+ * const dest2: BridgeDestination = { adapter, chain: 'Base', recipientAddress: '0x...' }
6840
+ *
6841
+ * // Destination with forwarder enabled (adapter for tx confirmation)
6842
+ * const dest3: BridgeDestination = { adapter, chain: 'Base', useForwarder: true }
6843
+ *
6844
+ * // Forwarder-only destination (no adapter, requires recipientAddress)
6845
+ * const dest4: BridgeDestination = { chain: 'Base', useForwarder: true, recipientAddress: '0x...' }
6846
+ * ```
6847
+ */
6848
+ type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TChainIdentifier extends ChainIdentifier$1 = ChainIdentifier$1> = ((AdapterContext<TAdapterCapabilities, TChainIdentifier> | BridgeDestinationWithAddress<TAdapterCapabilities, TChainIdentifier>) & {
6849
+ /**
6850
+ * Enable Circle's relayer to submit the destination transaction.
6775
6851
  *
6776
- * @example
6777
- * ```typescript
6778
- * const a = Amount.parse('1.5', { decimals: 6 })
6779
- * a.toJSON()
6780
- * // { raw: "1500000", decimals: 6, formatted: "1.5" }
6781
- * ```
6852
+ * Where the relay fee is charged depends on the route and on
6853
+ * {@link BridgeConfig.feePayment}: it may be taken from the amount that
6854
+ * arrives, or priced into a quote the source transaction pays.
6855
+ *
6856
+ * Whether the option is required, optional, or refused depends on the
6857
+ * routed provider and the rest of the config.
6782
6858
  */
6783
- toJSON(): AmountJSON;
6859
+ useForwarder?: boolean;
6860
+ }) | ForwarderDestination<TChainIdentifier>;
6861
+
6862
+ /**
6863
+ * MOVED, not new. Lifted from providers/earn-service/src/validations/, where the
6864
+ * same mapper existed; borrow-service uses it instead of adding a second copy.
6865
+ */
6866
+
6867
+ /**
6868
+ * A single claimed (or claimable) reward token amount.
6869
+ *
6870
+ * @example
6871
+ * ```typescript
6872
+ * import type { ClaimedAmount } from '@core/service-client'
6873
+ *
6874
+ * const reward: ClaimedAmount = {
6875
+ * address: '0x9994E35Db50125E0DF82e4c2dde62496CE330999',
6876
+ * symbol: 'MORPHO',
6877
+ * amount: Amount.fromJSON({ raw: '12500000000000000000', decimals: 18 }),
6878
+ * }
6879
+ * ```
6880
+ */
6881
+ interface ClaimedAmount$1 {
6882
+ /** Reward token contract address. */
6883
+ readonly address: string;
6884
+ /** Reward token symbol. */
6885
+ readonly symbol: string;
6886
+ /** Claimed (or claimable) amount. */
6887
+ readonly amount: Amount;
6888
+ }
6889
+
6890
+ /**
6891
+ * MOVED, not new. The claim-rewards result types previously declared
6892
+ * identically in providers/earn-service/src/types.ts and
6893
+ * providers/borrow-service/src/types.ts. Both now re-export from here.
6894
+ */
6895
+ /**
6896
+ * Provider-level result types for the claim-rewards contract.
6897
+ *
6898
+ * The claim-rewards contract returns the same shapes to every kit that
6899
+ * consumes it, so these are declared once here rather than per service.
6900
+ *
6901
+ * @packageDocumentation
6902
+ */
6903
+
6904
+ /**
6905
+ * Result returned when no rewards were claimable.
6906
+ *
6907
+ * No transaction is submitted in this case, so there is no hash to report.
6908
+ */
6909
+ interface NoClaimableRewardsResult {
6910
+ /** Discriminant: nothing was claimable. */
6911
+ readonly status: 'no_rewards';
6912
+ /** Always empty. */
6913
+ readonly rewards: readonly [];
6914
+ }
6915
+ /**
6916
+ * Read-only claimable-rewards quote.
6917
+ *
6918
+ * Services may extend this with their own optional fields (e.g. EarnKit
6919
+ * carries an always-empty `gasFees` for symmetry with its other quotes); the
6920
+ * `rewards` list itself is contract-defined and identical everywhere.
6921
+ */
6922
+ interface ClaimRewardsQuoteInfo$1 {
6923
+ /** Reward tokens currently available for claiming. */
6924
+ readonly rewards: readonly ClaimedAmount$1[];
6784
6925
  }
6785
6926
 
6786
6927
  /** @internal */
@@ -7597,20 +7738,19 @@ interface EarnWithdrawResult {
7597
7738
  * Extend {@link AssetAmount} with a required contract address.
7598
7739
  * The former `tokenAddress` field is now `address`, and
7599
7740
  * `amountBaseUnits` / `decimals` are collapsed into `amount`.
7741
+ *
7742
+ * @remarks
7743
+ * This is a distinct type from `@core/service-client`'s `ClaimedAmount`, which
7744
+ * carries only `address`/`symbol`/`amount`. This local, richer type is the one
7745
+ * used throughout this package (`provider/claimRewards/claimRewards.ts`,
7746
+ * `validations/schemas.ts`), by `@circle-fin/earn-kit`, and as the `rewards`
7747
+ * element type of this file's {@link ClaimRewardsResult}; take care to import
7748
+ * the one you actually mean.
7600
7749
  */
7601
7750
  interface ClaimedAmount extends AssetAmount {
7602
7751
  /** Reward token contract address (always present for claimed rewards). */
7603
7752
  readonly address: string;
7604
7753
  }
7605
- /**
7606
- * Result returned when no rewards are claimable.
7607
- */
7608
- interface NoClaimableRewardsResult {
7609
- /** Discriminates the no-op result where no transaction was submitted. */
7610
- readonly status: 'no_rewards';
7611
- /** Empty because there were no rewards to claim. */
7612
- readonly rewards: readonly [];
7613
- }
7614
7754
  /**
7615
7755
  * Fields shared by both {@link EarnGasFeeEstimate} variants.
7616
7756
  *
@@ -7789,9 +7929,7 @@ interface WithdrawalQuoteInfo {
7789
7929
  * - `amount` — claimable amount as an {@link Amount}
7790
7930
  * - `address` — reward token contract address
7791
7931
  */
7792
- interface ClaimRewardsQuoteInfo {
7793
- /** Reward tokens available for claiming. */
7794
- readonly rewards: readonly AssetAmount[];
7932
+ interface ClaimRewardsQuoteInfo extends ClaimRewardsQuoteInfo$1 {
7795
7933
  /**
7796
7934
  * Estimated native gas fees for claiming rewards.
7797
7935
  *
@@ -9128,7 +9266,7 @@ interface ServiceSwapConfig {
9128
9266
  *
9129
9267
  * @defaultValue true
9130
9268
  */
9131
- batchTransactions?: boolean;
9269
+ batchTransactions?: boolean | undefined;
9132
9270
  }
9133
9271
  /**
9134
9272
  * Parameters for initiating a swap operation through the Stablecoin Service.
@@ -9592,6 +9730,33 @@ interface SwapConfig {
9592
9730
  * `apiKey` is omitted, and `apiKey` takes precedence when both are set.
9593
9731
  */
9594
9732
  kitKey?: string;
9733
+ /**
9734
+ * Enable or disable atomic batched execution of the approval and swap.
9735
+ *
9736
+ * When `true` (or omitted), an EVM swap that needs an on-chain ERC-20
9737
+ * approval submits the approval and the swap as one atomic batch if the
9738
+ * connected wallet supports it (EIP-5792, or a signing strategy that
9739
+ * declares atomic batching). Set to `false` to force the sequential
9740
+ * approve-then-swap flow.
9741
+ *
9742
+ * @remarks
9743
+ * Has no effect on the gasless permit path, native-token swaps, or Solana,
9744
+ * which already execute as a single transaction. USDT input always uses the
9745
+ * sequential path because its allowance must be reset to zero first. The
9746
+ * batched path relies on the wallet's own gas estimation for the swap call;
9747
+ * set `false` if your wallet under-estimates gas for complex routes or
9748
+ * rejects batched calls.
9749
+ *
9750
+ * @defaultValue `undefined` (batching attempted when the wallet supports it)
9751
+ *
9752
+ * @example
9753
+ * ```typescript
9754
+ * const config: SwapConfig = {
9755
+ * batchTransactions: false, // force sequential approve → swap
9756
+ * }
9757
+ * ```
9758
+ */
9759
+ batchTransactions?: boolean | undefined;
9595
9760
  }
9596
9761
  /**
9597
9762
  * Resolved parameters for swap operations after validation and normalization.
@@ -9960,8 +10125,8 @@ interface AppKitContext {
9960
10125
  *
9961
10126
  * This property stores event handlers that are registered via the AppKit's
9962
10127
  * `on()` method. Handlers are grouped by operation type. The runtime buckets
9963
- * are `bridge` and `earn`; the context can add more operation buckets as
9964
- * AppKit wires action handlers for additional kits.
10128
+ * are `bridge`, `earn`, and `borrow`; the context can add more operation
10129
+ * buckets as AppKit wires action handlers for additional kits.
9965
10130
  *
9966
10131
  * Within each operation bucket, handlers are keyed by action name (for
9967
10132
  * example, `bridge.approve` or `earn.deposit`) or `*` for wildcard handlers.
@@ -9980,13 +10145,13 @@ interface AppKitContext {
9980
10145
  * // Earn handlers are registered with EarnKit when earn operations run
9981
10146
  * ```
9982
10147
  */
9983
- actions: Record<'bridge' | 'earn', Record<string, ((payload: unknown) => void)[]>>;
10148
+ actions: Record<'bridge' | 'earn' | 'borrow', Record<string, ((payload: unknown) => void)[]>>;
9984
10149
  /**
9985
- * Disable success analytics for the underlying EarnKit, SwapKit, and
9986
- * UnifiedBalanceKit.
10150
+ * Disable success analytics for the underlying EarnKit, SwapKit,
10151
+ * BorrowKit, and UnifiedBalanceKit.
9987
10152
  *
9988
- * When `true`, completed earn, swap, and unified balance operations will not
9989
- * POST analytics events. This does not disable error reporting; use
10153
+ * When `true`, completed earn, swap, borrow, and unified balance operations
10154
+ * will not POST analytics events. This does not disable error reporting; use
9990
10155
  * {@link AppKitContext.disableErrorReporting} for that. Defaults to `false`.
9991
10156
  *
9992
10157
  * @defaultValue false
@@ -9996,7 +10161,7 @@ interface AppKitContext {
9996
10161
  * Disable error telemetry for all sub-kits.
9997
10162
  *
9998
10163
  * When `true`, none of the underlying kits (BridgeKit, SwapKit, EarnKit,
9999
- * UnifiedBalanceKit) will POST error details to the telemetry
10164
+ * BorrowKit, UnifiedBalanceKit) will POST error details to the telemetry
10000
10165
  * endpoint when operations throw. Defaults to `false` (enabled).
10001
10166
  *
10002
10167
  * @defaultValue false