@circle-fin/app-kit 1.11.0 → 1.12.1
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/CHANGELOG.md +53 -0
- package/README.md +56 -25
- package/bridge.cjs +1696 -1348
- package/bridge.d.cts +979 -2
- package/bridge.d.mts +979 -2
- package/bridge.d.ts +979 -2
- package/bridge.mjs +1696 -1348
- package/chains.cjs +106 -1
- package/chains.d.cts +96 -2
- package/chains.d.mts +96 -2
- package/chains.d.ts +96 -2
- package/chains.mjs +105 -2
- package/context.d.cts +978 -1
- package/context.d.mts +978 -1
- package/context.d.ts +978 -1
- package/earn.cjs +1728 -65
- package/earn.d.cts +978 -1
- package/earn.d.mts +978 -1
- package/earn.d.ts +978 -1
- package/earn.mjs +1728 -65
- package/estimateBridge.cjs +1695 -1347
- package/estimateBridge.d.cts +978 -1
- package/estimateBridge.d.mts +978 -1
- package/estimateBridge.d.ts +978 -1
- package/estimateBridge.mjs +1695 -1347
- package/estimateSwap.cjs +312 -17
- package/estimateSwap.d.cts +977 -1
- package/estimateSwap.d.mts +977 -1
- package/estimateSwap.d.ts +977 -1
- package/estimateSwap.mjs +312 -17
- package/index.cjs +3608 -1603
- package/index.d.cts +4181 -3426
- package/index.d.mts +4181 -3426
- package/index.d.ts +4181 -3426
- package/index.mjs +3607 -1604
- package/package.json +6 -6
- package/swap.cjs +312 -17
- package/swap.d.cts +977 -1
- package/swap.d.mts +977 -1
- package/swap.d.ts +977 -1
- package/swap.mjs +312 -17
- package/unifiedBalance.cjs +436 -122
- package/unifiedBalance.d.cts +132 -31
- package/unifiedBalance.d.mts +132 -31
- package/unifiedBalance.d.ts +132 -31
- package/unifiedBalance.mjs +436 -122
package/earn.d.cts
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.
|
|
@@ -2953,6 +2957,18 @@ interface TokenActionMap {
|
|
|
2953
2957
|
*/
|
|
2954
2958
|
walletAddress?: string | undefined;
|
|
2955
2959
|
};
|
|
2960
|
+
/**
|
|
2961
|
+
* Get the on-chain name of the token contract.
|
|
2962
|
+
*
|
|
2963
|
+
* This is a read-only operation. For USDC the value is also the EIP-712
|
|
2964
|
+
* domain name, which permit and authorize signing flows need.
|
|
2965
|
+
*/
|
|
2966
|
+
name: ActionParameters & {
|
|
2967
|
+
/**
|
|
2968
|
+
* The contract address of the token.
|
|
2969
|
+
*/
|
|
2970
|
+
tokenAddress: string;
|
|
2971
|
+
};
|
|
2956
2972
|
}
|
|
2957
2973
|
|
|
2958
2974
|
/**
|
|
@@ -3782,6 +3798,30 @@ declare class ActionRegistry {
|
|
|
3782
3798
|
executeAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, context: ResolvedOperationContext): Promise<PreparedChainRequest>;
|
|
3783
3799
|
}
|
|
3784
3800
|
|
|
3801
|
+
/**
|
|
3802
|
+
* Canonical list of actions that do not prepare or submit transactions.
|
|
3803
|
+
*
|
|
3804
|
+
* @internal
|
|
3805
|
+
*/
|
|
3806
|
+
declare const READ_ACTION_KEYS: readonly ["token.allowance", "token.balanceOf", "token.name", "native.balanceOf", "usdc.allowance", "usdc.balanceOf", "usdc.name", "gateway.v1.isDelegate", "gateway.v1.withdrawingBalance", "gateway.v1.withdrawalBlock", "gateway.v1.signBurnIntents"];
|
|
3807
|
+
/**
|
|
3808
|
+
* Action keys that execute without preparing or submitting a transaction.
|
|
3809
|
+
*
|
|
3810
|
+
* @remarks
|
|
3811
|
+
* Derive this type from the canonical runtime list so compile-time and runtime
|
|
3812
|
+
* classification cannot drift. `gateway.v1.signBurnIntents` is included
|
|
3813
|
+
* because the action system models off-chain signing as a read action: it does
|
|
3814
|
+
* not prepare a chain request.
|
|
3815
|
+
*
|
|
3816
|
+
* @example
|
|
3817
|
+
* ```typescript
|
|
3818
|
+
* import type { ReadActionKey } from '@core/adapter'
|
|
3819
|
+
*
|
|
3820
|
+
* const action: ReadActionKey = 'token.allowance'
|
|
3821
|
+
* ```
|
|
3822
|
+
*/
|
|
3823
|
+
type ReadActionKey = (typeof READ_ACTION_KEYS)[number];
|
|
3824
|
+
|
|
3785
3825
|
/**
|
|
3786
3826
|
* Defines the capabilities of an adapter, including address handling patterns and supported chains.
|
|
3787
3827
|
*
|
|
@@ -3950,6 +3990,69 @@ declare abstract class Adapter<TAdapterCapabilities extends AdapterCapabilities
|
|
|
3950
3990
|
* ```
|
|
3951
3991
|
*/
|
|
3952
3992
|
prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<PreparedChainRequest>;
|
|
3993
|
+
/**
|
|
3994
|
+
* Execute a non-transaction action without routing through transaction preparation.
|
|
3995
|
+
*
|
|
3996
|
+
* @remarks
|
|
3997
|
+
* Use this seam for balance, allowance, contract-state, and other actions
|
|
3998
|
+
* classified as reads. It never calls {@link Adapter.prepareAction}, so
|
|
3999
|
+
* transaction authorization wrappers only observe actions that can produce a
|
|
4000
|
+
* signable chain request.
|
|
4001
|
+
*
|
|
4002
|
+
* @typeParam TActionKey - The read action key.
|
|
4003
|
+
* @param action - The read action to execute.
|
|
4004
|
+
* @param params - The parameters for the read action.
|
|
4005
|
+
* @param ctx - The operation context.
|
|
4006
|
+
* @returns The raw action response.
|
|
4007
|
+
* @throws {KitError} When the key is not a read action or no handler is registered.
|
|
4008
|
+
* @throws Error When the operation context or action handler fails.
|
|
4009
|
+
*
|
|
4010
|
+
* @example
|
|
4011
|
+
* ```typescript
|
|
4012
|
+
* import { Ethereum } from '@core/chains'
|
|
4013
|
+
*
|
|
4014
|
+
* const balance = await adapter.readAction(
|
|
4015
|
+
* 'token.balanceOf',
|
|
4016
|
+
* { tokenAddress, walletAddress },
|
|
4017
|
+
* { chain: Ethereum },
|
|
4018
|
+
* )
|
|
4019
|
+
* ```
|
|
4020
|
+
*
|
|
4021
|
+
* @internal
|
|
4022
|
+
*/
|
|
4023
|
+
readAction<TActionKey extends ReadActionKey>(action: TActionKey, params: ActionPayload<TActionKey>, ctx: OperationContext<TAdapterCapabilities>): Promise<unknown>;
|
|
4024
|
+
/**
|
|
4025
|
+
* Read the current token allowance a delegate holds over an owner's tokens.
|
|
4026
|
+
*
|
|
4027
|
+
* @remarks
|
|
4028
|
+
* Perform a network read through {@link Adapter.readAction}. This method
|
|
4029
|
+
* never routes through {@link Adapter.prepareAction}. On chains without an
|
|
4030
|
+
* allowance model, such as Solana, return the maximum uint256 value.
|
|
4031
|
+
*
|
|
4032
|
+
* @param params - The token to query and the delegate whose allowance is being read.
|
|
4033
|
+
* @param ctx - Operation context with compile-time validated address requirements.
|
|
4034
|
+
* @returns A promise resolving to the current allowance in the token's base units.
|
|
4035
|
+
* @throws {KitError} When the adapter does not register a `token.allowance` handler.
|
|
4036
|
+
* @throws Error When the operation context or action handler fails.
|
|
4037
|
+
*
|
|
4038
|
+
* @example
|
|
4039
|
+
* ```typescript
|
|
4040
|
+
* import type { Adapter } from '@core/adapter'
|
|
4041
|
+
* import { Ethereum } from '@core/chains'
|
|
4042
|
+
*
|
|
4043
|
+
* declare const adapter: Adapter
|
|
4044
|
+
*
|
|
4045
|
+
* const allowance = await adapter.getTokenAllowance(
|
|
4046
|
+
* {
|
|
4047
|
+
* tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
4048
|
+
* delegate: '0x1111111111111111111111111111111111111111',
|
|
4049
|
+
* },
|
|
4050
|
+
* { chain: Ethereum },
|
|
4051
|
+
* )
|
|
4052
|
+
* console.log(allowance) // 1000000n
|
|
4053
|
+
* ```
|
|
4054
|
+
*/
|
|
4055
|
+
getTokenAllowance(params: ActionPayload<'token.allowance'>, ctx: OperationContext<TAdapterCapabilities>): Promise<bigint>;
|
|
3953
4056
|
/**
|
|
3954
4057
|
* Prepares a transaction for future gas estimation and execution.
|
|
3955
4058
|
*
|
|
@@ -5260,6 +5363,132 @@ declare enum TransferSpeed {
|
|
|
5260
5363
|
/** Standard burn mode - normal transfer time with standard fees */
|
|
5261
5364
|
SLOW = "SLOW"
|
|
5262
5365
|
}
|
|
5366
|
+
/**
|
|
5367
|
+
* Context object representing a wallet and signing authority on a specific blockchain network.
|
|
5368
|
+
*
|
|
5369
|
+
* Combines a wallet or contract address, the blockchain it resides on, and the adapter (signer)
|
|
5370
|
+
* responsible for authorizing transactions. Used to specify the source or destination in cross-chain
|
|
5371
|
+
* transfer operations.
|
|
5372
|
+
*
|
|
5373
|
+
* @remarks
|
|
5374
|
+
* The `adapter` (signer) and `address` do not always have to belong to the same entity. For example,
|
|
5375
|
+
* in minting or withdrawal scenarios, the signing adapter may authorize a transaction that credits
|
|
5376
|
+
* funds to a different recipient address. This context is essential for cross-chain operations,
|
|
5377
|
+
* ensuring that both the address and the associated adapter are correctly paired with the intended
|
|
5378
|
+
* blockchain, but not necessarily with each other.
|
|
5379
|
+
*
|
|
5380
|
+
* @example
|
|
5381
|
+
* ```typescript
|
|
5382
|
+
* import type { WalletContext } from '@core/provider'
|
|
5383
|
+
* import { adapter, blockchain } from './setup'
|
|
5384
|
+
*
|
|
5385
|
+
* const wallet: WalletContext = {
|
|
5386
|
+
* adapter,
|
|
5387
|
+
* address: '0x1234...abcd',
|
|
5388
|
+
* chain: blockchain,
|
|
5389
|
+
* }
|
|
5390
|
+
* ```
|
|
5391
|
+
*/
|
|
5392
|
+
interface WalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
|
|
5393
|
+
/**
|
|
5394
|
+
* The chain definition type to use for the wallet context.
|
|
5395
|
+
*
|
|
5396
|
+
* @defaultValue ChainDefinition
|
|
5397
|
+
*/
|
|
5398
|
+
TChainDefinition extends ChainDefinition = ChainDefinition> {
|
|
5399
|
+
/**
|
|
5400
|
+
* The adapter (signer) for the wallet on the specified chain.
|
|
5401
|
+
*
|
|
5402
|
+
* Responsible for authorizing transactions and signing messages on behalf of the wallet or
|
|
5403
|
+
* for a different recipient, depending on the use case.
|
|
5404
|
+
*/
|
|
5405
|
+
adapter: Adapter<TAdapterCapabilities>;
|
|
5406
|
+
/**
|
|
5407
|
+
* The wallet or contract address.
|
|
5408
|
+
*
|
|
5409
|
+
* Must be a valid address format for the specified blockchain. May differ from the adapter's
|
|
5410
|
+
* own address in scenarios such as relayed transactions or third-party minting.
|
|
5411
|
+
*/
|
|
5412
|
+
address: string;
|
|
5413
|
+
/**
|
|
5414
|
+
* The blockchain network where the wallet or contract address resides.
|
|
5415
|
+
*
|
|
5416
|
+
* Determines the context and format for the address and adapter.
|
|
5417
|
+
*/
|
|
5418
|
+
chain: TChainDefinition;
|
|
5419
|
+
}
|
|
5420
|
+
/**
|
|
5421
|
+
* Wallet context for bridge destinations with optional custom recipient.
|
|
5422
|
+
*
|
|
5423
|
+
* Extends WalletContext to support scenarios where the recipient address
|
|
5424
|
+
* differs from the signer address (e.g., bridging to a third-party wallet).
|
|
5425
|
+
* The signer address is used for transaction authorization, while the
|
|
5426
|
+
* recipient address specifies where the minted funds should be sent.
|
|
5427
|
+
*
|
|
5428
|
+
* @typeParam TAdapterCapabilities - The adapter capabilities type to use for the wallet context.
|
|
5429
|
+
* @typeParam TChainDefinition - The chain definition type to use for the wallet context.
|
|
5430
|
+
*
|
|
5431
|
+
* @example
|
|
5432
|
+
* ```typescript
|
|
5433
|
+
* import type { DestinationWalletContext } from '@core/provider'
|
|
5434
|
+
* import { adapter, blockchain } from './setup'
|
|
5435
|
+
*
|
|
5436
|
+
* // Bridge to a custom recipient address
|
|
5437
|
+
* const destination: DestinationWalletContext = {
|
|
5438
|
+
* adapter,
|
|
5439
|
+
* address: '0x1234...abcd', // Signer address
|
|
5440
|
+
* chain: blockchain,
|
|
5441
|
+
* recipientAddress: '0x9876...fedc' // Custom recipient
|
|
5442
|
+
* }
|
|
5443
|
+
* ```
|
|
5444
|
+
*/
|
|
5445
|
+
interface DestinationWalletContext<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
|
|
5446
|
+
/**
|
|
5447
|
+
* The chain definition type to use for the wallet context.
|
|
5448
|
+
*
|
|
5449
|
+
* @defaultValue ChainDefinition
|
|
5450
|
+
*/
|
|
5451
|
+
TChainDefinition extends ChainDefinition = ChainDefinition> extends WalletContext<TAdapterCapabilities, TChainDefinition> {
|
|
5452
|
+
/**
|
|
5453
|
+
* Optional custom recipient address for minted funds.
|
|
5454
|
+
*
|
|
5455
|
+
* When provided, minted tokens will be sent to this address instead of
|
|
5456
|
+
* the address specified in the wallet context. The wallet context address
|
|
5457
|
+
* is still used for transaction signing and authorization.
|
|
5458
|
+
*
|
|
5459
|
+
* Must be a valid address format for the specified blockchain.
|
|
5460
|
+
*/
|
|
5461
|
+
recipientAddress?: string;
|
|
5462
|
+
}
|
|
5463
|
+
/**
|
|
5464
|
+
* Parameters for executing a cross-chain bridge operation.
|
|
5465
|
+
*/
|
|
5466
|
+
interface BridgeParams$1<TFromCapabilities extends AdapterCapabilities = AdapterCapabilities, TToCapabilities extends AdapterCapabilities = AdapterCapabilities,
|
|
5467
|
+
/**
|
|
5468
|
+
* The chain definition type to use for the wallet context.
|
|
5469
|
+
*
|
|
5470
|
+
* @defaultValue ChainDefinition
|
|
5471
|
+
*/
|
|
5472
|
+
TChainDefinition extends ChainDefinition = ChainDefinition> {
|
|
5473
|
+
/** The source adapter containing wallet and chain information */
|
|
5474
|
+
source: WalletContext<TFromCapabilities, TChainDefinition>;
|
|
5475
|
+
/** The destination adapter containing wallet and chain information */
|
|
5476
|
+
destination: DestinationWalletContext<TToCapabilities, TChainDefinition>;
|
|
5477
|
+
/** The amount to transfer (as a string to avoid precision issues) */
|
|
5478
|
+
amount: string;
|
|
5479
|
+
/** The token to transfer (currently only USDC is supported) */
|
|
5480
|
+
token: 'USDC';
|
|
5481
|
+
/** Bridge configuration (e.g., fast burn settings) */
|
|
5482
|
+
config: BridgeConfig;
|
|
5483
|
+
/**
|
|
5484
|
+
* Optional invocation metadata for tracing and correlation.
|
|
5485
|
+
*
|
|
5486
|
+
* When provided, the `traceId` is used to correlate all events emitted during
|
|
5487
|
+
* the bridge operation. If not provided, an OpenTelemetry-compatible traceId
|
|
5488
|
+
* will be auto-generated.
|
|
5489
|
+
*/
|
|
5490
|
+
invocationMeta?: InvocationMeta;
|
|
5491
|
+
}
|
|
5263
5492
|
/**
|
|
5264
5493
|
* Configuration options for customizing bridge behavior.
|
|
5265
5494
|
*
|
|
@@ -7391,6 +7620,24 @@ interface EarnConfig {
|
|
|
7391
7620
|
* Format: `KIT_KEY:<keyId>:<keySecret>`
|
|
7392
7621
|
*/
|
|
7393
7622
|
readonly kitKey?: string | undefined;
|
|
7623
|
+
/**
|
|
7624
|
+
* Optional base URL override for the Earn Service API.
|
|
7625
|
+
*
|
|
7626
|
+
* Defaults to `https://api.circle.com` when omitted. Override for testing
|
|
7627
|
+
* against staging or local environments.
|
|
7628
|
+
*/
|
|
7629
|
+
readonly baseUrl?: string | undefined;
|
|
7630
|
+
/**
|
|
7631
|
+
* Enable or disable atomic batched transaction execution.
|
|
7632
|
+
*
|
|
7633
|
+
* When `true` (or `undefined` / omitted), same-chain deposit and withdraw
|
|
7634
|
+
* bundle the approve and execute calls into one adapter-native atomic batch
|
|
7635
|
+
* when the connected wallet supports it. Set to `false` to force the
|
|
7636
|
+
* sequential approve → execute flow.
|
|
7637
|
+
*
|
|
7638
|
+
* @defaultValue `undefined` (batching attempted when the wallet supports it)
|
|
7639
|
+
*/
|
|
7640
|
+
readonly batchTransactions?: boolean | undefined;
|
|
7394
7641
|
}
|
|
7395
7642
|
/**
|
|
7396
7643
|
* Parameters for fetching vault information.
|
|
@@ -8017,6 +8264,91 @@ type EarnClaimRewardsQuoteInfo = Omit<ClaimRewardsQuoteInfo, 'rewards'> & {
|
|
|
8017
8264
|
*/
|
|
8018
8265
|
type EarnOperationParams = AnyDepositParams | WithdrawParams | ClaimRewardsParams | GetVaultsParams | ExploreVaultsParams | ExploreVaultsIteratorParams | GetPositionParams | GetDepositQuoteParams | GetWithdrawalQuoteParams | GetClaimRewardsQuoteParams;
|
|
8019
8266
|
|
|
8267
|
+
type FeeFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
|
|
8268
|
+
type FeeRecipientFunction<TFromAdapterCapabilities extends AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities> = (feePayoutChain: ChainDefinition, params: BridgeParams$1<TFromAdapterCapabilities, TToAdapterCapabilities>) => Promise<string> | string;
|
|
8269
|
+
/**
|
|
8270
|
+
* Custom fee policy for BridgeKit.
|
|
8271
|
+
*
|
|
8272
|
+
* Provides hooks to calculate an absolute custom fee and resolve the fee recipient address
|
|
8273
|
+
* on the source chain. The returned fee is **added on top of the transfer amount** (the wallet signs for
|
|
8274
|
+
* `amount + customFee`). Once collected, the custom fee is split:
|
|
8275
|
+
*
|
|
8276
|
+
* - **10%** automatically routes to Circle.
|
|
8277
|
+
* - **90%** routes to your supplied `recipientAddress`.
|
|
8278
|
+
*
|
|
8279
|
+
* The entire transfer amount still flows through CCTPv2, which then charges its own protocol fee.
|
|
8280
|
+
*
|
|
8281
|
+
* Use `computeFee` (recommended) for human-readable amounts, or `calculateFee` (deprecated)
|
|
8282
|
+
* for smallest-unit amounts. Only one should be provided.
|
|
8283
|
+
*
|
|
8284
|
+
* @example
|
|
8285
|
+
* ```typescript
|
|
8286
|
+
* import type { CustomFeePolicy, BridgeParams } from '@circle-fin/bridge-kit'
|
|
8287
|
+
*
|
|
8288
|
+
* const policy: CustomFeePolicy = {
|
|
8289
|
+
* // computeFee receives human-readable amounts (e.g., '100' for 100 USDC)
|
|
8290
|
+
* computeFee: (params: BridgeParams) => {
|
|
8291
|
+
* const amount = parseFloat(params.amount)
|
|
8292
|
+
*
|
|
8293
|
+
* // 1% fee, capped between 5-50 USDC
|
|
8294
|
+
* const fee = Math.min(Math.max(amount * 0.01, 5), 50)
|
|
8295
|
+
* return fee.toFixed(6)
|
|
8296
|
+
* },
|
|
8297
|
+
* resolveFeeRecipientAddress: (feePayoutChain) =>
|
|
8298
|
+
* feePayoutChain.type === 'solana'
|
|
8299
|
+
* ? 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
|
|
8300
|
+
* : '0x1234567890123456789012345678901234567890',
|
|
8301
|
+
* }
|
|
8302
|
+
* ```
|
|
8303
|
+
*/
|
|
8304
|
+
type CustomFeePolicy$2 = {
|
|
8305
|
+
/**
|
|
8306
|
+
* A function that returns the fee to charge for the bridge transfer.
|
|
8307
|
+
* The value returned from the function represents an absolute fee.
|
|
8308
|
+
* The returned fee is **added on top of the transfer amount**. For example, returning
|
|
8309
|
+
* `'5'` (5 USDC) for a 100 USDC transfer causes the wallet to debit 105 USDC total.
|
|
8310
|
+
* CCTPv2 still processes the full 100 USDC transfer amount, while the custom fee is split
|
|
8311
|
+
* 10%/90% between Circle and your fee recipient.
|
|
8312
|
+
*
|
|
8313
|
+
* @example
|
|
8314
|
+
* ```typescript
|
|
8315
|
+
* computeFee: (params) => {
|
|
8316
|
+
* const amount = parseFloat(params.amount)
|
|
8317
|
+
* return (amount * 0.01).toString() // 1% fee
|
|
8318
|
+
* }
|
|
8319
|
+
* ```
|
|
8320
|
+
*/
|
|
8321
|
+
computeFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
|
|
8322
|
+
calculateFee?: never;
|
|
8323
|
+
/**
|
|
8324
|
+
* A function that returns the fee recipient for a bridge transfer.
|
|
8325
|
+
* The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
|
|
8326
|
+
* The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
|
|
8327
|
+
*
|
|
8328
|
+
* For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
|
|
8329
|
+
* because the source chain of the bridge transfer is Ethereum.
|
|
8330
|
+
*/
|
|
8331
|
+
resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
|
|
8332
|
+
} | {
|
|
8333
|
+
computeFee?: never;
|
|
8334
|
+
/**
|
|
8335
|
+
* Calculate the fee to charge for the bridge transfer using smallest-unit amounts.
|
|
8336
|
+
*
|
|
8337
|
+
* @deprecated Use `computeFee` instead, which receives human-readable amounts.
|
|
8338
|
+
*
|
|
8339
|
+
* The `params.amount` is in smallest units (e.g., `'100000000'` for 100 USDC).
|
|
8340
|
+
*/
|
|
8341
|
+
calculateFee: FeeFunction<AdapterCapabilities, AdapterCapabilities>;
|
|
8342
|
+
/**
|
|
8343
|
+
* A function that returns the fee recipient for a bridge transfer.
|
|
8344
|
+
* The value returned from the function represents the address that will receive the fee on the source chain of the bridge transfer.
|
|
8345
|
+
* The fee recipient address **must be a valid address for the source chain** of the bridge transfer.
|
|
8346
|
+
*
|
|
8347
|
+
* For example: if you are bridging from Ethereum to Solana you would return `'0x1234567890123456789012345678901234567890'`,
|
|
8348
|
+
* because the source chain of the bridge transfer is Ethereum.
|
|
8349
|
+
*/
|
|
8350
|
+
resolveFeeRecipientAddress: FeeRecipientFunction<AdapterCapabilities, AdapterCapabilities>;
|
|
8351
|
+
};
|
|
8020
8352
|
/**
|
|
8021
8353
|
* Parameters for initiating a cross-chain USDC bridge transfer.
|
|
8022
8354
|
*
|
|
@@ -8121,6 +8453,463 @@ interface BridgeParams<TFromAdapterCapabilities extends AdapterCapabilities = Ad
|
|
|
8121
8453
|
invocationMeta?: InvocationMeta;
|
|
8122
8454
|
}
|
|
8123
8455
|
|
|
8456
|
+
/**
|
|
8457
|
+
* Allowance strategy for token approvals during swap operations.
|
|
8458
|
+
*
|
|
8459
|
+
* Defines how token allowances should be granted to the swap contract:
|
|
8460
|
+
* - `permit`: Use EIP-2612 permit signature (gas-efficient, no approval transaction)
|
|
8461
|
+
* - `approve`: Traditional approval transaction
|
|
8462
|
+
*
|
|
8463
|
+
* The default strategy is `permit` with fallback to `approve` if permit is not supported.
|
|
8464
|
+
*/
|
|
8465
|
+
type AllowanceStrategy$1 = 'permit' | 'approve';
|
|
8466
|
+
/**
|
|
8467
|
+
* Configuration options for swap operations.
|
|
8468
|
+
*
|
|
8469
|
+
* Controls swap behavior including allowance strategy, slippage tolerance,
|
|
8470
|
+
* minimum output amounts, custom fees, and kit identification.
|
|
8471
|
+
*
|
|
8472
|
+
* @example
|
|
8473
|
+
* ```typescript
|
|
8474
|
+
* import type { ServiceSwapConfig } from '@circle-fin/provider-stablecoin-service-swap'
|
|
8475
|
+
*
|
|
8476
|
+
* // Percentage-based fee
|
|
8477
|
+
* const config: ServiceSwapConfig = {
|
|
8478
|
+
* allowanceStrategy: 'permit',
|
|
8479
|
+
* slippageBps: 300, // 3%
|
|
8480
|
+
* stopLimit: '950000', // Minimum 0.95 USDC output
|
|
8481
|
+
* customFee: {
|
|
8482
|
+
* percentageBps: 1000, // 10% fee
|
|
8483
|
+
* recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
|
8484
|
+
* }
|
|
8485
|
+
* }
|
|
8486
|
+
* ```
|
|
8487
|
+
*
|
|
8488
|
+
* @example
|
|
8489
|
+
* ```typescript
|
|
8490
|
+
* // Absolute amount fee (from callback)
|
|
8491
|
+
* const config: ServiceSwapConfig = {
|
|
8492
|
+
* allowanceStrategy: 'permit',
|
|
8493
|
+
* customFee: {
|
|
8494
|
+
* amount: '10000', // 0.01 USDC fee (absolute)
|
|
8495
|
+
* recipientAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
|
8496
|
+
* }
|
|
8497
|
+
* }
|
|
8498
|
+
* ```
|
|
8499
|
+
*/
|
|
8500
|
+
interface ServiceSwapConfig {
|
|
8501
|
+
/**
|
|
8502
|
+
* Strategy for granting token allowances to the swap contract.
|
|
8503
|
+
*
|
|
8504
|
+
* Defaults to 'permit' with fallback to 'approve'.
|
|
8505
|
+
*/
|
|
8506
|
+
allowanceStrategy?: AllowanceStrategy$1;
|
|
8507
|
+
/**
|
|
8508
|
+
* Maximum acceptable slippage in basis points (BPS).
|
|
8509
|
+
*
|
|
8510
|
+
* 1 BPS = 0.01%, so 300 BPS = 3% slippage.
|
|
8511
|
+
* Defaults to 300 BPS (3%).
|
|
8512
|
+
*/
|
|
8513
|
+
slippageBps?: number;
|
|
8514
|
+
/**
|
|
8515
|
+
* Minimum acceptable output amount in smallest units (stop-limit).
|
|
8516
|
+
*
|
|
8517
|
+
* If the estimated output falls below this value, the swap will fail.
|
|
8518
|
+
* Expressed as a string to avoid precision issues.
|
|
8519
|
+
*/
|
|
8520
|
+
stopLimit?: string;
|
|
8521
|
+
/**
|
|
8522
|
+
* Custom fee configuration for this swap.
|
|
8523
|
+
*
|
|
8524
|
+
* Supports two mutually exclusive approaches:
|
|
8525
|
+
* 1. Percentage-based: Use `percentageBps` field (simple)
|
|
8526
|
+
* 2. Absolute amount: Use `amount` field (from callback)
|
|
8527
|
+
*
|
|
8528
|
+
* If both are set, validation will fail. Transaction-level percentage
|
|
8529
|
+
* takes precedence over kit-level callback policy.
|
|
8530
|
+
*/
|
|
8531
|
+
customFee?: {
|
|
8532
|
+
/**
|
|
8533
|
+
* Fee percentage in basis points (NEW).
|
|
8534
|
+
*
|
|
8535
|
+
* 100 bps = 1%, 1000 bps = 10%, 10000 bps = 100%
|
|
8536
|
+
*
|
|
8537
|
+
* Service calculates fee using `estimatedAmount` for same-chain output fees
|
|
8538
|
+
* and the input amount for cross-chain swaps.
|
|
8539
|
+
* Must be greater than 0 and less than or equal to 10000 (maximum 100%).
|
|
8540
|
+
* Mutually exclusive with `amount`.
|
|
8541
|
+
*
|
|
8542
|
+
* @example 1000 // 10% fee
|
|
8543
|
+
*/
|
|
8544
|
+
percentageBps?: number;
|
|
8545
|
+
/**
|
|
8546
|
+
* Fee amount in smallest units (for callback results).
|
|
8547
|
+
*
|
|
8548
|
+
* Absolute fee amount calculated by callback function.
|
|
8549
|
+
* Mutually exclusive with `percentageBps`.
|
|
8550
|
+
*
|
|
8551
|
+
* @example '10000' // 0.01 USDC (6 decimals)
|
|
8552
|
+
*/
|
|
8553
|
+
amount?: string;
|
|
8554
|
+
/**
|
|
8555
|
+
* Address that will receive the developer's 90% fee share.
|
|
8556
|
+
*
|
|
8557
|
+
* Required whenever a custom fee is submitted to the provider. Optional at
|
|
8558
|
+
* the type level so SDK callback flows can represent partial fee state
|
|
8559
|
+
* before final validation.
|
|
8560
|
+
*
|
|
8561
|
+
* Must be valid on the fee payout chain: source chain for input-side fees
|
|
8562
|
+
* and cross-chain swaps, destination chain for same-chain output-side fees.
|
|
8563
|
+
*
|
|
8564
|
+
* @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
|
8565
|
+
*/
|
|
8566
|
+
recipientAddress?: string;
|
|
8567
|
+
};
|
|
8568
|
+
/**
|
|
8569
|
+
* Stablecoin Service Kit Key used to authenticate service-backed swap
|
|
8570
|
+
* requests.
|
|
8571
|
+
*
|
|
8572
|
+
* Treat this value as a credential. Do not log it, embed it in client-side
|
|
8573
|
+
* source, or expose it in telemetry.
|
|
8574
|
+
*/
|
|
8575
|
+
kitKey?: string;
|
|
8576
|
+
/**
|
|
8577
|
+
* DEX aggregator identifier used to source the swap route.
|
|
8578
|
+
*
|
|
8579
|
+
* @example 'lifi', 'paraswap'
|
|
8580
|
+
*/
|
|
8581
|
+
provider?: string;
|
|
8582
|
+
/**
|
|
8583
|
+
* Whether to fuse the ERC-20 approval and the swap into a single atomic
|
|
8584
|
+
* batch when the adapter supports it (EIP-5792, or a signing strategy that
|
|
8585
|
+
* declares atomic batching).
|
|
8586
|
+
*
|
|
8587
|
+
* @remarks
|
|
8588
|
+
* Defaults to `true`. When batching is available this collapses the two
|
|
8589
|
+
* sequential transactions of the on-chain approval path into one atomic
|
|
8590
|
+
* submission — a single signing challenge for a smart-contract wallet. Set
|
|
8591
|
+
* to `false` to force the sequential approve-then-swap path. Has no effect on
|
|
8592
|
+
* the gasless permit path (already a single transaction) or on native-token
|
|
8593
|
+
* swaps (no approval needed).
|
|
8594
|
+
*
|
|
8595
|
+
* The batch path relies on the wallet's own gas estimation for the swap call:
|
|
8596
|
+
* the service-provided gas floor and pre-flight simulation that the sequential
|
|
8597
|
+
* path applies are not conveyed through the batch. For a complex/multi-hop
|
|
8598
|
+
* swap whose wallet-side estimate under-shoots, this can out-of-gas-revert the
|
|
8599
|
+
* atomic batch where the sequential path would succeed — set `false` to fall
|
|
8600
|
+
* back to the service-floored sequential path if you hit this.
|
|
8601
|
+
*
|
|
8602
|
+
* @defaultValue true
|
|
8603
|
+
*/
|
|
8604
|
+
batchTransactions?: boolean;
|
|
8605
|
+
}
|
|
8606
|
+
/**
|
|
8607
|
+
* Parameters for initiating a swap operation through the Stablecoin Service.
|
|
8608
|
+
*
|
|
8609
|
+
* This type is used as the primary input to provider swap operations, allowing users to specify
|
|
8610
|
+
* the source context, input/output tokens, swap amount, destination address, and optional configuration.
|
|
8611
|
+
*
|
|
8612
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
|
|
8613
|
+
*
|
|
8614
|
+
* @example
|
|
8615
|
+
* ```typescript
|
|
8616
|
+
* import type { ServiceSwapParams } from '@circle-fin/provider-stablecoin-service-swap'
|
|
8617
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
|
|
8618
|
+
* import { Ethereum } from '@core/chains'
|
|
8619
|
+
*
|
|
8620
|
+
* const adapter = createAdapterFromPrivateKey({
|
|
8621
|
+
* privateKey: process.env.PRIVATE_KEY,
|
|
8622
|
+
* })
|
|
8623
|
+
*
|
|
8624
|
+
* const params: ServiceSwapParams = {
|
|
8625
|
+
* from: { adapter, chain: Ethereum },
|
|
8626
|
+
* tokenIn: 'USDC', // Alias resolves to chain-specific address
|
|
8627
|
+
* tokenOut: 'USDT', // Alias resolves to chain-specific address
|
|
8628
|
+
* amountIn: '100500000', // 100.50 USDC in base units
|
|
8629
|
+
* to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
|
8630
|
+
* config: {
|
|
8631
|
+
* slippageBps: 300, // 3% slippage
|
|
8632
|
+
* allowanceStrategy: 'permit'
|
|
8633
|
+
* }
|
|
8634
|
+
* }
|
|
8635
|
+
* ```
|
|
8636
|
+
*/
|
|
8637
|
+
interface ServiceSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities,
|
|
8638
|
+
/**
|
|
8639
|
+
* The chain definition type to use for the wallet context.
|
|
8640
|
+
*
|
|
8641
|
+
* @defaultValue ChainDefinition
|
|
8642
|
+
*/
|
|
8643
|
+
TChainDefinition extends ChainDefinition = ChainDefinition> {
|
|
8644
|
+
/**
|
|
8645
|
+
* The source adapter context (wallet and chain) for the swap.
|
|
8646
|
+
*/
|
|
8647
|
+
from: WalletContext<TFromAdapterCapabilities, TChainDefinition>;
|
|
8648
|
+
/**
|
|
8649
|
+
* The input token address or alias to swap from.
|
|
8650
|
+
*
|
|
8651
|
+
* **Supported formats:**
|
|
8652
|
+
* - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
|
|
8653
|
+
* - EVM address: `'0x'` prefixed hex (e.g., `'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'`)
|
|
8654
|
+
* - Solana address: Base58-encoded (e.g., `'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'`)
|
|
8655
|
+
*
|
|
8656
|
+
* Token aliases are automatically resolved to the chain-specific contract address.
|
|
8657
|
+
*
|
|
8658
|
+
* @example 'USDC' // Recommended: use alias
|
|
8659
|
+
* @example '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // Or full address
|
|
8660
|
+
*/
|
|
8661
|
+
tokenIn: string;
|
|
8662
|
+
/**
|
|
8663
|
+
* The output token address or alias to swap to.
|
|
8664
|
+
*
|
|
8665
|
+
* **Supported formats:**
|
|
8666
|
+
* - Token alias: `"USDC"`, `"USDT"`, `"NATIVE"` (case-insensitive)
|
|
8667
|
+
* - EVM address: `'0x'` prefixed hex (e.g., `'0xdAC17F958D2ee523a2206206994597C13D831ec7'`)
|
|
8668
|
+
* - Solana address: Base58-encoded (e.g., `'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'`)
|
|
8669
|
+
*
|
|
8670
|
+
* Token aliases are automatically resolved to the chain-specific contract address.
|
|
8671
|
+
*
|
|
8672
|
+
* @example 'USDT' // Recommended: use alias
|
|
8673
|
+
* @example '0xdAC17F958D2ee523a2206206994597C13D831ec7' // Or full address
|
|
8674
|
+
*/
|
|
8675
|
+
tokenOut: string;
|
|
8676
|
+
/**
|
|
8677
|
+
* The amount of input token to swap in base units.
|
|
8678
|
+
*
|
|
8679
|
+
* SwapKit converts human-readable amounts to base units before passing to the provider.
|
|
8680
|
+
*
|
|
8681
|
+
* @example '100500000' for 100.50 USDC (6 decimals)
|
|
8682
|
+
*/
|
|
8683
|
+
amountIn: string;
|
|
8684
|
+
/**
|
|
8685
|
+
* The destination address where the swapped tokens will be sent.
|
|
8686
|
+
*
|
|
8687
|
+
* @example '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
|
8688
|
+
*/
|
|
8689
|
+
to: string;
|
|
8690
|
+
/**
|
|
8691
|
+
* Optional destination chain for cross-chain swaps.
|
|
8692
|
+
*
|
|
8693
|
+
* Defaults to `from.chain` for same-chain swaps.
|
|
8694
|
+
*/
|
|
8695
|
+
toChain?: TChainDefinition;
|
|
8696
|
+
/**
|
|
8697
|
+
* Optional configuration for swap behavior.
|
|
8698
|
+
*
|
|
8699
|
+
* If omitted, defaults will be used:
|
|
8700
|
+
* - allowanceStrategy: 'permit' (fallback to 'approve')
|
|
8701
|
+
* - slippageBps: 300 (3%)
|
|
8702
|
+
*/
|
|
8703
|
+
config?: ServiceSwapConfig;
|
|
8704
|
+
}
|
|
8705
|
+
|
|
8706
|
+
/**
|
|
8707
|
+
* Fee context when fee is taken from INPUT token.
|
|
8708
|
+
*
|
|
8709
|
+
* Used for swaps where the fee is collected from the input token, including
|
|
8710
|
+
* all cross-chain swaps.
|
|
8711
|
+
* Extends the resolved swap parameters with a discriminator to indicate input fee scenario.
|
|
8712
|
+
*
|
|
8713
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
|
|
8714
|
+
*
|
|
8715
|
+
* @example
|
|
8716
|
+
* ```typescript
|
|
8717
|
+
* // USDC → RandomToken swap (fee from input)
|
|
8718
|
+
* const context: SwapInputFeeContext = {
|
|
8719
|
+
* type: 'input',
|
|
8720
|
+
* from: {
|
|
8721
|
+
* adapter: viemAdapter,
|
|
8722
|
+
* chain: Ethereum,
|
|
8723
|
+
* address: '0x...'
|
|
8724
|
+
* },
|
|
8725
|
+
* tokenIn: 'USDC',
|
|
8726
|
+
* tokenOut: 'RandomToken',
|
|
8727
|
+
* amountIn: '100000000', // 100 USDC in base units
|
|
8728
|
+
* to: '0x...'
|
|
8729
|
+
* }
|
|
8730
|
+
* ```
|
|
8731
|
+
*/
|
|
8732
|
+
interface SwapInputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
|
|
8733
|
+
/**
|
|
8734
|
+
* Fee source discriminator - input token.
|
|
8735
|
+
*/
|
|
8736
|
+
type: 'input';
|
|
8737
|
+
}
|
|
8738
|
+
/**
|
|
8739
|
+
* Fee context when fee is taken from OUTPUT token.
|
|
8740
|
+
*
|
|
8741
|
+
* Used for swaps where the output token is supported for fee collection.
|
|
8742
|
+
* Extends the resolved swap parameters with output amounts and discriminator.
|
|
8743
|
+
*
|
|
8744
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
|
|
8745
|
+
*
|
|
8746
|
+
* @remarks
|
|
8747
|
+
* If using `estimatedAmount` in callback and quote cache expires,
|
|
8748
|
+
* calculated fee may not match fresh quote. Use `minAmount` for
|
|
8749
|
+
* predictability at the cost of potentially lower fees.
|
|
8750
|
+
*
|
|
8751
|
+
* @example
|
|
8752
|
+
* ```typescript
|
|
8753
|
+
* // RandomToken → USDC swap (fee from output)
|
|
8754
|
+
* const context: SwapOutputFeeContext = {
|
|
8755
|
+
* type: 'output',
|
|
8756
|
+
* from: {
|
|
8757
|
+
* adapter: viemAdapter,
|
|
8758
|
+
* chain: Ethereum,
|
|
8759
|
+
* address: '0x...'
|
|
8760
|
+
* },
|
|
8761
|
+
* tokenIn: 'RandomToken',
|
|
8762
|
+
* tokenOut: 'USDC',
|
|
8763
|
+
* amountIn: '100000000',
|
|
8764
|
+
* to: '0x...',
|
|
8765
|
+
* minAmount: '50000000', // 50 USDC guaranteed minimum
|
|
8766
|
+
* estimatedAmount: '55000000' // 55 USDC expected output
|
|
8767
|
+
* }
|
|
8768
|
+
* ```
|
|
8769
|
+
*/
|
|
8770
|
+
interface SwapOutputFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> extends ResolvedSwapParams<TFromAdapterCapabilities> {
|
|
8771
|
+
/**
|
|
8772
|
+
* Fee source discriminator - output token.
|
|
8773
|
+
*/
|
|
8774
|
+
type: 'output';
|
|
8775
|
+
/**
|
|
8776
|
+
* Guaranteed minimum output amount in base units.
|
|
8777
|
+
*
|
|
8778
|
+
* More stable but lower than estimatedAmount. Use this for
|
|
8779
|
+
* predictable fee calculations.
|
|
8780
|
+
*/
|
|
8781
|
+
minAmount: string;
|
|
8782
|
+
/**
|
|
8783
|
+
* Estimated output amount in base units.
|
|
8784
|
+
*
|
|
8785
|
+
* Expected output based on current market conditions. May be
|
|
8786
|
+
* higher than minAmount. Subject to change if quote expires.
|
|
8787
|
+
*/
|
|
8788
|
+
estimatedAmount: string;
|
|
8789
|
+
}
|
|
8790
|
+
/**
|
|
8791
|
+
* Discriminated union for swap fee contexts.
|
|
8792
|
+
*
|
|
8793
|
+
* Provides different context based on whether fee is from input or output token.
|
|
8794
|
+
* Discriminated by the `type` field: 'input' for fees from input token, 'output' for output token.
|
|
8795
|
+
*
|
|
8796
|
+
* Includes full swap parameters (adapter, chain, tokens, amounts) for maximum flexibility
|
|
8797
|
+
* in fee calculation logic.
|
|
8798
|
+
*
|
|
8799
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
|
|
8800
|
+
*/
|
|
8801
|
+
type SwapFeeContext<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = SwapInputFeeContext<TFromAdapterCapabilities> | SwapOutputFeeContext<TFromAdapterCapabilities>;
|
|
8802
|
+
/**
|
|
8803
|
+
* Custom fee policy for SwapKit (callback-based approach).
|
|
8804
|
+
*
|
|
8805
|
+
* Provides hooks to calculate an absolute fee amount and resolve the fee
|
|
8806
|
+
* recipient address. The callback receives a discriminated context with
|
|
8807
|
+
* different fields based on operation type (bridge vs swap) and fee source
|
|
8808
|
+
* (input vs output).
|
|
8809
|
+
*
|
|
8810
|
+
* @remarks
|
|
8811
|
+
* This is mutually exclusive with transaction-level percentage fees.
|
|
8812
|
+
* If both are set, the transaction-level percentage takes precedence.
|
|
8813
|
+
*
|
|
8814
|
+
* The callback approach makes two API calls for same-chain output fees:
|
|
8815
|
+
* 1. GET /quote - retrieve fee context and quote
|
|
8816
|
+
* 2. POST /swap - execute with calculated fee
|
|
8817
|
+
*
|
|
8818
|
+
* Cross-chain swaps always use input fees on the source chain, so callbacks
|
|
8819
|
+
* receive `type: 'input'` for those routes.
|
|
8820
|
+
*
|
|
8821
|
+
* @example
|
|
8822
|
+
* ```typescript
|
|
8823
|
+
* import type { CustomFeePolicy } from '@circle-fin/swap-kit'
|
|
8824
|
+
*
|
|
8825
|
+
* const policy: CustomFeePolicy = {
|
|
8826
|
+
* computeFee: async (ctx) => {
|
|
8827
|
+
* // Discriminate by fee source (input vs output)
|
|
8828
|
+
* if (ctx.type === 'input') {
|
|
8829
|
+
* // Simple percentage for input fees
|
|
8830
|
+
* return (parseFloat(ctx.amountIn) * 0.1).toString()
|
|
8831
|
+
* } else {
|
|
8832
|
+
* // Complex logic for output fees (VIP tiers, etc.)
|
|
8833
|
+
* const user = await database.getUser(...)
|
|
8834
|
+
* if (user.isVIP) {
|
|
8835
|
+
* return (parseFloat(ctx.minAmount) * 0.05).toString()
|
|
8836
|
+
* }
|
|
8837
|
+
* return (parseFloat(ctx.estimatedAmount) * 0.1).toString()
|
|
8838
|
+
* }
|
|
8839
|
+
* },
|
|
8840
|
+
* resolveFeeRecipientAddress: (chain) => {
|
|
8841
|
+
* return chain.type === 'solana'
|
|
8842
|
+
* ? 'SolanaAddress...'
|
|
8843
|
+
* : '0xEVMAddress...'
|
|
8844
|
+
* },
|
|
8845
|
+
* }
|
|
8846
|
+
* ```
|
|
8847
|
+
*/
|
|
8848
|
+
interface CustomFeePolicy$1 {
|
|
8849
|
+
/**
|
|
8850
|
+
* Calculate custom fee amount based on swap context.
|
|
8851
|
+
*
|
|
8852
|
+
* Receives full swap parameters including adapter, chain, tokens, and amounts.
|
|
8853
|
+
* Context is discriminated by `type` field:
|
|
8854
|
+
* - 'input': Fee from input token (OK → Any swaps and all cross-chain swaps)
|
|
8855
|
+
* - 'output': Fee from output token (same-chain Any → OK swaps), includes minAmount and estimatedAmount
|
|
8856
|
+
*
|
|
8857
|
+
* The wrapper automatically converts amounts to/from base units, so your
|
|
8858
|
+
* callback works with human-readable numbers (e.g., '0.1' for 0.1 USDC).
|
|
8859
|
+
*
|
|
8860
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter
|
|
8861
|
+
* @param context - Discriminated swap fee context with full swap parameters
|
|
8862
|
+
* @returns Absolute fee amount as string in human-readable format
|
|
8863
|
+
*
|
|
8864
|
+
* @example
|
|
8865
|
+
* ```typescript
|
|
8866
|
+
* computeFee: async (ctx) => {
|
|
8867
|
+
* if (ctx.type === 'output') {
|
|
8868
|
+
* // Output fee scenario
|
|
8869
|
+
* // Use estimatedAmount or minAmount for calculation
|
|
8870
|
+
* return (parseFloat(ctx.estimatedAmount) * 0.01).toString()
|
|
8871
|
+
* }
|
|
8872
|
+
* // Input fee scenario
|
|
8873
|
+
* return (parseFloat(ctx.amountIn) * 0.01).toString()
|
|
8874
|
+
* }
|
|
8875
|
+
* ```
|
|
8876
|
+
*
|
|
8877
|
+
* @example
|
|
8878
|
+
* ```typescript
|
|
8879
|
+
* computeFee: async (ctx) => {
|
|
8880
|
+
* if (ctx.type === 'output') {
|
|
8881
|
+
* // Use minAmount for predictable fees
|
|
8882
|
+
* return (parseFloat(ctx.minAmount) * 0.01).toString()
|
|
8883
|
+
* }
|
|
8884
|
+
* return (parseFloat(ctx.amountIn) * 0.01).toString()
|
|
8885
|
+
* }
|
|
8886
|
+
* ```
|
|
8887
|
+
*/
|
|
8888
|
+
computeFee: <TFromAdapterCapabilities extends AdapterCapabilities>(context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
|
|
8889
|
+
/**
|
|
8890
|
+
* Resolve fee recipient address for the chain where fee is collected.
|
|
8891
|
+
*
|
|
8892
|
+
* Called with the chain where fee will be paid. For cross-chain swaps this
|
|
8893
|
+
* is always the source chain. Must return a valid address format for that
|
|
8894
|
+
* chain type (EVM or Solana).
|
|
8895
|
+
*
|
|
8896
|
+
* @param feePayoutChain - Chain definition where fee is collected
|
|
8897
|
+
* @param context - The swap fee context with full parameters
|
|
8898
|
+
* @returns Fee recipient address for the chain
|
|
8899
|
+
*
|
|
8900
|
+
* @example
|
|
8901
|
+
* ```typescript
|
|
8902
|
+
* resolveFeeRecipientAddress: (chain, ctx) => {
|
|
8903
|
+
* // Chain-based routing
|
|
8904
|
+
* if (chain.type === 'solana') {
|
|
8905
|
+
* return 'SolanaAddress...'
|
|
8906
|
+
* }
|
|
8907
|
+
* return '0xEVMAddress...'
|
|
8908
|
+
* }
|
|
8909
|
+
* ```
|
|
8910
|
+
*/
|
|
8911
|
+
resolveFeeRecipientAddress: <TFromAdapterCapabilities extends AdapterCapabilities>(feePayoutChain: ChainDefinition, context: SwapFeeContext<TFromAdapterCapabilities>) => Promise<string> | string;
|
|
8912
|
+
}
|
|
8124
8913
|
/**
|
|
8125
8914
|
* Adapter context constrained to swap-supported chains.
|
|
8126
8915
|
*/
|
|
@@ -8268,6 +9057,45 @@ interface SwapConfig {
|
|
|
8268
9057
|
*/
|
|
8269
9058
|
kitKey?: string;
|
|
8270
9059
|
}
|
|
9060
|
+
/**
|
|
9061
|
+
* Resolved parameters for swap operations after validation and normalization.
|
|
9062
|
+
*
|
|
9063
|
+
* Internal type used by SwapKit operations after `resolveSwapParams()` has:
|
|
9064
|
+
* - Validated the input parameters
|
|
9065
|
+
* - Resolved chain identifiers to full ChainDefinition objects
|
|
9066
|
+
* - Extracted and validated wallet addresses
|
|
9067
|
+
*
|
|
9068
|
+
* Note: Raw user input is validated first, then `tokenIn` and `tokenOut` may
|
|
9069
|
+
* be canonicalized for downstream routing (for example, Arc Testnet
|
|
9070
|
+
* `NATIVE` → `USDC`). Address resolution is handled by the provider layer.
|
|
9071
|
+
*
|
|
9072
|
+
* This type is consumed by swap providers and internal operations but is not
|
|
9073
|
+
* exposed to end users. It extends ServiceSwapParams which is the format expected
|
|
9074
|
+
* by the StablecoinServiceSwapProvider.
|
|
9075
|
+
*
|
|
9076
|
+
* @typeParam TFromAdapterCapabilities - The adapter capabilities type for the source adapter.
|
|
9077
|
+
*
|
|
9078
|
+
* @example
|
|
9079
|
+
* ```typescript
|
|
9080
|
+
* // After resolution, SwapParams becomes ResolvedSwapParams:
|
|
9081
|
+
* const resolved: ResolvedSwapParams = {
|
|
9082
|
+
* from: {
|
|
9083
|
+
* adapter: viemAdapter,
|
|
9084
|
+
* chain: Ethereum, // Full chain definition
|
|
9085
|
+
* address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e'
|
|
9086
|
+
* },
|
|
9087
|
+
* tokenIn: 'USDC', // Canonicalized for provider routing
|
|
9088
|
+
* tokenOut: 'USDT', // Canonicalized for provider routing
|
|
9089
|
+
* amountIn: '100500000', // Converted to base units (100.5 USDC with 6 decimals)
|
|
9090
|
+
* to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
|
|
9091
|
+
* config: {
|
|
9092
|
+
* slippageBps: 300,
|
|
9093
|
+
* allowanceStrategy: 'permit'
|
|
9094
|
+
* }
|
|
9095
|
+
* }
|
|
9096
|
+
* ```
|
|
9097
|
+
*/
|
|
9098
|
+
type ResolvedSwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> = ServiceSwapParams<TFromAdapterCapabilities>;
|
|
8271
9099
|
interface SwapParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
|
|
8272
9100
|
/**
|
|
8273
9101
|
* The source adapter context (wallet and chain) for the swap.
|
|
@@ -8313,6 +9141,122 @@ interface SwapParams<TFromAdapterCapabilities extends AdapterCapabilities = Adap
|
|
|
8313
9141
|
config?: SwapConfig;
|
|
8314
9142
|
}
|
|
8315
9143
|
|
|
9144
|
+
interface CustomFeeConfig {
|
|
9145
|
+
recipientAddress: string;
|
|
9146
|
+
value: string;
|
|
9147
|
+
}
|
|
9148
|
+
/**
|
|
9149
|
+
* Data needed to retry a mint that failed after the transfer was
|
|
9150
|
+
* already committed (funds locked).
|
|
9151
|
+
*
|
|
9152
|
+
* Obtain these values from the KitError (TRANSACTION_REVERTED) thrown when
|
|
9153
|
+
* the on-chain mint step fails. The attestation and signature are available
|
|
9154
|
+
* in `error.cause.trace`.
|
|
9155
|
+
*/
|
|
9156
|
+
interface RetryMintConfig {
|
|
9157
|
+
/** The attestation hex string returned by the Gateway `/v1/transfer` API. */
|
|
9158
|
+
attestation: string;
|
|
9159
|
+
/** The attestation signature hex string returned by `/v1/transfer`. */
|
|
9160
|
+
signature: string;
|
|
9161
|
+
}
|
|
9162
|
+
interface SpendConfig {
|
|
9163
|
+
customFee?: CustomFeeConfig;
|
|
9164
|
+
/**
|
|
9165
|
+
* When provided, skips the estimate/sign/transfer steps and proceeds
|
|
9166
|
+
* directly to the on-chain mint using a previously obtained attestation.
|
|
9167
|
+
*
|
|
9168
|
+
* Use this to retry a mint that failed due to an RPC or network issue
|
|
9169
|
+
* after the transfer was already committed.
|
|
9170
|
+
*
|
|
9171
|
+
* @remarks
|
|
9172
|
+
* The `useForwarder` flag on the destination is ignored during retry
|
|
9173
|
+
* because the attestation was already issued — the Forwarding Service
|
|
9174
|
+
* is only involved in the initial transfer, not re-mints.
|
|
9175
|
+
*/
|
|
9176
|
+
retry?: RetryMintConfig;
|
|
9177
|
+
}
|
|
9178
|
+
interface ResolvedAllocation {
|
|
9179
|
+
amount: string;
|
|
9180
|
+
chain: ChainDefinition;
|
|
9181
|
+
}
|
|
9182
|
+
interface ResolvedSpendSource<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
|
|
9183
|
+
adapter: Adapter<TAdapterCapabilities>;
|
|
9184
|
+
allocations: ResolvedAllocation[];
|
|
9185
|
+
address?: string;
|
|
9186
|
+
sourceAccount?: string;
|
|
9187
|
+
}
|
|
9188
|
+
interface ResolvedSpendDestination<TAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
|
|
9189
|
+
adapter?: Adapter<TAdapterCapabilities>;
|
|
9190
|
+
chain: ChainDefinition;
|
|
9191
|
+
recipientAddress?: string;
|
|
9192
|
+
address?: string;
|
|
9193
|
+
useForwarder?: boolean;
|
|
9194
|
+
}
|
|
9195
|
+
interface ResolvedSpendParams<TFromAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities, TToAdapterCapabilities extends AdapterCapabilities = AdapterCapabilities> {
|
|
9196
|
+
from: ResolvedSpendSource<TFromAdapterCapabilities>[];
|
|
9197
|
+
to: ResolvedSpendDestination<TToAdapterCapabilities>;
|
|
9198
|
+
token: SupportedToken;
|
|
9199
|
+
config?: SpendConfig;
|
|
9200
|
+
}
|
|
9201
|
+
/**
|
|
9202
|
+
* Function that computes the fee amount (in human-readable units, e.g. "10.5")
|
|
9203
|
+
* given the resolved spend parameters.
|
|
9204
|
+
*/
|
|
9205
|
+
type SpendFeeFunction = (params: ResolvedSpendParams) => Promise<string> | string;
|
|
9206
|
+
/**
|
|
9207
|
+
* Function that resolves the fee recipient address for a spend.
|
|
9208
|
+
* Called once per spend, against the resolved **destination** chain —
|
|
9209
|
+
* every fee burn intent in a spend mints to that single chain
|
|
9210
|
+
* regardless of which source chain(s) funded it, so only one
|
|
9211
|
+
* recipient address (valid on the destination chain) is ever needed.
|
|
9212
|
+
*/
|
|
9213
|
+
type SpendFeeRecipientFunction = (destinationChain: ChainDefinition, params: ResolvedSpendParams) => Promise<string> | string;
|
|
9214
|
+
/**
|
|
9215
|
+
* Policy for computing and routing custom developer fees.
|
|
9216
|
+
*
|
|
9217
|
+
* **Important:** When the kit invokes `computeFee` and
|
|
9218
|
+
* `resolveFeeRecipientAddress`, the `params` argument may be the
|
|
9219
|
+
* **raw, unresolved** `SpendParams` (cast to `ResolvedSpendParams`).
|
|
9220
|
+
* Fields that only exist after resolution (e.g. per-source allocations)
|
|
9221
|
+
* may be `undefined`. Implementations should only rely on top-level
|
|
9222
|
+
* fields such as `to`, `token`, and `amount`.
|
|
9223
|
+
*
|
|
9224
|
+
* @remarks
|
|
9225
|
+
* `resolveFeeRecipientAddress` is optional when you configure
|
|
9226
|
+
* {@link UnifiedBalanceKit.setFeeRecipients} instead — the declarative
|
|
9227
|
+
* map takes priority over this callback when both are present. Provide
|
|
9228
|
+
* exactly one of the two; a policy with neither throws at spend time.
|
|
9229
|
+
*/
|
|
9230
|
+
interface CustomFeePolicy {
|
|
9231
|
+
computeFee: SpendFeeFunction;
|
|
9232
|
+
resolveFeeRecipientAddress?: SpendFeeRecipientFunction;
|
|
9233
|
+
}
|
|
9234
|
+
|
|
9235
|
+
/**
|
|
9236
|
+
* Runtime array of token identifiers supported by the unified-balance-kit.
|
|
9237
|
+
*
|
|
9238
|
+
* @example
|
|
9239
|
+
* ```typescript
|
|
9240
|
+
* import { SUPPORTED_TOKENS } from '@circle-fin/unified-balance-kit'
|
|
9241
|
+
*
|
|
9242
|
+
* if (SUPPORTED_TOKENS.includes('USDC')) {
|
|
9243
|
+
* console.log('USDC is supported')
|
|
9244
|
+
* }
|
|
9245
|
+
* ```
|
|
9246
|
+
*/
|
|
9247
|
+
declare const SUPPORTED_TOKENS: readonly ["USDC"];
|
|
9248
|
+
/**
|
|
9249
|
+
* Token identifiers supported by the unified-balance-kit.
|
|
9250
|
+
*
|
|
9251
|
+
* @example
|
|
9252
|
+
* ```typescript
|
|
9253
|
+
* import type { SupportedToken } from '@circle-fin/unified-balance-kit'
|
|
9254
|
+
*
|
|
9255
|
+
* const token: SupportedToken = 'USDC'
|
|
9256
|
+
* ```
|
|
9257
|
+
*/
|
|
9258
|
+
type SupportedToken = (typeof SUPPORTED_TOKENS)[number];
|
|
9259
|
+
|
|
8316
9260
|
/**
|
|
8317
9261
|
* Operation types that support the `getFee`/`getFeeRecipient` hooks.
|
|
8318
9262
|
*/
|
|
@@ -8343,6 +9287,31 @@ interface OperationParamsMap {
|
|
|
8343
9287
|
swap: SwapParams;
|
|
8344
9288
|
earn: EarnOperationParams;
|
|
8345
9289
|
}
|
|
9290
|
+
/**
|
|
9291
|
+
* Operation-scoped custom fee policies configured at the AppKit level.
|
|
9292
|
+
*
|
|
9293
|
+
* Each property is optional so consumers can enable custom fees only for the
|
|
9294
|
+
* operation they use. AppKit forwards the supplied policy to the matching
|
|
9295
|
+
* underlying kit when that operation runs.
|
|
9296
|
+
*
|
|
9297
|
+
* @example
|
|
9298
|
+
* ```typescript
|
|
9299
|
+
* const policy: AppKitCustomFeePolicy = {
|
|
9300
|
+
* bridge: {
|
|
9301
|
+
* computeFee: () => '1.00',
|
|
9302
|
+
* resolveFeeRecipientAddress: () => '0x1234567890123456789012345678901234567890',
|
|
9303
|
+
* },
|
|
9304
|
+
* }
|
|
9305
|
+
* ```
|
|
9306
|
+
*/
|
|
9307
|
+
interface AppKitCustomFeePolicy {
|
|
9308
|
+
/** Custom fee policy forwarded to BridgeKit bridge operations. */
|
|
9309
|
+
bridge?: CustomFeePolicy$2;
|
|
9310
|
+
/** Custom fee policy forwarded to SwapKit swap operations. */
|
|
9311
|
+
swap?: CustomFeePolicy$1;
|
|
9312
|
+
/** Custom fee policy forwarded to UnifiedBalanceKit spend operations. */
|
|
9313
|
+
unifiedBalance?: CustomFeePolicy;
|
|
9314
|
+
}
|
|
8346
9315
|
/**
|
|
8347
9316
|
* Context interface for the AppKit with strongly typed getFee method.
|
|
8348
9317
|
*
|
|
@@ -8430,6 +9399,14 @@ interface AppKitContext {
|
|
|
8430
9399
|
chain: ChainDefinition;
|
|
8431
9400
|
params: OperationParamsMap[T];
|
|
8432
9401
|
}): Promise<string>;
|
|
9402
|
+
/**
|
|
9403
|
+
* Operation-scoped custom fee policies.
|
|
9404
|
+
*
|
|
9405
|
+
* Prefer {@link AppKit.setCustomFeePolicy} for runtime configuration. This
|
|
9406
|
+
* context property is read by the internal kit factories when AppKit creates
|
|
9407
|
+
* BridgeKit and SwapKit instances for each operation.
|
|
9408
|
+
*/
|
|
9409
|
+
customFeePolicy?: AppKitCustomFeePolicy;
|
|
8433
9410
|
/**
|
|
8434
9411
|
* Event handlers registered for AppKit operations.
|
|
8435
9412
|
*
|