@circle-fin/app-kit 1.11.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.
package/bridge.d.mts CHANGED
@@ -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
  * Machine-readable classification of a {@link BridgeStep} error.
5265
5395
  *
@@ -5753,6 +5883,91 @@ type BridgeDestination<TAdapterCapabilities extends AdapterCapabilities = Adapte
5753
5883
  useForwarder?: boolean;
5754
5884
  }) | ForwarderDestination<TChainIdentifier>;
5755
5885
 
5886
+ type FeeFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
5887
+ type FeeRecipientFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (feePayoutChain: ChainDefinition, params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
5888
+ /**
5889
+ * Custom fee policy for BridgeKit.
5890
+ *
5891
+ * Provides hooks to calculate an absolute custom fee and resolve the fee recipient address
5892
+ * on the source chain. The returned fee is **added on top of the transfer amount** (the wallet signs for
5893
+ * `amount + customFee`). Once collected, the custom fee is split:
5894
+ *
5895
+ * - **10%** automatically routes to Circle.
5896
+ * - **90%** routes to your supplied `recipientAddress`.
5897
+ *
5898
+ * The entire transfer amount still flows through CCTPv2, which then charges its own protocol fee.
5899
+ *
5900
+ * Use `computeFee` (recommended) for human-readable amounts, or `calculateFee` (deprecated)
5901
+ * for smallest-unit amounts. Only one should be provided.
5902
+ *
5903
+ * @example
5904
+ * ```typescript
5905
+ * import type { CustomFeePolicy, BridgeParams } from '@circle-fin/bridge-kit'
5906
+ *
5907
+ * const policy: CustomFeePolicy = {
5908
+ * // computeFee receives human-readable amounts (e.g., '100' for 100 USDC)
5909
+ * computeFee: (params: BridgeParams) => {
5910
+ * const amount = parseFloat(params.amount)
5911
+ *
5912
+ * // 1% fee, capped between 5-50 USDC
5913
+ * const fee = Math.min(Math.max(amount * 0.01, 5), 50)
5914
+ * return fee.toFixed(6)
5915
+ * },
5916
+ * resolveFeeRecipientAddress: (feePayoutChain) =>
5917
+ * feePayoutChain.type === 'solana'
5918
+ * ? 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
5919
+ * : '0x1234567890123456789012345678901234567890',
5920
+ * }
5921
+ * ```
5922
+ */
5923
+ type CustomFeePolicy$2 = {
5924
+ /**
5925
+ * A function that returns the fee to charge for the bridge transfer.
5926
+ * The value returned from the function represents an absolute fee.
5927
+ * The returned fee is **added on top of the transfer amount**. For example, returning
5928
+ * `'5'` (5 USDC) for a 100 USDC transfer causes the wallet to debit 105 USDC total.
5929
+ * CCTPv2 still processes the full 100 USDC transfer amount, while the custom fee is split
5930
+ * 10%/90% between Circle and your fee recipient.
5931
+ *
5932
+ * @example
5933
+ * ```typescript
5934
+ * computeFee: (params) => {
5935
+ * const amount = parseFloat(params.amount)
5936
+ * return (amount * 0.01).toString() // 1% fee
5937
+ * }
5938
+ * ```
5939
+ */
5940
+ computeFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
5941
+ calculateFee?: never;
5942
+ /**
5943
+ * A function that returns the fee recipient for a bridge transfer.
5944
+ * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
5945
+ * The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
5946
+ *
5947
+ * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
5948
+ * because the source chain of the bridge transfer is Ethereum.
5949
+ */
5950
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
5951
+ } | {
5952
+ computeFee?: never;
5953
+ /**
5954
+ * Calculate the fee to charge for the bridge transfer using smallest-unit amounts.
5955
+ *
5956
+ * @deprecated Use `computeFee` instead, which receives human-readable amounts.
5957
+ *
5958
+ * The `params.amount` is in smallest units (e.g., `'100000000'` for 100 USDC).
5959
+ */
5960
+ calculateFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
5961
+ /**
5962
+ * A function that returns the fee recipient for a bridge transfer.
5963
+ * The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
5964
+ * The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
5965
+ *
5966
+ * For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
5967
+ * because the source chain of the bridge transfer is Ethereum.
5968
+ */
5969
+ resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
5970
+ };
5756
5971
  /**
5757
5972
  * Parameters for initiating a cross-chain USDC bridge transfer.
5758
5973
  *
@@ -5857,6 +6072,463 @@ interface BridgeParams<TFromAdapterCapabilities extends AdapterCapabilities = Ad
5857
6072
  invocationMeta?: InvocationMeta;
5858
6073
  }
5859
6074
 
6075
+ /**
6076
+ * Allowance strategy for token approvals during swap operations.
6077
+ *
6078
+ * Defines how token allowances should be granted to the swap contract:
6079
+ * - `permit`: Use EIP-2612 permit signature (gas-efficient, no approval transaction)
6080
+ * - `approve`: Traditional approval transaction
6081
+ *
6082
+ * The default strategy is `permit` with fallback to `approve` if permit is not supported.
6083
+ */
6084
+ type AllowanceStrategy$1 = 'permit' | 'approve';
6085
+ /**
6086
+ * Configuration options for swap operations.
6087
+ *
6088
+ * Controls swap behavior including allowance strategy, slippage tolerance,
6089
+ * minimum output amounts, custom fees, and kit identification.
6090
+ *
6091
+ * @example
6092
+ * ```typescript
6093
+ * import type { ServiceSwapConfig } from '@circle-fin/provider-stablecoin-service-swap'
6094
+ *
6095
+ * // Percentage-based fee
6096
+ * const config: ServiceSwapConfig = {
6097
+ * allowanceStrategy: 'permit',
6098
+ * slippageBps: 300, // 3%
6099
+ * stopLimit: '950000', // Minimum 0.95 USDC output
6100
+ * customFee: {
6101
+ * percentageBps: 1000, // 10% fee
6102
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6103
+ * }
6104
+ * }
6105
+ * ```
6106
+ *
6107
+ * @example
6108
+ * ```typescript
6109
+ * // Absolute amount fee (from callback)
6110
+ * const config: ServiceSwapConfig = {
6111
+ * allowanceStrategy: 'permit',
6112
+ * customFee: {
6113
+ * amount: '10000', // 0.01 USDC fee (absolute)
6114
+ * recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6115
+ * }
6116
+ * }
6117
+ * ```
6118
+ */
6119
+ interface ServiceSwapConfig {
6120
+ /**
6121
+ * Strategy for granting token allowances to the swap contract.
6122
+ *
6123
+ * Defaults to 'permit' with fallback to 'approve'.
6124
+ */
6125
+ allowanceStrategy?: AllowanceStrategy$1;
6126
+ /**
6127
+ * Maximum acceptable slippage in basis points (BPS).
6128
+ *
6129
+ * 1 BPS = 0.01%, so 300 BPS = 3% slippage.
6130
+ * Defaults to 300 BPS (3%).
6131
+ */
6132
+ slippageBps?: number;
6133
+ /**
6134
+ * Minimum acceptable output amount in smallest units (stop-limit).
6135
+ *
6136
+ * If the estimated output falls below this value, the swap will fail.
6137
+ * Expressed as a string to avoid precision issues.
6138
+ */
6139
+ stopLimit?: string;
6140
+ /**
6141
+ * Custom fee configuration for this swap.
6142
+ *
6143
+ * Supports two mutually exclusive approaches:
6144
+ * 1. Percentage-based: Use `percentageBps` field (simple)
6145
+ * 2. Absolute amount: Use `amount` field (from callback)
6146
+ *
6147
+ * If both are set, validation will fail. Transaction-level percentage
6148
+ * takes precedence over kit-level callback policy.
6149
+ */
6150
+ customFee?: {
6151
+ /**
6152
+ * Fee percentage in basis points (NEW).
6153
+ *
6154
+ * 100 bps = 1%, 1000 bps = 10%, 10000 bps = 100%
6155
+ *
6156
+ * Service calculates fee using `estimatedAmount` for same-chain output fees
6157
+ * and the input amount for cross-chain swaps.
6158
+ * Must be greater than 0 and less than or equal to 10000 (maximum 100%).
6159
+ * Mutually exclusive with `amount`.
6160
+ *
6161
+ * @example 1000 // 10% fee
6162
+ */
6163
+ percentageBps?: number;
6164
+ /**
6165
+ * Fee amount in smallest units (for callback results).
6166
+ *
6167
+ * Absolute fee amount calculated by callback function.
6168
+ * Mutually exclusive with `percentageBps`.
6169
+ *
6170
+ * @example '10000' // 0.01 USDC (6 decimals)
6171
+ */
6172
+ amount?: string;
6173
+ /**
6174
+ * Address that will receive the developer's 90% fee share.
6175
+ *
6176
+ * Required whenever a custom fee is submitted to the provider. Optional at
6177
+ * the type level so SDK callback flows can represent partial fee state
6178
+ * before final validation.
6179
+ *
6180
+ * Must be valid on the fee payout chain: source chain for input-side fees
6181
+ * and cross-chain swaps, destination chain for same-chain output-side fees.
6182
+ *
6183
+ * @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6184
+ */
6185
+ recipientAddress?: string;
6186
+ };
6187
+ /**
6188
+ * Stablecoin Service Kit Key used to authenticate service-backed swap
6189
+ * requests.
6190
+ *
6191
+ * Treat this value as a credential. Do not log it, embed it in client-side
6192
+ * source, or expose it in telemetry.
6193
+ */
6194
+ kitKey?: string;
6195
+ /**
6196
+ * DEX aggregator identifier used to source the swap route.
6197
+ *
6198
+ * @example 'lifi', 'paraswap'
6199
+ */
6200
+ provider?: string;
6201
+ /**
6202
+ * Whether to fuse the ERC-20 approval and the swap into a single atomic
6203
+ * batch when the adapter supports it (EIP-5792, or a signing strategy that
6204
+ * declares atomic batching).
6205
+ *
6206
+ * @remarks
6207
+ * Defaults to `true`. When batching is available this collapses the two
6208
+ * sequential transactions of the on-chain approval path into one atomic
6209
+ * submission — a single signing challenge for a smart-contract wallet. Set
6210
+ * to `false` to force the sequential approve-then-swap path. Has no effect on
6211
+ * the gasless permit path (already a single transaction) or on native-token
6212
+ * swaps (no approval needed).
6213
+ *
6214
+ * The batch path relies on the wallet's own gas estimation for the swap call:
6215
+ * the service-provided gas floor and pre-flight simulation that the sequential
6216
+ * path applies are not conveyed through the batch. For a complex/multi-hop
6217
+ * swap whose wallet-side estimate under-shoots, this can out-of-gas-revert the
6218
+ * atomic batch where the sequential path would succeed — set `false` to fall
6219
+ * back to the service-floored sequential path if you hit this.
6220
+ *
6221
+ * @defaultValue true
6222
+ */
6223
+ batchTransactions?: boolean;
6224
+ }
6225
+ /**
6226
+ * Parameters for initiating a swap operation through the Stablecoin Service.
6227
+ *
6228
+ * This type is used as the primary input to provider swap operations, allowing users to specify
6229
+ * the source context, input/output tokens, swap amount, destination address, and optional configuration.
6230
+ *
6231
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
6232
+ *
6233
+ * @example
6234
+ * ```typescript
6235
+ * import type { ServiceSwapParams } from '@circle-fin/provider-stablecoin-service-swap'
6236
+ * import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
6237
+ * import { Ethereum } from '@core/chains'
6238
+ *
6239
+ * const adapter = createAdapterFromPrivateKey({
6240
+ * privateKey: process.env.PRIVATE_KEY,
6241
+ * })
6242
+ *
6243
+ * const params: ServiceSwapParams = {
6244
+ * from: { adapter, chain: Ethereum },
6245
+ * tokenIn: 'USDC', // Alias resolves to chain-specific address
6246
+ * tokenOut: 'USDT', // Alias resolves to chain-specific address
6247
+ * amountIn: '100500000', // 100.50 USDC in base units
6248
+ * to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
6249
+ * config: {
6250
+ * slippageBps: 300, // 3% slippage
6251
+ * allowanceStrategy: 'permit'
6252
+ * }
6253
+ * }
6254
+ * ```
6255
+ */
6256
+ interface ServiceSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
6257
+ /**
6258
+ * The chain definition type to use for the wallet context.
6259
+ *
6260
+ * @defaultValue ChainDefinition
6261
+ */
6262
+ TChainDefinition extends ChainDefinition = ChainDefinition> {
6263
+ /**
6264
+ * The source adapter context (wallet and chain) for the swap.
6265
+ */
6266
+ from: WalletContext<TFromAdapterCapabilities, TChainDefinition>;
6267
+ /**
6268
+ * The input token address or alias to swap from.
6269
+ *
6270
+ * **Supported formats:**
6271
+ * - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
6272
+ * - EVM address: `'0x'` prefixed hex (e.g., `'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'`)
6273
+ * - Solana address: Base58-encoded (e.g., `'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'`)
6274
+ *
6275
+ * Token aliases are automatically resolved to the chain-specific contract address.
6276
+ *
6277
+ * @example 'USDC' // Recommended: use alias
6278
+ * @example '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // Or full address
6279
+ */
6280
+ tokenIn: string;
6281
+ /**
6282
+ * The output token address or alias to swap to.
6283
+ *
6284
+ * **Supported formats:**
6285
+ * - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
6286
+ * - EVM address: `'0x'` prefixed hex (e.g., `'0xdAC17F958D2ee523a2206206994597C13D831ec7'`)
6287
+ * - Solana address: Base58-encoded (e.g., `'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'`)
6288
+ *
6289
+ * Token aliases are automatically resolved to the chain-specific contract address.
6290
+ *
6291
+ * @example 'USDT' // Recommended: use alias
6292
+ * @example '0xdAC17F958D2ee523a2206206994597C13D831ec7' // Or full address
6293
+ */
6294
+ tokenOut: string;
6295
+ /**
6296
+ * The amount of input token to swap in base units.
6297
+ *
6298
+ * SwapKit converts human-readable amounts to base units before passing to the provider.
6299
+ *
6300
+ * @example '100500000' for 100.50 USDC (6 decimals)
6301
+ */
6302
+ amountIn: string;
6303
+ /**
6304
+ * The destination address where the swapped tokens will be sent.
6305
+ *
6306
+ * @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6307
+ */
6308
+ to: string;
6309
+ /**
6310
+ * Optional destination chain for cross-chain swaps.
6311
+ *
6312
+ * Defaults to `from.chain` for same-chain swaps.
6313
+ */
6314
+ toChain?: TChainDefinition;
6315
+ /**
6316
+ * Optional configuration for swap behavior.
6317
+ *
6318
+ * If omitted, defaults will be used:
6319
+ * - allowanceStrategy: 'permit' (fallback to 'approve')
6320
+ * - slippageBps: 300 (3%)
6321
+ */
6322
+ config?: ServiceSwapConfig;
6323
+ }
6324
+
6325
+ /**
6326
+ * Fee context when fee is taken from INPUT token.
6327
+ *
6328
+ * Used for swaps where the fee is collected from the input token, including
6329
+ * all cross-chain swaps.
6330
+ * Extends the resolved swap parameters with a discriminator to indicate input fee scenario.
6331
+ *
6332
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6333
+ *
6334
+ * @example
6335
+ * ```typescript
6336
+ * // USDC → RandomToken swap (fee from input)
6337
+ * const context: SwapInputFeeContext = {
6338
+ * type: 'input',
6339
+ * from: {
6340
+ * adapter: viemAdapter,
6341
+ * chain: Ethereum,
6342
+ * address: '0x...'
6343
+ * },
6344
+ * tokenIn: 'USDC',
6345
+ * tokenOut: 'RandomToken',
6346
+ * amountIn: '100000000', // 100 USDC in base units
6347
+ * to: '0x...'
6348
+ * }
6349
+ * ```
6350
+ */
6351
+ interface SwapInputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
6352
+ /**
6353
+ * Fee source discriminator - input token.
6354
+ */
6355
+ type: 'input';
6356
+ }
6357
+ /**
6358
+ * Fee context when fee is taken from OUTPUT token.
6359
+ *
6360
+ * Used for swaps where the output token is supported for fee collection.
6361
+ * Extends the resolved swap parameters with output amounts and discriminator.
6362
+ *
6363
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6364
+ *
6365
+ * @remarks
6366
+ * If using `estimatedAmount` in callback and quote cache expires,
6367
+ * calculated fee may not match fresh quote. Use `minAmount` for
6368
+ * predictability at the cost of potentially lower fees.
6369
+ *
6370
+ * @example
6371
+ * ```typescript
6372
+ * // RandomToken → USDC swap (fee from output)
6373
+ * const context: SwapOutputFeeContext = {
6374
+ * type: 'output',
6375
+ * from: {
6376
+ * adapter: viemAdapter,
6377
+ * chain: Ethereum,
6378
+ * address: '0x...'
6379
+ * },
6380
+ * tokenIn: 'RandomToken',
6381
+ * tokenOut: 'USDC',
6382
+ * amountIn: '100000000',
6383
+ * to: '0x...',
6384
+ * minAmount: '50000000', // 50 USDC guaranteed minimum
6385
+ * estimatedAmount: '55000000' // 55 USDC expected output
6386
+ * }
6387
+ * ```
6388
+ */
6389
+ interface SwapOutputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
6390
+ /**
6391
+ * Fee source discriminator - output token.
6392
+ */
6393
+ type: 'output';
6394
+ /**
6395
+ * Guaranteed minimum output amount in base units.
6396
+ *
6397
+ * More stable but lower than estimatedAmount. Use this for
6398
+ * predictable fee calculations.
6399
+ */
6400
+ minAmount: string;
6401
+ /**
6402
+ * Estimated output amount in base units.
6403
+ *
6404
+ * Expected output based on current market conditions. May be
6405
+ * higher than minAmount. Subject to change if quote expires.
6406
+ */
6407
+ estimatedAmount: string;
6408
+ }
6409
+ /**
6410
+ * Discriminated union for swap fee contexts.
6411
+ *
6412
+ * Provides different context based on whether fee is from input or output token.
6413
+ * Discriminated by the `type` field: 'input' for fees from input token, 'output' for output token.
6414
+ *
6415
+ * Includes full swap parameters (adapter, chain, tokens, amounts) for maximum flexibility
6416
+ * in fee calculation logic.
6417
+ *
6418
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6419
+ */
6420
+ type SwapFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = SwapInputFeeContext<TFromAdapterCapabilities> | SwapOutputFeeContext<TFromAdapterCapabilities>;
6421
+ /**
6422
+ * Custom fee policy for SwapKit (callback-based approach).
6423
+ *
6424
+ * Provides hooks to calculate an absolute fee amount and resolve the fee
6425
+ * recipient address. The callback receives a discriminated context with
6426
+ * different fields based on operation type (bridge vs swap) and fee source
6427
+ * (input vs output).
6428
+ *
6429
+ * @remarks
6430
+ * This is mutually exclusive with transaction-level percentage fees.
6431
+ * If both are set, the transaction-level percentage takes precedence.
6432
+ *
6433
+ * The callback approach makes two API calls for same-chain output fees:
6434
+ * 1. GET /quote - retrieve fee context and quote
6435
+ * 2. POST /swap - execute with calculated fee
6436
+ *
6437
+ * Cross-chain swaps always use input fees on the source chain, so callbacks
6438
+ * receive `type: 'input'` for those routes.
6439
+ *
6440
+ * @example
6441
+ * ```typescript
6442
+ * import type { CustomFeePolicy } from '@circle-fin/swap-kit'
6443
+ *
6444
+ * const policy: CustomFeePolicy = {
6445
+ * computeFee: async (ctx) => {
6446
+ * // Discriminate by fee source (input vs output)
6447
+ * if (ctx.type === 'input') {
6448
+ * // Simple percentage for input fees
6449
+ * return (parseFloat(ctx.amountIn) * 0.1).toString()
6450
+ * } else {
6451
+ * // Complex logic for output fees (VIP tiers, etc.)
6452
+ * const user = await database.getUser(...)
6453
+ * if (user.isVIP) {
6454
+ * return (parseFloat(ctx.minAmount) * 0.05).toString()
6455
+ * }
6456
+ * return (parseFloat(ctx.estimatedAmount) * 0.1).toString()
6457
+ * }
6458
+ * },
6459
+ * resolveFeeRecipientAddress: (chain) => {
6460
+ * return chain.type === 'solana'
6461
+ * ? 'SolanaAddress...'
6462
+ * : '0xEVMAddress...'
6463
+ * },
6464
+ * }
6465
+ * ```
6466
+ */
6467
+ interface CustomFeePolicy$1 {
6468
+ /**
6469
+ * Calculate custom fee amount based on swap context.
6470
+ *
6471
+ * Receives full swap parameters including adapter, chain, tokens, and amounts.
6472
+ * Context is discriminated by `type` field:
6473
+ * - 'input': Fee from input token (OK → Any swaps and all cross-chain swaps)
6474
+ * - 'output': Fee from output token (same-chain Any → OK swaps), includes minAmount and estimatedAmount
6475
+ *
6476
+ * The wrapper automatically converts amounts to/from base units, so your
6477
+ * callback works with human-readable numbers (e.g., '0.1' for 0.1 USDC).
6478
+ *
6479
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
6480
+ * @param context - Discriminated swap fee context with full swap parameters
6481
+ * @returns Absolute fee amount as string in human-readable format
6482
+ *
6483
+ * @example
6484
+ * ```typescript
6485
+ * computeFee: async (ctx) => {
6486
+ * if (ctx.type === 'output') {
6487
+ * // Output fee scenario
6488
+ * // Use estimatedAmount or minAmount for calculation
6489
+ * return (parseFloat(ctx.estimatedAmount) * 0.01).toString()
6490
+ * }
6491
+ * // Input fee scenario
6492
+ * return (parseFloat(ctx.amountIn) * 0.01).toString()
6493
+ * }
6494
+ * ```
6495
+ *
6496
+ * @example
6497
+ * ```typescript
6498
+ * computeFee: async (ctx) => {
6499
+ * if (ctx.type === 'output') {
6500
+ * // Use minAmount for predictable fees
6501
+ * return (parseFloat(ctx.minAmount) * 0.01).toString()
6502
+ * }
6503
+ * return (parseFloat(ctx.amountIn) * 0.01).toString()
6504
+ * }
6505
+ * ```
6506
+ */
6507
+ computeFee: <TFromAdapterCapabilities extends AdapterCapabilities>(context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
6508
+ /**
6509
+ * Resolve fee recipient address for the chain where fee is collected.
6510
+ *
6511
+ * Called with the chain where fee will be paid. For cross-chain swaps this
6512
+ * is always the source chain. Must return a valid address format for that
6513
+ * chain type (EVM or Solana).
6514
+ *
6515
+ * @param feePayoutChain - Chain definition where fee is collected
6516
+ * @param context - The swap fee context with full parameters
6517
+ * @returns Fee recipient address for the chain
6518
+ *
6519
+ * @example
6520
+ * ```typescript
6521
+ * resolveFeeRecipientAddress: (chain, ctx) => {
6522
+ * // Chain-based routing
6523
+ * if (chain.type === 'solana') {
6524
+ * return 'SolanaAddress...'
6525
+ * }
6526
+ * return '0xEVMAddress...'
6527
+ * }
6528
+ * ```
6529
+ */
6530
+ resolveFeeRecipientAddress: <TFromAdapterCapabilities extends AdapterCapabilities>(feePayoutChain: ChainDefinition, context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
6531
+ }
5860
6532
  /**
5861
6533
  * Adapter context constrained to swap-supported chains.
5862
6534
  */
@@ -6004,6 +6676,45 @@ interface SwapConfig {
6004
6676
  */
6005
6677
  kitKey?: string;
6006
6678
  }
6679
+ /**
6680
+ * Resolved parameters for swap operations after validation and normalization.
6681
+ *
6682
+ * Internal type used by SwapKit operations after `resolveSwapParams()` has:
6683
+ * - Validated the input parameters
6684
+ * - Resolved chain identifiers to full ChainDefinition objects
6685
+ * - Extracted and validated wallet addresses
6686
+ *
6687
+ * Note: Raw user input is validated first, then `tokenIn` and `tokenOut` may
6688
+ * be canonicalized for downstream routing (for example, Arc Testnet
6689
+ * `NATIVE` → `USDC`). Address resolution is handled by the provider layer.
6690
+ *
6691
+ * This type is consumed by swap providers and internal operations but is not
6692
+ * exposed to end users. It extends ServiceSwapParams which is the format expected
6693
+ * by the StablecoinServiceSwapProvider.
6694
+ *
6695
+ * @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
6696
+ *
6697
+ * @example
6698
+ * ```typescript
6699
+ * // After resolution, SwapParams becomes ResolvedSwapParams:
6700
+ * const resolved: ResolvedSwapParams = {
6701
+ * from: {
6702
+ * adapter: viemAdapter,
6703
+ * chain: Ethereum, // Full chain definition
6704
+ * address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
6705
+ * },
6706
+ * tokenIn: 'USDC', // Canonicalized for provider routing
6707
+ * tokenOut: 'USDT', // Canonicalized for provider routing
6708
+ * amountIn: '100500000', // Converted to base units (100.5 USDC with 6 decimals)
6709
+ * to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
6710
+ * config: {
6711
+ * slippageBps: 300,
6712
+ * allowanceStrategy: 'permit'
6713
+ * }
6714
+ * }
6715
+ * ```
6716
+ */
6717
+ type ResolvedSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = ServiceSwapParams<TFromAdapterCapabilities>;
6007
6718
  interface SwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
6008
6719
  /**
6009
6720
  * The source adapter context (wallet and chain) for the swap.
@@ -6116,6 +6827,24 @@ interface EarnConfig {
6116
6827
  * Format: `KIT_KEY:<keyId>:<keySecret>`
6117
6828
  */
6118
6829
  readonly kitKey?: string | undefined;
6830
+ /**
6831
+ * Optional base URL override for the Earn Service API.
6832
+ *
6833
+ * Defaults to `https://api.circle.com` when omitted. Override for testing
6834
+ * against staging or local environments.
6835
+ */
6836
+ readonly baseUrl?: string | undefined;
6837
+ /**
6838
+ * Enable or disable atomic batched transaction execution.
6839
+ *
6840
+ * When `true` (or `undefined` / omitted), same-chain deposit and withdraw
6841
+ * bundle the approve and execute calls into one adapter-native atomic batch
6842
+ * when the connected wallet supports it. Set to `false` to force the
6843
+ * sequential approve → execute flow.
6844
+ *
6845
+ * @defaultValue `undefined` (batching attempted when the wallet supports it)
6846
+ */
6847
+ readonly batchTransactions?: boolean | undefined;
6119
6848
  }
6120
6849
  /**
6121
6850
  * Parameters for fetching vault information.
@@ -6548,6 +7277,122 @@ interface GetClaimRewardsQuoteParams<TFromAdapterCapabilities extends AdapterCap
6548
7277
  */
6549
7278
  type EarnOperationParams = AnyDepositParams | WithdrawParams | ClaimRewardsParams | GetVaultsParams | ExploreVaultsParams | ExploreVaultsIteratorParams | GetPositionParams | GetDepositQuoteParams | GetWithdrawalQuoteParams | GetClaimRewardsQuoteParams;
6550
7279
 
7280
+ interface CustomFeeConfig {
7281
+ recipientAddress: string;
7282
+ value: string;
7283
+ }
7284
+ /**
7285
+ * Data needed to retry a mint that failed after the transfer was
7286
+ * already committed (funds locked).
7287
+ *
7288
+ * Obtain these values from the KitError (TRANSACTION_REVERTED) thrown when
7289
+ * the on-chain mint step fails. The attestation and signature are available
7290
+ * in `error.cause.trace`.
7291
+ */
7292
+ interface RetryMintConfig {
7293
+ /** The attestation hex string returned by the Gateway `/v1/transfer` API. */
7294
+ attestation: string;
7295
+ /** The attestation signature hex string returned by `/v1/transfer`. */
7296
+ signature: string;
7297
+ }
7298
+ interface SpendConfig {
7299
+ customFee?: CustomFeeConfig;
7300
+ /**
7301
+ * When provided, skips the estimate/sign/transfer steps and proceeds
7302
+ * directly to the on-chain mint using a previously obtained attestation.
7303
+ *
7304
+ * Use this to retry a mint that failed due to an RPC or network issue
7305
+ * after the transfer was already committed.
7306
+ *
7307
+ * @remarks
7308
+ * The `useForwarder` flag on the destination is ignored during retry
7309
+ * because the attestation was already issued — the Forwarding Service
7310
+ * is only involved in the initial transfer, not re-mints.
7311
+ */
7312
+ retry?: RetryMintConfig;
7313
+ }
7314
+ interface ResolvedAllocation {
7315
+ amount: string;
7316
+ chain: ChainDefinition;
7317
+ }
7318
+ interface ResolvedSpendSource<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7319
+ adapter: Adapter<TAdapterCapabilities>;
7320
+ allocations: ResolvedAllocation[];
7321
+ address?: string;
7322
+ sourceAccount?: string;
7323
+ }
7324
+ interface ResolvedSpendDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7325
+ adapter?: Adapter<TAdapterCapabilities>;
7326
+ chain: ChainDefinition;
7327
+ recipientAddress?: string;
7328
+ address?: string;
7329
+ useForwarder?: boolean;
7330
+ }
7331
+ interface ResolvedSpendParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
7332
+ from: ResolvedSpendSource<TFromAdapterCapabilities>[];
7333
+ to: ResolvedSpendDestination<TToAdapterCapabilities>;
7334
+ token: SupportedToken;
7335
+ config?: SpendConfig;
7336
+ }
7337
+ /**
7338
+ * Function that computes the fee amount (in human-readable units, e.g. "10.5")
7339
+ * given the resolved spend parameters.
7340
+ */
7341
+ type SpendFeeFunction = (params: ResolvedSpendParams) => Promise<string> | string;
7342
+ /**
7343
+ * Function that resolves the fee recipient address for a spend.
7344
+ * Called once per spend, against the resolved **destination** chain —
7345
+ * every fee burn intent in a spend mints to that single chain
7346
+ * regardless of which source chain(s) funded it, so only one
7347
+ * recipient address (valid on the destination chain) is ever needed.
7348
+ */
7349
+ type SpendFeeRecipientFunction = (destinationChain: ChainDefinition, params: ResolvedSpendParams) => Promise<string> | string;
7350
+ /**
7351
+ * Policy for computing and routing custom developer fees.
7352
+ *
7353
+ * **Important:** When the kit invokes `computeFee` and
7354
+ * `resolveFeeRecipientAddress`, the `params` argument may be the
7355
+ * **raw, unresolved** `SpendParams` (cast to `ResolvedSpendParams`).
7356
+ * Fields that only exist after resolution (e.g. per-source allocations)
7357
+ * may be `undefined`. Implementations should only rely on top-level
7358
+ * fields such as `to`, `token`, and `amount`.
7359
+ *
7360
+ * @remarks
7361
+ * `resolveFeeRecipientAddress` is optional when you configure
7362
+ * {@link UnifiedBalanceKit.setFeeRecipients} instead — the declarative
7363
+ * map takes priority over this callback when both are present. Provide
7364
+ * exactly one of the two; a policy with neither throws at spend time.
7365
+ */
7366
+ interface CustomFeePolicy {
7367
+ computeFee: SpendFeeFunction;
7368
+ resolveFeeRecipientAddress?: SpendFeeRecipientFunction;
7369
+ }
7370
+
7371
+ /**
7372
+ * Runtime array of token identifiers supported by the unified-balance-kit.
7373
+ *
7374
+ * @example
7375
+ * ```typescript
7376
+ * import { SUPPORTED_TOKENS } from '@circle-fin/unified-balance-kit'
7377
+ *
7378
+ * if (SUPPORTED_TOKENS.includes('USDC')) {
7379
+ * console.log('USDC is supported')
7380
+ * }
7381
+ * ```
7382
+ */
7383
+ declare const SUPPORTED_TOKENS: readonly ["USDC"];
7384
+ /**
7385
+ * Token identifiers supported by the unified-balance-kit.
7386
+ *
7387
+ * @example
7388
+ * ```typescript
7389
+ * import type { SupportedToken } from '@circle-fin/unified-balance-kit'
7390
+ *
7391
+ * const token: SupportedToken = 'USDC'
7392
+ * ```
7393
+ */
7394
+ type SupportedToken = (typeof SUPPORTED_TOKENS)[number];
7395
+
6551
7396
  /**
6552
7397
  * Operation types that support the `getFee`/`getFeeRecipient` hooks.
6553
7398
  */
