@circle-fin/app-kit 1.10.0 → 1.12.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.
@@ -740,6 +740,8 @@ declare enum Blockchain {
740
740
  World_Chain_Sepolia = "World_Chain_Sepolia",
741
741
  XDC = "XDC",
742
742
  XDC_Apothem = "XDC_Apothem",
743
+ X_Layer = "X_Layer",
744
+ X_Layer_Testnet = "X_Layer_Testnet",
743
745
  ZKSync_Era = "ZKSync_Era",
744
746
  ZKSync_Sepolia = "ZKSync_Sepolia"
745
747
  }
@@ -952,6 +954,7 @@ declare enum BridgeChain {
952
954
  Unichain = "Unichain",
953
955
  World_Chain = "World_Chain",
954
956
  XDC = "XDC",
957
+ X_Layer = "X_Layer",
955
958
  Arc_Testnet = "Arc_Testnet",
956
959
  Arbitrum_Sepolia = "Arbitrum_Sepolia",
957
960
  Avalanche_Fuji = "Avalanche_Fuji",
@@ -975,7 +978,8 @@ declare enum BridgeChain {
975
978
  Sonic_Testnet = "Sonic_Testnet",
976
979
  Unichain_Sepolia = "Unichain_Sepolia",
977
980
  World_Chain_Sepolia = "World_Chain_Sepolia",
978
- XDC_Apothem = "XDC_Apothem"
981
+ XDC_Apothem = "XDC_Apothem",
982
+ X_Layer_Testnet = "X_Layer_Testnet"
979
983
  }
980
984
  /**
981
985
  * Type representing valid bridge chain identifiers.
@@ -5260,6 +5264,132 @@ declare enum TransferSpeed {
5260
5264
  /** Standard burn mode - normal transfer time with standard fees */
5261
5265
  SLOW = "SLOW"
5262
5266
  }
5267
+ /**
5268
+ * Context object representing a wallet and signing authority on a specific blockchain network.
5269
+ *
5270
+ * Combines a wallet or contract address, the blockchain it resides on, and the adapter (signer)
5271
+ * responsible for authorizing transactions. Used to specify the source or destination in cross-chain
5272
+ * transfer operations.
5273
+ *
5274
+ * @remarks
5275
+ * The `adapter` (signer) and `address` do not always have to belong to the same entity. For example,
5276
+ * in minting or withdrawal scenarios, the signing adapter may authorize a transaction that credits
5277
+ * funds to a different recipient address. This context is essential for cross-chain operations,
5278
+ * ensuring that both the address and the associated adapter are correctly paired with the intended
5279
+ * blockchain, but not necessarily with each other.
5280
+ *
5281
+ * @example
5282
+ * ```typescript
5283
+ * import type { WalletContext } from '@core/provider'
5284
+ * import { adapter, blockchain } from './setup'
5285
+ *
5286
+ * const wallet: WalletContext = {
5287
+ * adapter,
5288
+ * address: '0x1234...abcd',
5289
+ * chain: blockchain,
5290
+ * }
5291
+ * ```
5292
+ */
5293
+ interface WalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
5294
+ /**
5295
+ * The chain definition type to use for the wallet context.
5296
+ *
5297
+ * @defaultValue ChainDefinition
5298
+ */
5299
+ TChainDefinition extends ChainDefinition = ChainDefinition> {
5300
+ /**
5301
+ * The adapter (signer) for the wallet on the specified chain.
5302
+ *
5303
+ * Responsible for authorizing transactions and signing messages on behalf of the wallet or
5304
+ * for a different recipient, depending on the use case.
5305
+ */
5306
+ adapter: Adapter<TAdapterCapabilities>;
5307
+ /**
5308
+ * The wallet or contract address.
5309
+ *
5310
+ * Must be a valid address format for the specified blockchain. May differ from the adapter's
5311
+ * own address in scenarios such as relayed transactions or third-party minting.
5312
+ */
5313
+ address: string;
5314
+ /**
5315
+ * The blockchain network where the wallet or contract address resides.
5316
+ *
5317
+ * Determines the context and format for the address and adapter.
5318
+ */
5319
+ chain: TChainDefinition;
5320
+ }
5321
+ /**
5322
+ * Wallet context for bridge destinations with optional custom recipient.
5323
+ *
5324
+ * Extends WalletContext to support scenarios where the recipient address
5325
+ * differs from the signer address (e.g., bridging to a third-party wallet).
5326
+ * The signer address is used for transaction authorization, while the
5327
+ * recipient address specifies where the minted funds should be sent.
5328
+ *
5329
+ * @typeParam TAdapterCapabilities - The adapter capabilities type to use for the wallet context.
5330
+ * @typeParam TChainDefinition - The chain definition type to use for the wallet context.
5331
+ *
5332
+ * @example
5333
+ * ```typescript
5334
+ * import type { DestinationWalletContext } from '@core/provider'
5335
+ * import { adapter, blockchain } from './setup'
5336
+ *
5337
+ * // Bridge to a custom recipient address
5338
+ * const destination: DestinationWalletContext = {
5339
+ * adapter,
5340
+ * address: '0x1234...abcd', // Signer address
5341
+ * chain: blockchain,
5342
+ * recipientAddress: '0x9876...fedc' // Custom recipient
5343
+ * }
5344
+ * ```
5345
+ */
5346
+ interface DestinationWalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
5347
+ /**
5348
+ * The chain definition type to use for the wallet context.
5349
+ *
5350
+ * @defaultValue ChainDefinition
5351
+ */
5352
+ TChainDefinition extends ChainDefinition = ChainDefinition> extends WalletContext<TAdapterCapabilities, TChainDefinition> {
5353
+ /**
5354
+ * Optional custom recipient address for minted funds.
5355
+ *
5356
+ * When provided, minted tokens will be sent to this address instead of
5357
+ * the address specified in the wallet context. The wallet context address
5358
+ * is still used for transaction signing and authorization.
5359
+ *
5360
+ * Must be a valid address format for the specified blockchain.
5361
+ */
5362
+ recipientAddress?: string;
5363
+ }
5364
+ /**
5365
+ * Parameters for executing a cross-chain bridge operation.
5366
+ */
5367
+ interface BridgeParams$1<TFromCapabilities extends AdapterCapabilities = AdapterCapabilities, TToCapabilities extends AdapterCapabilities = AdapterCapabilities,
5368
+ /**
5369
+ * The chain definition type to use for the wallet context.
5370
+ *
5371
+ * @defaultValue ChainDefinition
5372
+ */
5373
+ TChainDefinition extends ChainDefinition = ChainDefinition> {
5374
+ /** The source adapter containing wallet and chain information */
5375
+ source: WalletContext<TFromCapabilities, TChainDefinition>;
5376
+ /** The destination adapter containing wallet and chain information */
5377
+ destination: DestinationWalletContext<TToCapabilities, TChainDefinition>;
5378
+ /** The amount to transfer (as a string to avoid precision issues) */
5379
+ amount: string;
5380
+ /** The token to transfer (currently only USDC is supported) */
5381
+ token: 'USDC';
5382
+ /** Bridge configuration (e.g., fast burn settings) */
5383
+ config: BridgeConfig;
5384
+ /**
5385
+ * Optional invocation metadata for tracing and correlation.
5386
+ *
5387
+ * When provided, the `traceId` is used to correlate all events emitted during
5388
+ * the bridge operation. If not provided, an OpenTelemetry-compatible traceId
5389
+ * will be auto-generated.
5390
+ */
5391
+ invocationMeta?: InvocationMeta;
5392
+ }
5263
5393
  /**
5264
5394
  * Cost estimation result for a cross-chain transfer operation.
5265
5395
  *
@@ -5630,6 +5760,91 @@ type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = Adapte
5630
5760
  useForwarder?: boolean;
5631
5761
  }) | ForwarderDestination<TChainIdentifier>;
5632
5762
 
5763
+ type FeeFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
5764
+ type FeeRecipientFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (feePayoutChain: ChainDefinition, params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
5765
+ /**
5766
+ * Custom fee policy for BridgeKit.
5767
+ *
5768
+ * Provides hooks to calculate an absolute custom fee and resolve the fee recipient address
5769
+ * on the source chain. The returned fee is **added on top of the transfer amount** (the wallet signs for
5770
+ * `amount + customFee`). Once collected, the custom fee is split:
5771
+ *
5772
+ * - **10%** automatically routes to Circle.
5773
+ * - **90%** routes to your supplied `recipientAddress`.
5774
+ *
5775
+ * The entire transfer amount still flows through CCTPv2, which then charges its own protocol fee.
5776
+ *
5777
+ * Use `computeFee` (recommended) for human-readable amounts, or `calculateFee` (deprecated)
5778
+ * for smallest-unit amounts. Only one should be provided.
5779
+ *
5780
+ * @example
5781
+ * ```typescript
5782
+ * import type { CustomFeePolicy, BridgeParams } from '@circle-fin/bridge-kit'
5783
+ *
5784
+ * const policy: CustomFeePolicy = {
5785
+ * // computeFee receives human-readable amounts (e.g., '100' for 100 USDC)
5786
+ * computeFee: (params: BridgeParams) => {
5787
+ * const amount = parseFloat(params.amount)
5788
+ *
5789
+ * // 1% fee, capped between 5-50 USDC
5790
+ * const fee = Math.min(Math.max(amount * 0.01, 5), 50)
5791
+ * return fee.toFixed(6)
5792
+ * },
5793
+ * resolveFeeRecipientAddress: (feePayoutChain) =>
5794
+ * feePayoutChain.type === 'solana'
5795
+ * ? 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
5796
+ * : '0x1234567890123456789012345678901234567890',
5797
+ * }
5798
+ * ```
5799
+ */
5800
+ type CustomFeePolicy$2 = {
5801
+ /**
5802
+ * A function that returns the fee to charge for the bridge transfer.
5803
+ * The value returned from the function represents an absolute fee.
5804
+ * The returned fee is **added on top of the transfer amount**. For example, returning
5805
+ * `'5'` (5 USDC) for a 100 USDC transfer causes the wallet to debit 105 USDC total.
5806
+ * CCTPv2 still processes the full 100 USDC transfer amount, while the custom fee is split
5807
+ * 10%/90% between Circle and your fee recipient.
5808
+ *
5809
+ * @example
5810
+ * ```typescript
5811
+ * computeFee: (params) => {
5812
+ * const amount = parseFloat(params.amount)
5813
+ * return (amount * 0.01).toString() // 1% fee
5814
+ * }
5815
+ * ```
5816
+ */
5817
+ computeFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
5818
+ calculateFee?: never;
5819
+ /**
5820
+ * A function that returns the fee recipient for a bridge transfer.
5821
+ * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
5822
+ * The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
5823
+ *
5824
+ * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
5825
+ * because the source chain of the bridge transfer is Ethereum.
5826
+ */
5827
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
5828
+ } | {
5829
+ computeFee?: never;
5830
+ /**
5831
+ * Calculate the fee to charge for the bridge transfer using smallest-unit amounts.
5832
+ *
5833
+ * @deprecated Use `computeFee` instead, which receives human-readable amounts.
5834
+ *
5835
+ * The `params.amount` is in smallest units (e.g., `'100000000'` for 100 USDC).
5836
+ */
5837
+ calculateFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
5838
+ /**
5839
+ * A function that returns the fee recipient for a bridge transfer.
5840
+ * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
5841
+ * The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
5842
+ *
5843
+ * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
5844
+ * because the source chain of the bridge transfer is Ethereum.
5845
+ */
5846
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
5847
+ };
5633
5848
  /**
5634
5849
  * Parameters for initiating a cross-chain USDC bridge transfer.
5635
5850
  *
@@ -5734,6 +5949,463 @@ interface BridgeParams<TFromAdapterCapabilities extends AdapterCapabilities = Ad
5734
5949
  invocationMeta?: InvocationMeta;
5735
5950
  }
5736
5951
 
5952
+ /**
5953
+ * Allowance strategy for token approvals during swap operations.
5954
+ *
5955
+ * Defines how token allowances should be granted to the swap contract:
5956
+ * - `permit`: Use EIP-2612 permit signature (gas-efficient, no approval transaction)
5957
+ * - `approve`: Traditional approval transaction
5958
+ *
5959
+ * The default strategy is `permit` with fallback to `approve` if permit is not supported.
5960
+ */
5961
+ type AllowanceStrategy$1 = 'permit' | 'approve';
5962
+ /**
5963
+ * Configuration options for swap operations.
5964
+ *
5965
+ * Controls swap behavior including allowance strategy, slippage tolerance,
5966
+ * minimum output amounts, custom fees, and kit identification.
5967
+ *
5968
+ * @example
5969
+ * ```typescript
5970
+ * import type { ServiceSwapConfig } from '@circle-fin/provider-stablecoin-service-swap'
5971
+ *
5972
+ * // Percentage-based fee
5973
+ * const config: ServiceSwapConfig = {
5974
+ * allowanceStrategy: 'permit',
5975
+ * slippageBps: 300, // 3%
5976
+ * stopLimit: '950000', // Minimum 0.95 USDC output
5977
+ * customFee: {
5978
+ * percentageBps: 1000, // 10% fee
5979
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
5980
+ * }
5981
+ * }
5982
+ * ```
5983
+ *
5984
+ * @example
5985
+ * ```typescript
5986
+ * // Absolute amount fee (from callback)
5987
+ * const config: ServiceSwapConfig = {
5988
+ * allowanceStrategy: 'permit',
5989
+ * customFee: {
5990
+ * amount: '10000', // 0.01 USDC fee (absolute)
5991
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
5992
+ * }
5993
+ * }
5994
+ * ```
5995
+ */
5996
+ interface ServiceSwapConfig {
5997
+ /**
5998
+ * Strategy for granting token allowances to the swap contract.
5999
+ *
6000
+ * Defaults to 'permit' with fallback to 'approve'.
6001
+ */
6002
+ allowanceStrategy?: AllowanceStrategy$1;
6003
+ /**
6004
+ * Maximum acceptable slippage in basis points (BPS).
6005
+ *
6006
+ * 1 BPS = 0.01%, so 300 BPS = 3% slippage.
6007
+ * Defaults to 300 BPS (3%).
6008
+ */
6009
+ slippageBps?: number;
6010
+ /**
6011
+ * Minimum acceptable output amount in smallest units (stop-limit).
6012
+ *
6013
+ * If the estimated output falls below this value, the swap will fail.
6014
+ * Expressed as a string to avoid precision issues.
6015
+ */
6016
+ stopLimit?: string;
6017
+ /**
6018
+ * Custom fee configuration for this swap.
6019
+ *
6020
+ * Supports two mutually exclusive approaches:
6021
+ * 1. Percentage-based: Use `percentageBps` field (simple)
6022
+ * 2. Absolute amount: Use `amount` field (from callback)
6023
+ *
6024
+ * If both are set, validation will fail. Transaction-level percentage
6025
+ * takes precedence over kit-level callback policy.
6026
+ */
6027
+ customFee?: {
6028
+ /**
6029
+ * Fee percentage in basis points (NEW).
6030
+ *
6031
+ * 100 bps = 1%, 1000 bps = 10%, 10000 bps = 100%
6032
+ *
6033
+ * Service calculates fee using `estimatedAmount` for same-chain output fees
6034
+ * and the input amount for cross-chain swaps.
6035
+ * Must be greater than 0 and less than or equal to 10000 (maximum 100%).
6036
+ * Mutually exclusive with `amount`.
6037
+ *
6038
+ * @example 1000 // 10% fee
6039
+ */
6040
+ percentageBps?: number;
6041
+ /**
6042
+ * Fee amount in smallest units (for callback results).
6043
+ *
6044
+ * Absolute fee amount calculated by callback function.
6045
+ * Mutually exclusive with `percentageBps`.
6046
+ *
6047
+ * @example '10000' // 0.01 USDC (6 decimals)
6048
+ */
6049
+ amount?: string;
6050
+ /**
6051
+ * Address that will receive the developer's 90% fee share.
6052
+ *
6053
+ * Required whenever a custom fee is submitted to the provider. Optional at
6054
+ * the type level so SDK callback flows can represent partial fee state
6055
+ * before final validation.
6056
+ *
6057
+ * Must be valid on the fee payout chain: source chain for input-side fees
6058
+ * and cross-chain swaps, destination chain for same-chain output-side fees.
6059
+ *
6060
+ * @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6061
+ */
6062
+ recipientAddress?: string;
6063
+ };
6064
+ /**
6065
+ * Stablecoin Service Kit Key used to authenticate service-backed swap
6066
+ * requests.
6067
+ *
6068
+ * Treat this value as a credential. Do not log it, embed it in client-side
6069
+ * source, or expose it in telemetry.
6070
+ */
6071
+ kitKey?: string;
6072
+ /**
6073
+ * DEX aggregator identifier used to source the swap route.
6074
+ *
6075
+ * @example 'lifi', 'paraswap'
6076
+ */
6077
+ provider?: string;
6078
+ /**
6079
+ * Whether to fuse the ERC-20 approval and the swap into a single atomic
6080
+ * batch when the adapter supports it (EIP-5792, or a signing strategy that
6081
+ * declares atomic batching).
6082
+ *
6083
+ * @remarks
6084
+ * Defaults to `true`. When batching is available this collapses the two
6085
+ * sequential transactions of the on-chain approval path into one atomic
6086
+ * submission — a single signing challenge for a smart-contract wallet. Set
6087
+ * to `false` to force the sequential approve-then-swap path. Has no effect on
6088
+ * the gasless permit path (already a single transaction) or on native-token
6089
+ * swaps (no approval needed).
6090
+ *
6091
+ * The batch path relies on the wallet's own gas estimation for the swap call:
6092
+ * the service-provided gas floor and pre-flight simulation that the sequential
6093
+ * path applies are not conveyed through the batch. For a complex/multi-hop
6094
+ * swap whose wallet-side estimate under-shoots, this can out-of-gas-revert the
6095
+ * atomic batch where the sequential path would succeed — set `false` to fall
6096
+ * back to the service-floored sequential path if you hit this.
6097
+ *
6098
+ * @defaultValue true
6099
+ */
6100
+ batchTransactions?: boolean;
6101
+ }
6102
+ /**
6103
+ * Parameters for initiating a swap operation through the Stablecoin Service.
6104
+ *
6105
+ * This type is used as the primary input to provider swap operations, allowing users to specify
6106
+ * the source context, input/output tokens, swap amount, destination address, and optional configuration.
6107
+ *
6108
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
6109
+ *
6110
+ * @example
6111
+ * ```typescript
6112
+ * import type { ServiceSwapParams } from '@circle-fin/provider-stablecoin-service-swap'
6113
+ * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
6114
+ * import { Ethereum } from '@core/chains'
6115
+ *
6116
+ * const adapter = createAdapterFromPrivateKey({
6117
+ * privateKey: process.env.PRIVATE_KEY,
6118
+ * })
6119
+ *
6120
+ * const params: ServiceSwapParams = {
6121
+ * from: { adapter, chain: Ethereum },
6122
+ * tokenIn: 'USDC', // Alias resolves to chain-specific address
6123
+ * tokenOut: 'USDT', // Alias resolves to chain-specific address
6124
+ * amountIn: '100500000', // 100.50 USDC in base units
6125
+ * to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
6126
+ * config: {
6127
+ * slippageBps: 300, // 3% slippage
6128
+ * allowanceStrategy: 'permit'
6129
+ * }
6130
+ * }
6131
+ * ```
6132
+ */
6133
+ interface ServiceSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
6134
+ /**
6135
+ * The chain definition type to use for the wallet context.
6136
+ *
6137
+ * @defaultValue ChainDefinition
6138
+ */
6139
+ TChainDefinition extends ChainDefinition = ChainDefinition> {
6140
+ /**
6141
+ * The source adapter context (wallet and chain) for the swap.
6142
+ */
6143
+ from: WalletContext<TFromAdapterCapabilities, TChainDefinition>;
6144
+ /**
6145
+ * The input token address or alias to swap from.
6146
+ *
6147
+ * **Supported formats:**
6148
+ * - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
6149
+ * - EVM address: `'0x'` prefixed hex (e.g., `'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'`)
6150
+ * - Solana address: Base58-encoded (e.g., `'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'`)
6151
+ *
6152
+ * Token aliases are automatically resolved to the chain-specific contract address.
6153
+ *
6154
+ * @example 'USDC' // Recommended: use alias
6155
+ * @example '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // Or full address
6156
+ */
6157
+ tokenIn: string;
6158
+ /**
6159
+ * The output token address or alias to swap to.
6160
+ *
6161
+ * **Supported formats:**
6162
+ * - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
6163
+ * - EVM address: `'0x'` prefixed hex (e.g., `'0xdAC17F958D2ee523a2206206994597C13D831ec7'`)
6164
+ * - Solana address: Base58-encoded (e.g., `'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'`)
6165
+ *
6166
+ * Token aliases are automatically resolved to the chain-specific contract address.
6167
+ *
6168
+ * @example 'USDT' // Recommended: use alias
6169
+ * @example '0xdAC17F958D2ee523a2206206994597C13D831ec7' // Or full address
6170
+ */
6171
+ tokenOut: string;
6172
+ /**
6173
+ * The amount of input token to swap in base units.
6174
+ *
6175
+ * SwapKit converts human-readable amounts to base units before passing to the provider.
6176
+ *
6177
+ * @example '100500000' for 100.50 USDC (6 decimals)
6178
+ */
6179
+ amountIn: string;
6180
+ /**
6181
+ * The destination address where the swapped tokens will be sent.
6182
+ *
6183
+ * @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6184
+ */
6185
+ to: string;
6186
+ /**
6187
+ * Optional destination chain for cross-chain swaps.
6188
+ *
6189
+ * Defaults to `from.chain` for same-chain swaps.
6190
+ */
6191
+ toChain?: TChainDefinition;
6192
+ /**
6193
+ * Optional configuration for swap behavior.
6194
+ *
6195
+ * If omitted, defaults will be used:
6196
+ * - allowanceStrategy: 'permit' (fallback to 'approve')
6197
+ * - slippageBps: 300 (3%)
6198
+ */
6199
+ config?: ServiceSwapConfig;
6200
+ }
6201
+
6202
+ /**
6203
+ * Fee context when fee is taken from INPUT token.
6204
+ *
6205
+ * Used for swaps where the fee is collected from the input token, including
6206
+ * all cross-chain swaps.
6207
+ * Extends the resolved swap parameters with a discriminator to indicate input fee scenario.
6208
+ *
6209
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6210
+ *
6211
+ * @example
6212
+ * ```typescript
6213
+ * // USDC → RandomToken swap (fee from input)
6214
+ * const context: SwapInputFeeContext = {
6215
+ * type: 'input',
6216
+ * from: {
6217
+ * adapter: viemAdapter,
6218
+ * chain: Ethereum,
6219
+ * address: '0x...'
6220
+ * },
6221
+ * tokenIn: 'USDC',
6222
+ * tokenOut: 'RandomToken',
6223
+ * amountIn: '100000000', // 100 USDC in base units
6224
+ * to: '0x...'
6225
+ * }
6226
+ * ```
6227
+ */
6228
+ interface SwapInputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
6229
+ /**
6230
+ * Fee source discriminator - input token.
6231
+ */
6232
+ type: 'input';
6233
+ }
6234
+ /**
6235
+ * Fee context when fee is taken from OUTPUT token.
6236
+ *
6237
+ * Used for swaps where the output token is supported for fee collection.
6238
+ * Extends the resolved swap parameters with output amounts and discriminator.
6239
+ *
6240
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6241
+ *
6242
+ * @remarks
6243
+ * If using `estimatedAmount` in callback and quote cache expires,
6244
+ * calculated fee may not match fresh quote. Use `minAmount` for
6245
+ * predictability at the cost of potentially lower fees.
6246
+ *
6247
+ * @example
6248
+ * ```typescript
6249
+ * // RandomToken → USDC swap (fee from output)
6250
+ * const context: SwapOutputFeeContext = {
6251
+ * type: 'output',
6252
+ * from: {
6253
+ * adapter: viemAdapter,
6254
+ * chain: Ethereum,
6255
+ * address: '0x...'
6256
+ * },
6257
+ * tokenIn: 'RandomToken',
6258
+ * tokenOut: 'USDC',
6259
+ * amountIn: '100000000',
6260
+ * to: '0x...',
6261
+ * minAmount: '50000000', // 50 USDC guaranteed minimum
6262
+ * estimatedAmount: '55000000' // 55 USDC expected output
6263
+ * }
6264
+ * ```
6265
+ */
6266
+ interface SwapOutputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
6267
+ /**
6268
+ * Fee source discriminator - output token.
6269
+ */
6270
+ type: 'output';
6271
+ /**
6272
+ * Guaranteed minimum output amount in base units.
6273
+ *
6274
+ * More stable but lower than estimatedAmount. Use this for
6275
+ * predictable fee calculations.
6276
+ */
6277
+ minAmount: string;
6278
+ /**
6279
+ * Estimated output amount in base units.
6280
+ *
6281
+ * Expected output based on current market conditions. May be
6282
+ * higher than minAmount. Subject to change if quote expires.
6283
+ */
6284
+ estimatedAmount: string;
6285
+ }
6286
+ /**
6287
+ * Discriminated union for swap fee contexts.
6288
+ *
6289
+ * Provides different context based on whether fee is from input or output token.
6290
+ * Discriminated by the `type` field: 'input' for fees from input token, 'output' for output token.
6291
+ *
6292
+ * Includes full swap parameters (adapter, chain, tokens, amounts) for maximum flexibility
6293
+ * in fee calculation logic.
6294
+ *
6295
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6296
+ */
6297
+ type SwapFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = SwapInputFeeContext<TFromAdapterCapabilities> | SwapOutputFeeContext<TFromAdapterCapabilities>;
6298
+ /**
6299
+ * Custom fee policy for SwapKit (callback-based approach).
6300
+ *
6301
+ * Provides hooks to calculate an absolute fee amount and resolve the fee
6302
+ * recipient address. The callback receives a discriminated context with
6303
+ * different fields based on operation type (bridge vs swap) and fee source
6304
+ * (input vs output).
6305
+ *
6306
+ * @remarks
6307
+ * This is mutually exclusive with transaction-level percentage fees.
6308
+ * If both are set, the transaction-level percentage takes precedence.
6309
+ *
6310
+ * The callback approach makes two API calls for same-chain output fees:
6311
+ * 1. GET /quote - retrieve fee context and quote
6312
+ * 2. POST /swap - execute with calculated fee
6313
+ *
6314
+ * Cross-chain swaps always use input fees on the source chain, so callbacks
6315
+ * receive `type: 'input'` for those routes.
6316
+ *
6317
+ * @example
6318
+ * ```typescript
6319
+ * import type { CustomFeePolicy } from '@circle-fin/swap-kit'
6320
+ *
6321
+ * const policy: CustomFeePolicy = {
6322
+ * computeFee: async (ctx) => {
6323
+ * // Discriminate by fee source (input vs output)
6324
+ * if (ctx.type === 'input') {
6325
+ * // Simple percentage for input fees
6326
+ * return (parseFloat(ctx.amountIn) * 0.1).toString()
6327
+ * } else {
6328
+ * // Complex logic for output fees (VIP tiers, etc.)
6329
+ * const user = await database.getUser(...)
6330
+ * if (user.isVIP) {
6331
+ * return (parseFloat(ctx.minAmount) * 0.05).toString()
6332
+ * }
6333
+ * return (parseFloat(ctx.estimatedAmount) * 0.1).toString()
6334
+ * }
6335
+ * },
6336
+ * resolveFeeRecipientAddress: (chain) => {
6337
+ * return chain.type === 'solana'
6338
+ * ? 'SolanaAddress...'
6339
+ * : '0xEVMAddress...'
6340
+ * },
6341
+ * }
6342
+ * ```
6343
+ */
6344
+ interface CustomFeePolicy$1 {
6345
+ /**
6346
+ * Calculate custom fee amount based on swap context.
6347
+ *
6348
+ * Receives full swap parameters including adapter, chain, tokens, and amounts.
6349
+ * Context is discriminated by `type` field:
6350
+ * - 'input': Fee from input token (OK → Any swaps and all cross-chain swaps)
6351
+ * - 'output': Fee from output token (same-chain Any → OK swaps), includes minAmount and estimatedAmount
6352
+ *
6353
+ * The wrapper automatically converts amounts to/from base units, so your
6354
+ * callback works with human-readable numbers (e.g., '0.1' for 0.1 USDC).
6355
+ *
6356
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6357
+ * @param context - Discriminated swap fee context with full swap parameters
6358
+ * @returns Absolute fee amount as string in human-readable format
6359
+ *
6360
+ * @example
6361
+ * ```typescript
6362
+ * computeFee: async (ctx) => {
6363
+ * if (ctx.type === 'output') {
6364
+ * // Output fee scenario
6365
+ * // Use estimatedAmount or minAmount for calculation
6366
+ * return (parseFloat(ctx.estimatedAmount) * 0.01).toString()
6367
+ * }
6368
+ * // Input fee scenario
6369
+ * return (parseFloat(ctx.amountIn) * 0.01).toString()
6370
+ * }
6371
+ * ```
6372
+ *
6373
+ * @example
6374
+ * ```typescript
6375
+ * computeFee: async (ctx) => {
6376
+ * if (ctx.type === 'output') {
6377
+ * // Use minAmount for predictable fees
6378
+ * return (parseFloat(ctx.minAmount) * 0.01).toString()
6379
+ * }
6380
+ * return (parseFloat(ctx.amountIn) * 0.01).toString()
6381
+ * }
6382
+ * ```
6383
+ */
6384
+ computeFee: <TFromAdapterCapabilities extends AdapterCapabilities>(context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
6385
+ /**
6386
+ * Resolve fee recipient address for the chain where fee is collected.
6387
+ *
6388
+ * Called with the chain where fee will be paid. For cross-chain swaps this
6389
+ * is always the source chain. Must return a valid address format for that
6390
+ * chain type (EVM or Solana).
6391
+ *
6392
+ * @param feePayoutChain - Chain definition where fee is collected
6393
+ * @param context - The swap fee context with full parameters
6394
+ * @returns Fee recipient address for the chain
6395
+ *
6396
+ * @example
6397
+ * ```typescript
6398
+ * resolveFeeRecipientAddress: (chain, ctx) => {
6399
+ * // Chain-based routing
6400
+ * if (chain.type === 'solana') {
6401
+ * return 'SolanaAddress...'
6402
+ * }
6403
+ * return '0xEVMAddress...'
6404
+ * }
6405
+ * ```
6406
+ */
6407
+ resolveFeeRecipientAddress: <TFromAdapterCapabilities extends AdapterCapabilities>(feePayoutChain: ChainDefinition, context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
6408
+ }
5737
6409
  /**
5738
6410
  * Adapter context constrained to swap-supported chains.
5739
6411
  */
@@ -5881,6 +6553,45 @@ interface SwapConfig {
5881
6553
  */
5882
6554
  kitKey?: string;
5883
6555
  }
6556
+ /**
6557
+ * Resolved parameters for swap operations after validation and normalization.
6558
+ *
6559
+ * Internal type used by SwapKit operations after `resolveSwapParams()` has:
6560
+ * - Validated the input parameters
6561
+ * - Resolved chain identifiers to full ChainDefinition objects
6562
+ * - Extracted and validated wallet addresses
6563
+ *
6564
+ * Note: Raw user input is validated first, then `tokenIn` and `tokenOut` may
6565
+ * be canonicalized for downstream routing (for example, Arc Testnet
6566
+ * `NATIVE` → `USDC`). Address resolution is handled by the provider layer.
6567
+ *
6568
+ * This type is consumed by swap providers and internal operations but is not
6569
+ * exposed to end users. It extends ServiceSwapParams which is the format expected
6570
+ * by the StablecoinServiceSwapProvider.
6571
+ *
6572
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
6573
+ *
6574
+ * @example
6575
+ * ```typescript
6576
+ * // After resolution, SwapParams becomes ResolvedSwapParams:
6577
+ * const resolved: ResolvedSwapParams = {
6578
+ * from: {
6579
+ * adapter: viemAdapter,
6580
+ * chain: Ethereum, // Full chain definition
6581
+ * address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6582
+ * },
6583
+ * tokenIn: 'USDC', // Canonicalized for provider routing
6584
+ * tokenOut: 'USDT', // Canonicalized for provider routing
6585
+ * amountIn: '100500000', // Converted to base units (100.5 USDC with 6 decimals)
6586
+ * to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
6587
+ * config: {
6588
+ * slippageBps: 300,
6589
+ * allowanceStrategy: 'permit'
6590
+ * }
6591
+ * }
6592
+ * ```
6593
+ */
6594
+ type ResolvedSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = ServiceSwapParams<TFromAdapterCapabilities>;
5884
6595
  interface SwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
5885
6596
  /**
5886
6597
  * The source adapter context (wallet and chain) for the swap.
@@ -5993,6 +6704,24 @@ interface EarnConfig {
5993
6704
  * Format: `KIT_KEY:<keyId>:<keySecret>`
5994
6705
  */
5995
6706
  readonly kitKey?: string | undefined;
6707
+ /**
6708
+ * Optional base URL override for the Earn Service API.
6709
+ *
6710
+ * Defaults to `https://api.circle.com` when omitted. Override for testing
6711
+ * against staging or local environments.
6712
+ */
6713
+ readonly baseUrl?: string | undefined;
6714
+ /**
6715
+ * Enable or disable atomic batched transaction execution.
6716
+ *
6717
+ * When `true` (or `undefined` / omitted), same-chain deposit and withdraw
6718
+ * bundle the approve and execute calls into one adapter-native atomic batch
6719
+ * when the connected wallet supports it. Set to `false` to force the
6720
+ * sequential approve → execute flow.
6721
+ *
6722
+ * @defaultValue `undefined` (batching attempted when the wallet supports it)
6723
+ */
6724
+ readonly batchTransactions?: boolean | undefined;
5996
6725
  }
5997
6726
  /**
5998
6727
  * Parameters for fetching vault information.
@@ -6425,6 +7154,122 @@ interface GetClaimRewardsQuoteParams<TFromAdapterCapabilities extends AdapterCap
6425
7154
  */
6426
7155
  type EarnOperationParams = AnyDepositParams | WithdrawParams | ClaimRewardsParams | GetVaultsParams | ExploreVaultsParams | ExploreVaultsIteratorParams | GetPositionParams | GetDepositQuoteParams | GetWithdrawalQuoteParams | GetClaimRewardsQuoteParams;
6427
7156
 
7157
+ interface CustomFeeConfig {
7158
+ recipientAddress: string;
7159
+ value: string;
7160
+ }
7161
+ /**
7162
+ * Data needed to retry a mint that failed after the transfer was
7163
+ * already committed (funds locked).
7164
+ *
7165
+ * Obtain these values from the KitError (TRANSACTION_REVERTED) thrown when
7166
+ * the on-chain mint step fails. The attestation and signature are available
7167
+ * in `error.cause.trace`.
7168
+ */
7169
+ interface RetryMintConfig {
7170
+ /** The attestation hex string returned by the Gateway `/v1/transfer` API. */
7171
+ attestation: string;
7172
+ /** The attestation signature hex string returned by `/v1/transfer`. */
7173
+ signature: string;
7174
+ }
7175
+ interface SpendConfig {
7176
+ customFee?: CustomFeeConfig;
7177
+ /**
7178
+ * When provided, skips the estimate/sign/transfer steps and proceeds
7179
+ * directly to the on-chain mint using a previously obtained attestation.
7180
+ *
7181
+ * Use this to retry a mint that failed due to an RPC or network issue
7182
+ * after the transfer was already committed.
7183
+ *
7184
+ * @remarks
7185
+ * The `useForwarder` flag on the destination is ignored during retry
7186
+ * because the attestation was already issued — the Forwarding Service
7187
+ * is only involved in the initial transfer, not re-mints.
7188
+ */
7189
+ retry?: RetryMintConfig;
7190
+ }
7191
+ interface ResolvedAllocation {
7192
+ amount: string;
7193
+ chain: ChainDefinition;
7194
+ }
7195
+ interface ResolvedSpendSource<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7196
+ adapter: Adapter<TAdapterCapabilities>;
7197
+ allocations: ResolvedAllocation[];
7198
+ address?: string;
7199
+ sourceAccount?: string;
7200
+ }
7201
+ interface ResolvedSpendDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7202
+ adapter?: Adapter<TAdapterCapabilities>;
7203
+ chain: ChainDefinition;
7204
+ recipientAddress?: string;
7205
+ address?: string;
7206
+ useForwarder?: boolean;
7207
+ }
7208
+ interface ResolvedSpendParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7209
+ from: ResolvedSpendSource<TFromAdapterCapabilities>[];
7210
+ to: ResolvedSpendDestination<TToAdapterCapabilities>;
7211
+ token: SupportedToken;
7212
+ config?: SpendConfig;
7213
+ }
7214
+ /**
7215
+ * Function that computes the fee amount (in human-readable units, e.g. "10.5")
7216
+ * given the resolved spend parameters.
7217
+ */
7218
+ type SpendFeeFunction = (params: ResolvedSpendParams) => Promise<string> | string;
7219
+ /**
7220
+ * Function that resolves the fee recipient address for a spend.
7221
+ * Called once per spend, against the resolved **destination** chain —
7222
+ * every fee burn intent in a spend mints to that single chain
7223
+ * regardless of which source chain(s) funded it, so only one
7224
+ * recipient address (valid on the destination chain) is ever needed.
7225
+ */
7226
+ type SpendFeeRecipientFunction = (destinationChain: ChainDefinition, params: ResolvedSpendParams) => Promise<string> | string;
7227
+ /**
7228
+ * Policy for computing and routing custom developer fees.
7229
+ *
7230
+ * **Important:** When the kit invokes `computeFee` and
7231
+ * `resolveFeeRecipientAddress`, the `params` argument may be the
7232
+ * **raw, unresolved** `SpendParams` (cast to `ResolvedSpendParams`).
7233
+ * Fields that only exist after resolution (e.g. per-source allocations)
7234
+ * may be `undefined`. Implementations should only rely on top-level
7235
+ * fields such as `to`, `token`, and `amount`.
7236
+ *
7237
+ * @remarks
7238
+ * `resolveFeeRecipientAddress` is optional when you configure
7239
+ * {@link UnifiedBalanceKit.setFeeRecipients} instead — the declarative
7240
+ * map takes priority over this callback when both are present. Provide
7241
+ * exactly one of the two; a policy with neither throws at spend time.
7242
+ */
7243
+ interface CustomFeePolicy {
7244
+ computeFee: SpendFeeFunction;
7245
+ resolveFeeRecipientAddress?: SpendFeeRecipientFunction;
7246
+ }
7247
+
7248
+ /**
7249
+ * Runtime array of token identifiers supported by the unified-balance-kit.
7250
+ *
7251
+ * @example
7252
+ * ```typescript
7253
+ * import { SUPPORTED_TOKENS } from '@circle-fin/unified-balance-kit'
7254
+ *
7255
+ * if (SUPPORTED_TOKENS.includes('USDC')) {
7256
+ * console.log('USDC is supported')
7257
+ * }
7258
+ * ```
7259
+ */
7260
+ declare const SUPPORTED_TOKENS: readonly ["USDC"];
7261
+ /**
7262
+ * Token identifiers supported by the unified-balance-kit.
7263
+ *
7264
+ * @example
7265
+ * ```typescript
7266
+ * import type { SupportedToken } from '@circle-fin/unified-balance-kit'
7267
+ *
7268
+ * const token: SupportedToken = 'USDC'
7269
+ * ```
7270
+ */
7271
+ type SupportedToken = (typeof SUPPORTED_TOKENS)[number];
7272
+
6428
7273
  /**
6429
7274
  * Operation types that support the `getFee`/`getFeeRecipient` hooks.
6430
7275
  */