@@ -6578,6 +7423,31 @@ interface OperationParamsMap {
6578
7423
  swap: SwapParams;
6579
7424
  earn: EarnOperationParams;
6580
7425
  }
7426
+ /**
7427
+ * Operation-scoped custom fee policies configured at the AppKit level.
7428
+ *
7429
+ * Each property is optional so consumers can enable custom fees only for the
7430
+ * operation they use. AppKit forwards the supplied policy to the matching
7431
+ * underlying kit when that operation runs.
7432
+ *
7433
+ * @example
7434
+ * ```typescript
7435
+ * const policy: AppKitCustomFeePolicy = {
7436
+ * bridge: {
7437
+ * computeFee: () => '1.00',
7438
+ * resolveFeeRecipientAddress: () => '0x1234567890123456789012345678901234567890',
7439
+ * },
7440
+ * }
7441
+ * ```
7442
+ */
7443
+ interface AppKitCustomFeePolicy {
7444
+ /** Custom fee policy forwarded to BridgeKit bridge operations. */
7445
+ bridge?: CustomFeePolicy$2;
7446
+ /** Custom fee policy forwarded to SwapKit swap operations. */
7447
+ swap?: CustomFeePolicy$1;
7448
+ /** Custom fee policy forwarded to UnifiedBalanceKit spend operations. */
7449
+ unifiedBalance?: CustomFeePolicy;
7450
+ }
6581
7451
  /**
6582
7452
  * Context interface for the AppKit with strongly typed getFee method.
6583
7453
  *
@@ -6665,6 +7535,14 @@ interface AppKitContext {
6665
7535
  chain: ChainDefinition;
6666
7536
  params: OperationParamsMap[T];
6667
7537
  }): Promise<string>;
7538
+ /**
7539
+ * Operation-scoped custom fee policies.
7540
+ *
7541
+ * Prefer {@link AppKit.setCustomFeePolicy} for runtime configuration. This
7542
+ * context property is read by the internal kit factories when AppKit creates
7543
+ * BridgeKit and SwapKit instances for each operation.
7544
+ */
7545
+ customFeePolicy?: AppKitCustomFeePolicy;
6668
7546
  /**
6669
7547
  * Event handlers registered for AppKit operations.
6670
7548
  *