@@ -6455,6 +7300,31 @@ interface OperationParamsMap {
6455
7300
  swap: SwapParams;
6456
7301
  earn: EarnOperationParams;
6457
7302
  }
7303
+ /**
7304
+ * Operation-scoped custom fee policies configured at the AppKit level.
7305
+ *
7306
+ * Each property is optional so consumers can enable custom fees only for the
7307
+ * operation they use. AppKit forwards the supplied policy to the matching
7308
+ * underlying kit when that operation runs.
7309
+ *
7310
+ * @example
7311
+ * ```typescript
7312
+ * const policy: AppKitCustomFeePolicy = {
7313
+ * bridge: {
7314
+ * computeFee: () => '1.00',
7315
+ * resolveFeeRecipientAddress: () => '0x1234567890123456789012345678901234567890',
7316
+ * },
7317
+ * }
7318
+ * ```
7319
+ */
7320
+ interface AppKitCustomFeePolicy {
7321
+ /** Custom fee policy forwarded to BridgeKit bridge operations. */
7322
+ bridge?: CustomFeePolicy$2;
7323
+ /** Custom fee policy forwarded to SwapKit swap operations. */
7324
+ swap?: CustomFeePolicy$1;
7325
+ /** Custom fee policy forwarded to UnifiedBalanceKit spend operations. */
7326
+ unifiedBalance?: CustomFeePolicy;
7327
+ }
6458
7328
  /**
6459
7329
  * Context interface for the AppKit with strongly typed getFee method.
6460
7330
  *
@@ -6542,6 +7412,14 @@ interface AppKitContext {
6542
7412
  chain: ChainDefinition;
6543
7413
  params: OperationParamsMap[T];
6544
7414
  }): Promise<string>;
7415
+ /**
7416
+ * Operation-scoped custom fee policies.
7417
+ *
7418
+ * Prefer {@link AppKit.setCustomFeePolicy} for runtime configuration. This
7419
+ * context property is read by the internal kit factories when AppKit creates
7420
+ * BridgeKit and SwapKit instances for each operation.
7421
+ */
7422
+ customFeePolicy?: AppKitCustomFeePolicy;
6545
7423
  /**
6546
7424
  * Event handlers registered for AppKit operations.
6547
7425
  *
@@ -6568,10 +7446,21 @@ interface AppKitContext {
6568
7446
  * ```
6569
7447
  */
6570
7448
  actions: Record<'bridge' | 'earn', Record<string, ((payload: unknown) => void)[]>>;
7449
+ /**
7450
+ * Disable success analytics for the underlying EarnKit, SwapKit, and
7451
+ * UnifiedBalanceKit.
7452
+ *
7453
+ * When `true`, completed earn, swap, and unified balance operations will not
7454
+ * POST analytics events. This does not disable error reporting; use
7455
+ * {@link AppKitContext.disableErrorReporting} for that. Defaults to `false`.
7456
+ *
7457
+ * @defaultValue false
7458
+ */
7459
+ disableAnalytics?: boolean;
6571
7460
  /**
6572
7461
  * Disable error telemetry for all sub-kits.
6573
7462
  *
6574
- * When `true`, none of the underlying kits (BridgeKit, SwapKit,
7463
+ * When `true`, none of the underlying kits (BridgeKit, SwapKit, EarnKit,
6575
7464
  * UnifiedBalanceKit) will POST error details to the telemetry
6576
7465
  * endpoint when operations throw. Defaults to `false` (enabled).
6577
7466
  *