@circle-fin/adapter-ethers-v6 0.0.2-alpha.6
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/LICENSE +190 -0
- package/README.md +338 -0
- package/index.cjs.js +8398 -0
- package/index.cjs.js.map +1 -0
- package/index.d.ts +2679 -0
- package/index.mjs +8390 -0
- package/index.mjs.map +1 -0
- package/package.json +36 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,2679 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025, Circle Internet Group, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { Provider, Signer as Signer$1, Eip1193Provider } from 'ethers';
|
|
20
|
+
import { Abi } from 'abitype';
|
|
21
|
+
import { TransactionInstruction, Signer } from '@solana/web3.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @packageDocumentation
|
|
25
|
+
* @module ChainDefinitions
|
|
26
|
+
*
|
|
27
|
+
* This module provides a complete type system for blockchain chain definitions.
|
|
28
|
+
* It supports both EVM and non‑EVM chains, token configurations, and multiple
|
|
29
|
+
* versions of the Cross-Chain Transfer Protocol (CCTP). Additionally, utility types
|
|
30
|
+
* are provided to extract subsets of chains (e.g. chains supporting USDC, EURC, or specific
|
|
31
|
+
* CCTP versions) from a provided collection.
|
|
32
|
+
*
|
|
33
|
+
* All types are fully documented with TSDoc to maximize developer experience.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Represents basic information about a currency or token.
|
|
37
|
+
* @interface Currency
|
|
38
|
+
* @category Types
|
|
39
|
+
* @description Provides the essential properties of a cryptocurrency or token.
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const ethCurrency: Currency = {
|
|
43
|
+
* name: "Ether",
|
|
44
|
+
* symbol: "ETH",
|
|
45
|
+
* decimals: 18
|
|
46
|
+
* };
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
interface Currency {
|
|
50
|
+
/**
|
|
51
|
+
* The full name of the currency.
|
|
52
|
+
* @example "Ether", "USDC"
|
|
53
|
+
*/
|
|
54
|
+
name: string;
|
|
55
|
+
/**
|
|
56
|
+
* The symbol or ticker of the currency.
|
|
57
|
+
* @example "ETH", "USDC"
|
|
58
|
+
*/
|
|
59
|
+
symbol: string;
|
|
60
|
+
/**
|
|
61
|
+
* The number of decimal places for the currency.
|
|
62
|
+
* @description Defines the divisibility of the currency (e.g., 1 ETH = 10^18 wei).
|
|
63
|
+
* @example 18 for ETH, 6 for USDC
|
|
64
|
+
*/
|
|
65
|
+
decimals: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Base information that all chain definitions must include.
|
|
69
|
+
* @interface BaseChainDefinition
|
|
70
|
+
* @category Types
|
|
71
|
+
* @description Provides the common properties shared by all blockchain definitions.
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const baseChain: BaseChainDefinition = {
|
|
75
|
+
* chain: Blockchain.Ethereum,
|
|
76
|
+
* name: "Ethereum",
|
|
77
|
+
* nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
78
|
+
* isTestnet: false
|
|
79
|
+
* };
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
interface BaseChainDefinition {
|
|
83
|
+
/**
|
|
84
|
+
* The blockchain identifier from the {@link Blockchain} enum.
|
|
85
|
+
*/
|
|
86
|
+
chain: Blockchain;
|
|
87
|
+
/**
|
|
88
|
+
* The display name of the blockchain.
|
|
89
|
+
* @example "Ethereum", "Solana", "Avalanche"
|
|
90
|
+
*/
|
|
91
|
+
name: string;
|
|
92
|
+
/**
|
|
93
|
+
* Optional title or alternative name for the blockchain.
|
|
94
|
+
* @example "Ethereum Mainnet", "Solana Mainnet"
|
|
95
|
+
*/
|
|
96
|
+
title?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Information about the native currency of the blockchain.
|
|
99
|
+
*/
|
|
100
|
+
nativeCurrency: Currency;
|
|
101
|
+
/**
|
|
102
|
+
* Indicates whether this is a testnet or mainnet.
|
|
103
|
+
* @description Used to differentiate between production and testing environments.
|
|
104
|
+
*/
|
|
105
|
+
isTestnet: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Template URL for the blockchain explorer to view transactions.
|
|
108
|
+
* @description URL template with a `\{hash\}` placeholder for transaction hash.
|
|
109
|
+
* @example "https://etherscan.io/tx/\{hash\}", "https://sepolia.etherscan.io/tx/\{hash\}"
|
|
110
|
+
*/
|
|
111
|
+
explorerUrl: string;
|
|
112
|
+
/**
|
|
113
|
+
* Default RPC endpoints for connecting to the blockchain network.
|
|
114
|
+
* @description Array of reliable public RPC endpoints that can be used for read and write operations.
|
|
115
|
+
* The first endpoint in the array is considered the primary endpoint.
|
|
116
|
+
* @example ["https://cloudflare-eth.com", "https://ethereum.publicnode.com"]
|
|
117
|
+
*/
|
|
118
|
+
rpcEndpoints: readonly string[];
|
|
119
|
+
/**
|
|
120
|
+
* The contract address for EURC.
|
|
121
|
+
* @description Its presence indicates that EURC is supported.
|
|
122
|
+
*/
|
|
123
|
+
eurcAddress: string | null;
|
|
124
|
+
/**
|
|
125
|
+
* The contract address for USDC.
|
|
126
|
+
* @description Its presence indicates that USDC is supported.
|
|
127
|
+
*/
|
|
128
|
+
usdcAddress: string | null;
|
|
129
|
+
/**
|
|
130
|
+
* Optional CCTP configuration.
|
|
131
|
+
* @description If provided, the chain supports CCTP.
|
|
132
|
+
*/
|
|
133
|
+
cctp: CCTPConfig | null;
|
|
134
|
+
/**
|
|
135
|
+
* Optional kit-specific contract addresses for enhanced chain functionality.
|
|
136
|
+
*
|
|
137
|
+
* @description When provided, the chain supports additional kit-specific logic in addition
|
|
138
|
+
* to standard CCTP. This enables hybrid flows where both standard approve/burn/mint
|
|
139
|
+
* and enhanced custom features are available. When undefined, the chain uses only
|
|
140
|
+
* the standard CCTP flow.
|
|
141
|
+
*
|
|
142
|
+
* The address format varies by blockchain:
|
|
143
|
+
* - EVM chains: 40-character hexadecimal with 0x prefix (e.g., "0x1234...")
|
|
144
|
+
* - Solana: Base58-encoded 32-byte address (e.g., "9WzDX...")
|
|
145
|
+
* - Other chains: Platform-specific address formats
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // EVM chain with bridge contract
|
|
150
|
+
* const evmChain: ChainDefinition = {
|
|
151
|
+
* // ... other properties
|
|
152
|
+
* kitContracts: {
|
|
153
|
+
* bridge: "0x1234567890abcdef1234567890abcdef12345678"
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
*
|
|
157
|
+
* // Solana chain with bridge contract
|
|
158
|
+
* const solanaChain: ChainDefinition = {
|
|
159
|
+
* // ... other properties
|
|
160
|
+
* kitContracts: {
|
|
161
|
+
* bridge: "9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM"
|
|
162
|
+
* }
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
kitContracts?: KitContracts;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Represents chain definitions for Ethereum Virtual Machine (EVM) compatible blockchains.
|
|
170
|
+
* @interface EVMChainDefinition
|
|
171
|
+
* @extends BaseChainDefinition
|
|
172
|
+
* @category Types
|
|
173
|
+
* @description Adds properties specific to EVM chains.
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const ethereum: EVMChainDefinition = {
|
|
177
|
+
* type: 'evm',
|
|
178
|
+
* chain: Blockchain.Ethereum,
|
|
179
|
+
* chainId: 1,
|
|
180
|
+
* name: 'Ethereum',
|
|
181
|
+
* title: 'Ethereum Mainnet',
|
|
182
|
+
* nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
183
|
+
* isTestnet: false
|
|
184
|
+
* };
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
interface EVMChainDefinition extends BaseChainDefinition {
|
|
188
|
+
/**
|
|
189
|
+
* Discriminator for EVM chains.
|
|
190
|
+
* @description Used for type narrowing when handling different chain types.
|
|
191
|
+
*/
|
|
192
|
+
type: 'evm';
|
|
193
|
+
/**
|
|
194
|
+
* The unique identifier for the blockchain.
|
|
195
|
+
* @description Standard EVM chain ID as defined in EIP-155.
|
|
196
|
+
* @example 1 for Ethereum Mainnet, 137 for Polygon.
|
|
197
|
+
*/
|
|
198
|
+
chainId: number;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Represents chain definitions for non-EVM blockchains.
|
|
202
|
+
* @interface NonEVMChainDefinition
|
|
203
|
+
* @extends BaseChainDefinition
|
|
204
|
+
* @category Types
|
|
205
|
+
* @description Contains properties for blockchains that do not use the EVM.
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const solana: NonEVMChainDefinition = {
|
|
209
|
+
* type: 'solana',
|
|
210
|
+
* chain: Blockchain.Solana,
|
|
211
|
+
* name: 'Solana',
|
|
212
|
+
* nativeCurrency: { name: 'Solana', symbol: 'SOL', decimals: 9 },
|
|
213
|
+
* isTestnet: false
|
|
214
|
+
* };
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
interface NonEVMChainDefinition extends BaseChainDefinition {
|
|
218
|
+
/**
|
|
219
|
+
* Discriminator for non-EVM chains.
|
|
220
|
+
* @description Identifies the specific blockchain platform.
|
|
221
|
+
*/
|
|
222
|
+
type: 'algorand' | 'avalanche' | 'solana' | 'aptos' | 'near' | 'stellar' | 'sui' | 'hedera' | 'noble' | 'polkadot';
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The type of chain.
|
|
226
|
+
* @alias ChainType
|
|
227
|
+
* @category Types
|
|
228
|
+
* @description Represents the type of chain.
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const chainType: ChainType = 'evm'
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
type ChainType = EVMChainDefinition['type'] | NonEVMChainDefinition['type'];
|
|
235
|
+
/**
|
|
236
|
+
* Public chain definition type.
|
|
237
|
+
* @alias ChainDefinition
|
|
238
|
+
* @category Types
|
|
239
|
+
* @description Represents either an EVM-based or non-EVM-based blockchain definition.
|
|
240
|
+
* This type is used by developers to define chain configurations.
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* // Standard chain with CCTP support only
|
|
244
|
+
* const ethereumChain: ChainDefinition = {
|
|
245
|
+
* type: 'evm',
|
|
246
|
+
* chain: Blockchain.Ethereum,
|
|
247
|
+
* chainId: 1,
|
|
248
|
+
* name: 'Ethereum',
|
|
249
|
+
* nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
|
|
250
|
+
* isTestnet: false,
|
|
251
|
+
* explorerUrl: 'https://etherscan.io/tx/{hash}',
|
|
252
|
+
* rpcEndpoints: ['https://eth.example.com'],
|
|
253
|
+
* eurcAddress: null,
|
|
254
|
+
* usdcAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
255
|
+
* cctp: {
|
|
256
|
+
* domain: 0,
|
|
257
|
+
* contracts: {
|
|
258
|
+
* v2: {
|
|
259
|
+
* type: 'split',
|
|
260
|
+
* tokenMessenger: '0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d',
|
|
261
|
+
* messageTransmitter: '0x81D40F21F12A8F0E3252Bccb954D722d4c464B64',
|
|
262
|
+
* confirmations: 65,
|
|
263
|
+
* fastConfirmations: 2
|
|
264
|
+
* }
|
|
265
|
+
* }
|
|
266
|
+
* },
|
|
267
|
+
* kitContracts: undefined
|
|
268
|
+
* };
|
|
269
|
+
*
|
|
270
|
+
* // Chain with custom contract support (hybrid flow)
|
|
271
|
+
* const customChain: ChainDefinition = {
|
|
272
|
+
* ...ethereumChain,
|
|
273
|
+
* kitContracts: {
|
|
274
|
+
* bridge: '0x1234567890abcdef1234567890abcdef12345678'
|
|
275
|
+
* }
|
|
276
|
+
* };
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
type ChainDefinition = EVMChainDefinition | NonEVMChainDefinition;
|
|
280
|
+
/**
|
|
281
|
+
* Chain definition with CCTPv2 configuration.
|
|
282
|
+
* @alias ChainDefinitionWithCCTPv2
|
|
283
|
+
* @extends ChainDefinition
|
|
284
|
+
* @category Types
|
|
285
|
+
* @description Represents a chain definition that includes CCTPv2 configuration. This is useful for typescript consumers to narrow down the type of chain definition to a chain that supports CCTPv2.
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const ethereumWithCCTPv2: ChainDefinitionWithCCTPv2 = {
|
|
289
|
+
* ...ethereum,
|
|
290
|
+
* cctp: {
|
|
291
|
+
* domain: 0,
|
|
292
|
+
* contracts: {
|
|
293
|
+
* v2: {
|
|
294
|
+
* type: 'merged',
|
|
295
|
+
* contract: '0x123...'
|
|
296
|
+
* }
|
|
297
|
+
* }
|
|
298
|
+
* }
|
|
299
|
+
* };
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
type ChainDefinitionWithCCTPv2 = ChainDefinition & {
|
|
303
|
+
cctp: CCTPConfig & {
|
|
304
|
+
contracts: {
|
|
305
|
+
v2: VersionConfig;
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
usdcAddress: string;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Chain identifier that can be used in transfer parameters and factory functions.
|
|
312
|
+
* This can be either:
|
|
313
|
+
* - A ChainDefinition object
|
|
314
|
+
* - A Blockchain enum value (e.g., Blockchain.Ethereum)
|
|
315
|
+
* - A string literal of the blockchain value (e.g., "Ethereum")
|
|
316
|
+
*/
|
|
317
|
+
type ChainIdentifier = ChainDefinition | Blockchain | `${Blockchain}`;
|
|
318
|
+
interface CCTPSplitConfig {
|
|
319
|
+
type: 'split';
|
|
320
|
+
tokenMessenger: string;
|
|
321
|
+
messageTransmitter: string;
|
|
322
|
+
confirmations: number;
|
|
323
|
+
}
|
|
324
|
+
interface CCTPMergedConfig {
|
|
325
|
+
type: 'merged';
|
|
326
|
+
contract: string;
|
|
327
|
+
confirmations: number;
|
|
328
|
+
}
|
|
329
|
+
type VersionConfig = CCTPSplitConfig | CCTPMergedConfig;
|
|
330
|
+
type CCTPContracts = Partial<{
|
|
331
|
+
v1: VersionConfig;
|
|
332
|
+
v2: VersionConfig & {
|
|
333
|
+
fastConfirmations: number;
|
|
334
|
+
};
|
|
335
|
+
}>;
|
|
336
|
+
/**
|
|
337
|
+
* Configuration for the Cross-Chain Transfer Protocol (CCTP).
|
|
338
|
+
* @interface CCTPConfig
|
|
339
|
+
* @category Types
|
|
340
|
+
* @description Contains the domain and required contract addresses for CCTP support.
|
|
341
|
+
* @example
|
|
342
|
+
* ```
|
|
343
|
+
* const cctpConfig: CCTPConfig = {
|
|
344
|
+
* domain: 0,
|
|
345
|
+
* contracts: {
|
|
346
|
+
* TokenMessenger: '0xabc',
|
|
347
|
+
* MessageReceiver: '0xdef'
|
|
348
|
+
* }
|
|
349
|
+
* };
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
interface CCTPConfig {
|
|
353
|
+
/**
|
|
354
|
+
* The CCTP domain identifier.
|
|
355
|
+
*/
|
|
356
|
+
domain: number;
|
|
357
|
+
/**
|
|
358
|
+
* The contracts required for CCTP.
|
|
359
|
+
*/
|
|
360
|
+
contracts: CCTPContracts;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Available kit contract types for enhanced chain functionality.
|
|
364
|
+
*
|
|
365
|
+
* @description Defines the valid contract types that can be deployed on chains
|
|
366
|
+
* to provide additional features beyond standard CCTP functionality.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* import type { KitContractType } from '@core/chains'
|
|
371
|
+
*
|
|
372
|
+
* const contractType: KitContractType = 'bridge' // Valid
|
|
373
|
+
* const invalidType: KitContractType = 'invalid' // TypeScript error
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
type KitContractType = 'bridge';
|
|
377
|
+
/**
|
|
378
|
+
* Kit-specific contract addresses for enhanced chain functionality.
|
|
379
|
+
*
|
|
380
|
+
* @description Maps contract types to their addresses on a specific chain.
|
|
381
|
+
* All contract types are optional, allowing chains to selectively support
|
|
382
|
+
* specific kit features.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* import type { KitContracts } from '@core/chains'
|
|
387
|
+
*
|
|
388
|
+
* const contracts: KitContracts = {
|
|
389
|
+
* bridge: "0x1234567890abcdef1234567890abcdef12345678"
|
|
390
|
+
* }
|
|
391
|
+
*
|
|
392
|
+
* // Future example with multiple contract types:
|
|
393
|
+
* const futureContracts: KitContracts = {
|
|
394
|
+
* bridge: "0x1234567890abcdef1234567890abcdef12345678",
|
|
395
|
+
* // Note: other contract types would be added to KitContractType union
|
|
396
|
+
* // customType: "0xabcdef1234567890abcdef1234567890abcdef12"
|
|
397
|
+
* }
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
type KitContracts = Partial<Record<KitContractType, string>>;
|
|
401
|
+
/**
|
|
402
|
+
* Enumeration of all blockchains supported by this library.
|
|
403
|
+
* @enum
|
|
404
|
+
* @category Enums
|
|
405
|
+
* @description Provides string identifiers for each supported blockchain.
|
|
406
|
+
*/
|
|
407
|
+
declare enum Blockchain {
|
|
408
|
+
Algorand = "Algorand",
|
|
409
|
+
Algorand_Testnet = "Algorand_Testnet",
|
|
410
|
+
Aptos = "Aptos",
|
|
411
|
+
Aptos_Testnet = "Aptos_Testnet",
|
|
412
|
+
Arbitrum = "Arbitrum",
|
|
413
|
+
Arbitrum_Sepolia = "Arbitrum_Sepolia",
|
|
414
|
+
Avalanche = "Avalanche",
|
|
415
|
+
Avalanche_Fuji = "Avalanche_Fuji",
|
|
416
|
+
Base = "Base",
|
|
417
|
+
Base_Sepolia = "Base_Sepolia",
|
|
418
|
+
Celo = "Celo",
|
|
419
|
+
Celo_Alfajores_Testnet = "Celo_Alfajores_Testnet",
|
|
420
|
+
Codex = "Codex",
|
|
421
|
+
Codex_Testnet = "Codex_Testnet",
|
|
422
|
+
Ethereum = "Ethereum",
|
|
423
|
+
Ethereum_Sepolia = "Ethereum_Sepolia",
|
|
424
|
+
Hedera = "Hedera",
|
|
425
|
+
Hedera_Testnet = "Hedera_Testnet",
|
|
426
|
+
Linea = "Linea",
|
|
427
|
+
Linea_Sepolia = "Linea_Sepolia",
|
|
428
|
+
NEAR = "NEAR",
|
|
429
|
+
NEAR_Testnet = "NEAR_Testnet",
|
|
430
|
+
Noble = "Noble",
|
|
431
|
+
Noble_Testnet = "Noble_Testnet",
|
|
432
|
+
Optimism = "Optimism",
|
|
433
|
+
Optimism_Sepolia = "Optimism_Sepolia",
|
|
434
|
+
Polkadot_Asset_Hub = "Polkadot_Asset_Hub",
|
|
435
|
+
Polkadot_Westmint = "Polkadot_Westmint",
|
|
436
|
+
Polygon = "Polygon",
|
|
437
|
+
Polygon_Amoy_Testnet = "Polygon_Amoy_Testnet",
|
|
438
|
+
Sei = "Sei",
|
|
439
|
+
Sei_Testnet = "Sei_Testnet",
|
|
440
|
+
Solana = "Solana",
|
|
441
|
+
Solana_Devnet = "Solana_Devnet",
|
|
442
|
+
Sonic = "Sonic",
|
|
443
|
+
Sonic_Testnet = "Sonic_Testnet",
|
|
444
|
+
Stellar = "Stellar",
|
|
445
|
+
Stellar_Testnet = "Stellar_Testnet",
|
|
446
|
+
Sui = "Sui",
|
|
447
|
+
Sui_Testnet = "Sui_Testnet",
|
|
448
|
+
Unichain = "Unichain",
|
|
449
|
+
Unichain_Sepolia = "Unichain_Sepolia",
|
|
450
|
+
World_Chain = "World_Chain",
|
|
451
|
+
World_Chain_Sepolia = "World_Chain_Sepolia",
|
|
452
|
+
ZKSync_Era = "ZKSync_Era",
|
|
453
|
+
ZKSync_Sepolia = "ZKSync_Sepolia"
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Core type definitions for blockchain transaction execution and gas estimation.
|
|
458
|
+
*
|
|
459
|
+
* This module provides TypeScript interfaces and types for handling blockchain
|
|
460
|
+
* transactions across different networks, with a focus on EVM-compatible chains
|
|
461
|
+
* and gas estimation.
|
|
462
|
+
*
|
|
463
|
+
* @module types
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Estimated gas information for a blockchain transaction.
|
|
468
|
+
*
|
|
469
|
+
* This interface provides a unified way to represent gas costs across different
|
|
470
|
+
* blockchain networks, supporting both EVM-style gas calculations and other
|
|
471
|
+
* fee models.
|
|
472
|
+
*
|
|
473
|
+
* @interface EstimatedGas
|
|
474
|
+
* @category Types
|
|
475
|
+
* @example
|
|
476
|
+
* ```typescript
|
|
477
|
+
* // EVM chain example
|
|
478
|
+
* const evmGas: EstimatedGas = {
|
|
479
|
+
* gas: 21000n,
|
|
480
|
+
* gasPrice: 1000000000n, // 1 Gwei
|
|
481
|
+
* fee: (21000n * 1000000000n).toString() // Total fee in wei
|
|
482
|
+
* };
|
|
483
|
+
*
|
|
484
|
+
* // Solana example
|
|
485
|
+
* const solanaGas: EstimatedGas = {
|
|
486
|
+
* gas: 5000n, // Lamports for compute units
|
|
487
|
+
* fee: '5000' // Total fee in Lamports
|
|
488
|
+
* };
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
interface EstimatedGas {
|
|
492
|
+
/**
|
|
493
|
+
* The amount of gas estimated for the transaction.
|
|
494
|
+
* For EVM chains, this represents the gas units.
|
|
495
|
+
* For other chains, this might represent compute units or similar metrics.
|
|
496
|
+
*
|
|
497
|
+
* @example 21000n, 5000n
|
|
498
|
+
*/
|
|
499
|
+
gas: bigint;
|
|
500
|
+
/**
|
|
501
|
+
* The estimated price per unit of gas.
|
|
502
|
+
* This is primarily used in EVM chains where gas price is a separate metric.
|
|
503
|
+
*
|
|
504
|
+
* @example 1000000000n
|
|
505
|
+
*/
|
|
506
|
+
gasPrice: bigint;
|
|
507
|
+
/**
|
|
508
|
+
* The total estimated fee as a string.
|
|
509
|
+
* This field is useful for chains where gas/gasPrice isn't the whole story
|
|
510
|
+
* or when the total fee needs to be represented in a different format.
|
|
511
|
+
* For EVM chains, this is the total fee in wei (gas * gasPrice).
|
|
512
|
+
*
|
|
513
|
+
* @example "21000000000000", "5000"
|
|
514
|
+
*/
|
|
515
|
+
fee: string;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Override parameters for EVM gas estimation.
|
|
519
|
+
*
|
|
520
|
+
* These parameters allow customization of gas estimation behavior
|
|
521
|
+
* for EVM-compatible chains.
|
|
522
|
+
*
|
|
523
|
+
* @interface EvmEstimateOverrides
|
|
524
|
+
*/
|
|
525
|
+
interface EvmEstimateOverrides {
|
|
526
|
+
/**
|
|
527
|
+
* The sender's address for the transaction.
|
|
528
|
+
* @example "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
|
|
529
|
+
*/
|
|
530
|
+
from?: string;
|
|
531
|
+
/**
|
|
532
|
+
* The value to be sent with the transaction in wei.
|
|
533
|
+
* @example 1000000000000000000n // 1 ETH
|
|
534
|
+
*/
|
|
535
|
+
value?: bigint;
|
|
536
|
+
/**
|
|
537
|
+
* The block tag to use for estimation.
|
|
538
|
+
* @example "latest", "safe", "finalized"
|
|
539
|
+
*/
|
|
540
|
+
blockTag?: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized';
|
|
541
|
+
/**
|
|
542
|
+
* The maximum gas limit for the transaction.
|
|
543
|
+
* @example 3000000
|
|
544
|
+
*/
|
|
545
|
+
gasLimit?: number;
|
|
546
|
+
/**
|
|
547
|
+
* The maximum fee per gas unit (EIP-1559).
|
|
548
|
+
* @example 20000000000n // 20 Gwei
|
|
549
|
+
*/
|
|
550
|
+
maxFeePerGas?: bigint;
|
|
551
|
+
/**
|
|
552
|
+
* The maximum priority fee per gas unit (EIP-1559).
|
|
553
|
+
* @example 1500000000n // 1.5 Gwei
|
|
554
|
+
*/
|
|
555
|
+
maxPriorityFeePerGas?: bigint;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Extended override parameters for EVM transaction execution.
|
|
559
|
+
*
|
|
560
|
+
* Includes all estimation overrides plus additional parameters
|
|
561
|
+
* specific to transaction execution.
|
|
562
|
+
*
|
|
563
|
+
* @interface EvmExecuteOverrides
|
|
564
|
+
* @extends EvmEstimateOverrides
|
|
565
|
+
*/
|
|
566
|
+
interface EvmExecuteOverrides extends EvmEstimateOverrides {
|
|
567
|
+
/**
|
|
568
|
+
* The nonce to use for the transaction.
|
|
569
|
+
* If not provided, the current nonce of the sender will be used.
|
|
570
|
+
* @example 42
|
|
571
|
+
*/
|
|
572
|
+
nonce?: number;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Prepared contract execution for EVM chains.
|
|
576
|
+
*
|
|
577
|
+
* Represents a prepared contract execution that can be estimated
|
|
578
|
+
* and executed on EVM-compatible chains.
|
|
579
|
+
*
|
|
580
|
+
* @interface EvmPreparedChainRequest
|
|
581
|
+
*/
|
|
582
|
+
interface EvmPreparedChainRequest {
|
|
583
|
+
/** The type of the prepared execution. */
|
|
584
|
+
type: 'evm';
|
|
585
|
+
/**
|
|
586
|
+
* Estimate the gas cost for the contract execution.
|
|
587
|
+
*
|
|
588
|
+
* @param overrides - Optional parameters to override the default estimation behavior
|
|
589
|
+
* @returns A promise that resolves to the estimated gas information
|
|
590
|
+
* @throws If the estimation fails
|
|
591
|
+
*/
|
|
592
|
+
estimate(overrides?: EvmEstimateOverrides): Promise<EstimatedGas>;
|
|
593
|
+
/**
|
|
594
|
+
* Execute the prepared contract call.
|
|
595
|
+
*
|
|
596
|
+
* @param overrides - Optional parameters to override the default execution behavior
|
|
597
|
+
* @returns A promise that resolves to the transaction hash
|
|
598
|
+
* @throws If the execution fails
|
|
599
|
+
*/
|
|
600
|
+
execute(overrides?: EvmExecuteOverrides): Promise<string>;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Union type for all supported prepared contract executions.
|
|
604
|
+
* Currently only supports EVM chains, but can be extended for other chains.
|
|
605
|
+
*/
|
|
606
|
+
type PreparedChainRequest = EvmPreparedChainRequest | SolanaPreparedChainRequest | NoopPreparedChainRequest;
|
|
607
|
+
/**
|
|
608
|
+
* Parameters for preparing an EVM contract execution.
|
|
609
|
+
*/
|
|
610
|
+
type EvmPreparedChainRequestParams = {
|
|
611
|
+
/** The type of the prepared execution. */
|
|
612
|
+
type: 'evm';
|
|
613
|
+
/** The ABI of the contract. */
|
|
614
|
+
abi: Abi | string[];
|
|
615
|
+
/** The address of the contract. */
|
|
616
|
+
address: `0x${string}`;
|
|
617
|
+
/** The name of the function to call. */
|
|
618
|
+
functionName: string;
|
|
619
|
+
/** The arguments to pass to the function. */
|
|
620
|
+
args: unknown[];
|
|
621
|
+
/**
|
|
622
|
+
* The chain the prepared request should be executed on.
|
|
623
|
+
*/
|
|
624
|
+
chain: EVMChainDefinition;
|
|
625
|
+
} & Partial<EvmEstimateOverrides>;
|
|
626
|
+
/**
|
|
627
|
+
* Solana-specific parameters for preparing a transaction.
|
|
628
|
+
* @interface SolanaPreparedChainRequestParams
|
|
629
|
+
*/
|
|
630
|
+
interface SolanaPreparedChainRequestParams {
|
|
631
|
+
/**
|
|
632
|
+
* The array of instructions to include in the transaction.
|
|
633
|
+
*/
|
|
634
|
+
instructions: TransactionInstruction[];
|
|
635
|
+
/**
|
|
636
|
+
* Additional signers besides the Adapter’s wallet (e.g. program-derived authorities).
|
|
637
|
+
*/
|
|
638
|
+
signers?: Signer[];
|
|
639
|
+
/**
|
|
640
|
+
* Optional override for how many compute units this transaction may consume.
|
|
641
|
+
* If omitted, the network’s default compute budget applies.
|
|
642
|
+
*/
|
|
643
|
+
computeUnitLimit?: number;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Solana-specific configuration for transaction estimation.
|
|
647
|
+
* @interface SolanaEstimateOverrides
|
|
648
|
+
*/
|
|
649
|
+
interface SolanaEstimateOverrides {
|
|
650
|
+
/** Optional compute unit limit for the transaction. */
|
|
651
|
+
computeUnitLimit?: number;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Solana-specific configuration for transaction execution.
|
|
655
|
+
* @interface SolanaExecuteOverrides
|
|
656
|
+
* @extends SolanaEstimateOverrides
|
|
657
|
+
*/
|
|
658
|
+
interface SolanaExecuteOverrides extends SolanaEstimateOverrides {
|
|
659
|
+
/** The commitment level for the transaction. */
|
|
660
|
+
preflightCommitment?: 'processed' | 'confirmed' | 'finalized';
|
|
661
|
+
/** The maximum number of retries for the transaction. */
|
|
662
|
+
maxRetries?: number;
|
|
663
|
+
/** Whether to skip the preflight check. */
|
|
664
|
+
skipPreflight?: boolean;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Solana-specific prepared chain request.
|
|
668
|
+
* @interface SolanaPreparedChainRequest
|
|
669
|
+
*/
|
|
670
|
+
interface SolanaPreparedChainRequest {
|
|
671
|
+
/** The type of the chain request. */
|
|
672
|
+
type: 'solana';
|
|
673
|
+
/** Estimate the compute units and fee for the transaction. */
|
|
674
|
+
estimate(overrides?: SolanaEstimateOverrides): Promise<EstimatedGas>;
|
|
675
|
+
/** Execute the prepared transaction. */
|
|
676
|
+
execute(overrides?: SolanaExecuteOverrides): Promise<string>;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* No-op prepared chain request for unsupported operations.
|
|
680
|
+
*
|
|
681
|
+
* This interface represents a prepared chain request that performs no operation.
|
|
682
|
+
* It is returned when an action is not supported by the target chain or when
|
|
683
|
+
* no actual blockchain interaction is required.
|
|
684
|
+
*
|
|
685
|
+
* @remarks
|
|
686
|
+
* The estimate and execute methods return placeholder values since no actual
|
|
687
|
+
* transaction is performed. This allows the calling code to handle unsupported
|
|
688
|
+
* operations gracefully without breaking the expected interface contract.
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* ```typescript
|
|
692
|
+
* const noopRequest: NoopPreparedChainRequest = {
|
|
693
|
+
* type: 'noop',
|
|
694
|
+
* estimate: async () => ({ gasLimit: 0n, gasPrice: 0n, totalFee: 0n }),
|
|
695
|
+
* execute: async () => '0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
696
|
+
* }
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
interface NoopPreparedChainRequest {
|
|
700
|
+
/** The type of the prepared request. */
|
|
701
|
+
type: 'noop';
|
|
702
|
+
/**
|
|
703
|
+
* Placeholder for the estimate method.
|
|
704
|
+
* @returns The estimated gas cost.
|
|
705
|
+
*/
|
|
706
|
+
estimate: () => Promise<EstimatedGas>;
|
|
707
|
+
/**
|
|
708
|
+
* Placeholder for the execute method.
|
|
709
|
+
* @returns The transaction hash.
|
|
710
|
+
*/
|
|
711
|
+
execute: () => Promise<string>;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Union type for all supported contract execution parameters.
|
|
715
|
+
* Currently only supports EVM chains, but can be extended for other chains.
|
|
716
|
+
*/
|
|
717
|
+
type PreparedChainRequestParams = EvmPreparedChainRequestParams | SolanaPreparedChainRequestParams;
|
|
718
|
+
/**
|
|
719
|
+
* Response from waiting for a transaction to be mined and confirmed on the blockchain.
|
|
720
|
+
*
|
|
721
|
+
* @interface WaitForTransactionResponse
|
|
722
|
+
*/
|
|
723
|
+
interface WaitForTransactionResponse {
|
|
724
|
+
/**
|
|
725
|
+
* The transaction hash identifier.
|
|
726
|
+
* @example "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
|
|
727
|
+
*/
|
|
728
|
+
txHash: string;
|
|
729
|
+
/**
|
|
730
|
+
* The final status of the transaction execution.
|
|
731
|
+
* Indicates whether the transaction was successfully executed or reverted.
|
|
732
|
+
* @example "success", "reverted"
|
|
733
|
+
*/
|
|
734
|
+
status: 'success' | 'reverted';
|
|
735
|
+
/**
|
|
736
|
+
* The total amount of gas used by all transactions in the block up to and including this transaction.
|
|
737
|
+
* Represents the cumulative gas consumption within the block.
|
|
738
|
+
* @example 2100000n
|
|
739
|
+
*/
|
|
740
|
+
cumulativeGasUsed?: bigint;
|
|
741
|
+
/**
|
|
742
|
+
* The amount of gas actually consumed by this specific transaction.
|
|
743
|
+
* This value is always less than or equal to the gas limit set for the transaction.
|
|
744
|
+
* @example 21000n
|
|
745
|
+
*/
|
|
746
|
+
gasUsed?: bigint;
|
|
747
|
+
/**
|
|
748
|
+
* The block number where the transaction was mined.
|
|
749
|
+
* Represents the sequential position of the block in the blockchain.
|
|
750
|
+
* @example 18500000n
|
|
751
|
+
*/
|
|
752
|
+
blockNumber?: bigint;
|
|
753
|
+
/**
|
|
754
|
+
* The hash of the block containing this transaction.
|
|
755
|
+
* Provides a unique identifier for the block where the transaction was included.
|
|
756
|
+
* @example "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
|
|
757
|
+
*/
|
|
758
|
+
blockHash?: string;
|
|
759
|
+
/**
|
|
760
|
+
* The zero-based index position of the transaction within the block.
|
|
761
|
+
* Indicates the order in which this transaction appears in the block.
|
|
762
|
+
* @example 5
|
|
763
|
+
*/
|
|
764
|
+
transactionIndex?: number;
|
|
765
|
+
/**
|
|
766
|
+
* The actual gas price paid per unit of gas for this transaction.
|
|
767
|
+
* For EIP-1559 transactions, this reflects the base fee plus priority fee.
|
|
768
|
+
* @example 15000000000n // 15 Gwei
|
|
769
|
+
*/
|
|
770
|
+
effectiveGasPrice?: bigint;
|
|
771
|
+
}
|
|
772
|
+
interface WaitForTransactionConfig {
|
|
773
|
+
/**
|
|
774
|
+
* The timeout for the transaction to be mined and confirmed on the blockchain.
|
|
775
|
+
* @example 10000
|
|
776
|
+
*/
|
|
777
|
+
timeout?: number | undefined;
|
|
778
|
+
/**
|
|
779
|
+
* The number of confirmations to wait for the transaction to be mined and confirmed on the blockchain.
|
|
780
|
+
* @example 1
|
|
781
|
+
*/
|
|
782
|
+
confirmations?: number;
|
|
783
|
+
/**
|
|
784
|
+
* The maximum supported transaction version for getTransaction.
|
|
785
|
+
* Defaults to 0 if not provided.
|
|
786
|
+
* @example 0
|
|
787
|
+
*/
|
|
788
|
+
maxSupportedTransactionVersion?: number;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Base interface for all action parameter objects.
|
|
793
|
+
*
|
|
794
|
+
* Provide a compile-time marker to explicitly identify objects that represent
|
|
795
|
+
* action parameters (leaf nodes) versus namespace containers that should be
|
|
796
|
+
* traversed during type recursion.
|
|
797
|
+
*
|
|
798
|
+
* @remarks
|
|
799
|
+
* This marker property exists only at the type level and is stripped away
|
|
800
|
+
* during compilation. It serves as a deterministic way to identify action
|
|
801
|
+
* parameter objects without relying on property name heuristics.
|
|
802
|
+
*
|
|
803
|
+
* All action parameter objects must extend this interface to be properly
|
|
804
|
+
* recognized by the recursive utility types in the action system.
|
|
805
|
+
*/
|
|
806
|
+
interface ActionParameters {
|
|
807
|
+
/**
|
|
808
|
+
* Compile-time marker identifying this as an action parameter object.
|
|
809
|
+
*
|
|
810
|
+
* This property is used by the type system to distinguish between
|
|
811
|
+
* namespace containers and action parameter definitions. It does not
|
|
812
|
+
* exist at runtime and is purely for TypeScript's type checking.
|
|
813
|
+
*/
|
|
814
|
+
readonly __isActionParams: true;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* EIP-2612 permit signature parameters for gasless token approvals.
|
|
819
|
+
*
|
|
820
|
+
* Contains the signature components and deadline required for permit-based
|
|
821
|
+
* token spending authorization without requiring separate approval transactions.
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```typescript
|
|
825
|
+
* const permitParams: PermitParams = {
|
|
826
|
+
* deadline: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour from now
|
|
827
|
+
* v: 27,
|
|
828
|
+
* r: '0x1234567890abcdef...',
|
|
829
|
+
* s: '0xfedcba0987654321...'
|
|
830
|
+
* }
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
interface PermitParams {
|
|
834
|
+
/**
|
|
835
|
+
* Permit expiration timestamp (Unix timestamp in seconds).
|
|
836
|
+
*
|
|
837
|
+
* The permit signature becomes invalid after this timestamp.
|
|
838
|
+
* Must be greater than the current block timestamp.
|
|
839
|
+
*/
|
|
840
|
+
deadline: bigint;
|
|
841
|
+
/**
|
|
842
|
+
* Recovery parameter of the ECDSA signature (27 or 28).
|
|
843
|
+
*
|
|
844
|
+
* Used to recover the public key from the signature components.
|
|
845
|
+
*/
|
|
846
|
+
v: number;
|
|
847
|
+
/**
|
|
848
|
+
* R component of the ECDSA signature.
|
|
849
|
+
*
|
|
850
|
+
* First 32 bytes of the signature as a hex string.
|
|
851
|
+
*/
|
|
852
|
+
r: string;
|
|
853
|
+
/**
|
|
854
|
+
* S component of the ECDSA signature.
|
|
855
|
+
*
|
|
856
|
+
* Second 32 bytes of the signature as a hex string.
|
|
857
|
+
*/
|
|
858
|
+
s: string;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Action map for Circle's Cross-Chain Transfer Protocol (CCTP) version 2 operations.
|
|
862
|
+
*
|
|
863
|
+
* Define the parameter schemas for CCTP v2 actions that enable native USDC
|
|
864
|
+
* transfers between supported blockchain networks. Use Circle's attestation
|
|
865
|
+
* service to verify and complete cross-chain transactions with cryptographic
|
|
866
|
+
* proof of burn and mint operations.
|
|
867
|
+
*
|
|
868
|
+
* @remarks
|
|
869
|
+
* CCTP v2 represents Circle's native cross-chain transfer protocol that allows
|
|
870
|
+
* USDC to move between chains without traditional lock-and-mint bridging.
|
|
871
|
+
* Instead, USDC is burned on the source chain and minted natively on the
|
|
872
|
+
* destination chain using cryptographic attestations.
|
|
873
|
+
*
|
|
874
|
+
* The protocol supports both "slow" (free) and "fast" (fee-based) transfer
|
|
875
|
+
* modes, with configurable finality thresholds and destination execution
|
|
876
|
+
* parameters for advanced use cases.
|
|
877
|
+
*
|
|
878
|
+
* @example
|
|
879
|
+
* ```typescript
|
|
880
|
+
* import type { CCTPv2ActionMap } from '@core/adapter/actions/cctp/v2'
|
|
881
|
+
* import { mainnet, polygon } from '@core/chains'
|
|
882
|
+
*
|
|
883
|
+
* // Deposit and burn USDC for cross-chain transfer
|
|
884
|
+
* const burnParams: CCTPv2ActionMap['depositForBurn'] = {
|
|
885
|
+
* amount: '1000000', // 1 USDC (6 decimals)
|
|
886
|
+
* mintRecipient: '0x742d35Cc6634C0532925a3b8D8E5e8d8D8e5e8d8D8e5e8',
|
|
887
|
+
* maxFee: '1000', // 0.001 USDC fast fee
|
|
888
|
+
* minFinalityThreshold: 65,
|
|
889
|
+
* fromChain: mainnet,
|
|
890
|
+
* toChain: polygon
|
|
891
|
+
* }
|
|
892
|
+
*
|
|
893
|
+
* // Receive and mint USDC on destination chain
|
|
894
|
+
* const receiveParams: CCTPv2ActionMap['receiveMessage'] = {
|
|
895
|
+
* eventNonce: '0x123abc...',
|
|
896
|
+
* attestation: '0xdef456...',
|
|
897
|
+
* message: '0x789012...',
|
|
898
|
+
* fromChain: mainnet,
|
|
899
|
+
* toChain: polygon
|
|
900
|
+
* }
|
|
901
|
+
* ```
|
|
902
|
+
*
|
|
903
|
+
* @see {@link ChainDefinitionWithCCTPv2} for supported chain definitions
|
|
904
|
+
*/
|
|
905
|
+
interface CCTPv2ActionMap {
|
|
906
|
+
/**
|
|
907
|
+
* Initiate a cross-chain USDC transfer by depositing and burning tokens on the source chain.
|
|
908
|
+
*
|
|
909
|
+
* Burn USDC tokens on the source chain and generate a message for attestation
|
|
910
|
+
* by Circle's infrastructure. The burned tokens will be minted on the destination
|
|
911
|
+
* chain once the attestation is obtained and the receive message is executed.
|
|
912
|
+
*
|
|
913
|
+
* @remarks
|
|
914
|
+
* This action represents the first step in a CCTP cross-chain transfer. After
|
|
915
|
+
* execution, you must wait for Circle's attestation service to observe the burn
|
|
916
|
+
* event and provide a cryptographic attestation that can be used to mint the
|
|
917
|
+
* equivalent amount on the destination chain.
|
|
918
|
+
*
|
|
919
|
+
* The `maxFee` parameter enables fast transfers through Circle's fast liquidity
|
|
920
|
+
* network, where liquidity providers can fulfill transfers immediately in exchange
|
|
921
|
+
* for a fee. Set to "0" for slower, free transfers that wait for full finality.
|
|
922
|
+
*/
|
|
923
|
+
depositForBurn: ActionParameters & {
|
|
924
|
+
/**
|
|
925
|
+
* Amount of USDC to deposit and burn (in token's smallest unit).
|
|
926
|
+
*
|
|
927
|
+
* Specify the amount in the token's atomic units (e.g., for USDC with
|
|
928
|
+
* 6 decimals, "1000000" represents 1 USDC). This amount will be burned
|
|
929
|
+
* on the source chain and minted on the destination chain.
|
|
930
|
+
*/
|
|
931
|
+
amount: bigint;
|
|
932
|
+
/**
|
|
933
|
+
* Address of the recipient who will receive minted tokens on the destination chain.
|
|
934
|
+
*
|
|
935
|
+
* Provide the destination address as a 32-byte hex string (bytes32 format).
|
|
936
|
+
*/
|
|
937
|
+
mintRecipient: string;
|
|
938
|
+
/**
|
|
939
|
+
* Address authorized to call receiveMessage on the destination chain.
|
|
940
|
+
*
|
|
941
|
+
* Restrict who can execute the final minting step on the destination chain.
|
|
942
|
+
* If not specified or set to bytes32(0), any address can call receiveMessage.
|
|
943
|
+
* Use this for advanced integrations requiring specific execution control.
|
|
944
|
+
*
|
|
945
|
+
* @defaultValue bytes32(0) - allows any address to complete the transfer
|
|
946
|
+
*/
|
|
947
|
+
destinationCaller?: string;
|
|
948
|
+
/**
|
|
949
|
+
* Maximum fee to pay for fast transfer fulfillment.
|
|
950
|
+
*
|
|
951
|
+
* Specify the maximum amount (in the same units as `amount`) you're willing
|
|
952
|
+
* to pay for immediate liquidity. Set to "0" for free transfers that wait
|
|
953
|
+
* for full chain finality. Higher fees increase the likelihood of fast
|
|
954
|
+
* fulfillment.
|
|
955
|
+
*/
|
|
956
|
+
maxFee: bigint;
|
|
957
|
+
/**
|
|
958
|
+
* Minimum finality threshold for attestation eligibility.
|
|
959
|
+
*
|
|
960
|
+
* Set the number of confirmations required before Circle's attestation
|
|
961
|
+
* service will observe and attest to the burn event. Higher values
|
|
962
|
+
* provide stronger finality guarantees but increase transfer time.
|
|
963
|
+
* Typical values: 1000 for fast transfers, 2000 for maximum security.
|
|
964
|
+
*/
|
|
965
|
+
minFinalityThreshold: number;
|
|
966
|
+
/**
|
|
967
|
+
* Source chain definition where tokens will be burned.
|
|
968
|
+
*/
|
|
969
|
+
fromChain: ChainDefinitionWithCCTPv2;
|
|
970
|
+
/**
|
|
971
|
+
* Destination chain definition where tokens will be minted.
|
|
972
|
+
*/
|
|
973
|
+
toChain: ChainDefinitionWithCCTPv2;
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* Complete a cross-chain transfer by receiving and processing an attested message.
|
|
977
|
+
*
|
|
978
|
+
* Execute the final step of a CCTP transfer by submitting Circle's attestation
|
|
979
|
+
* and the original message to mint USDC tokens on the destination chain.
|
|
980
|
+
* This action consumes the attestation and delivers tokens to the specified
|
|
981
|
+
* recipient from the original burn operation.
|
|
982
|
+
*
|
|
983
|
+
* @remarks
|
|
984
|
+
* This action must be called after obtaining a valid attestation from Circle's
|
|
985
|
+
* API for a corresponding `depositForBurn` operation. The attestation proves
|
|
986
|
+
* that tokens were burned on the source chain and authorizes minting the
|
|
987
|
+
* equivalent amount on the destination chain.
|
|
988
|
+
*
|
|
989
|
+
* The message parameter contains the original burn message data, while the
|
|
990
|
+
* attestation provides the cryptographic proof. Both must match exactly
|
|
991
|
+
* with Circle's records for the transaction to succeed.
|
|
992
|
+
*/
|
|
993
|
+
receiveMessage: ActionParameters & {
|
|
994
|
+
/**
|
|
995
|
+
* Unique nonce identifying the specific burn event.
|
|
996
|
+
*
|
|
997
|
+
* Provide the event nonce from the MessageSent event emitted by the
|
|
998
|
+
* depositForBurn transaction. This must be a 0x-prefixed 64-character
|
|
999
|
+
* hex string representing the 32-byte nonce value.
|
|
1000
|
+
*/
|
|
1001
|
+
readonly eventNonce: string;
|
|
1002
|
+
/**
|
|
1003
|
+
* Cryptographic attestation from Circle's infrastructure.
|
|
1004
|
+
*
|
|
1005
|
+
* Submit the attestation obtained from Circle's API that proves the
|
|
1006
|
+
* corresponding burn event occurred and was observed. This must be
|
|
1007
|
+
* a valid 0x-prefixed hex string containing Circle's signature data.
|
|
1008
|
+
*/
|
|
1009
|
+
readonly attestation: string;
|
|
1010
|
+
/**
|
|
1011
|
+
* Original message bytes from the source chain burn event.
|
|
1012
|
+
*
|
|
1013
|
+
* Provide the raw message data emitted in the MessageSent event from
|
|
1014
|
+
* the depositForBurn transaction. This 0x-prefixed hex string contains
|
|
1015
|
+
* the encoded transfer details that will be verified against the attestation.
|
|
1016
|
+
*/
|
|
1017
|
+
readonly message: string;
|
|
1018
|
+
/**
|
|
1019
|
+
* Source chain definition where the original burn occurred.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly fromChain: ChainDefinitionWithCCTPv2;
|
|
1022
|
+
/**
|
|
1023
|
+
* Destination chain definition where tokens will be minted.
|
|
1024
|
+
*/
|
|
1025
|
+
readonly toChain: ChainDefinitionWithCCTPv2;
|
|
1026
|
+
};
|
|
1027
|
+
/**
|
|
1028
|
+
* Initiate a cross-chain USDC transfer using a custom bridge contract with preapproval funnel.
|
|
1029
|
+
*
|
|
1030
|
+
* This action combines token approval and burning into a single transaction using
|
|
1031
|
+
* a custom bridge contract that supports preapproval functionality. It provides
|
|
1032
|
+
* enhanced gas efficiency by eliminating separate approval transactions while
|
|
1033
|
+
* maintaining the same developer interface as standard CCTP transfers.
|
|
1034
|
+
*
|
|
1035
|
+
* @remarks
|
|
1036
|
+
* This action is only available on chains that support custom bridge contracts,
|
|
1037
|
+
* as determined by `hasCustomContractSupport(chain, 'bridge')`. The custom bridge
|
|
1038
|
+
* handles token approval internally and supports advanced features like protocol
|
|
1039
|
+
* fees and custom routing logic.
|
|
1040
|
+
*
|
|
1041
|
+
* For basic use cases, this provides the same interface as `depositForBurn`.
|
|
1042
|
+
* For advanced use cases, optional protocol fee parameters enable custom fee
|
|
1043
|
+
* collection and revenue sharing models.
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```typescript
|
|
1047
|
+
* // Basic usage (same as depositForBurn)
|
|
1048
|
+
* await adapter.action('cctp.v2.customBurn', {
|
|
1049
|
+
* amount: BigInt('1000000'),
|
|
1050
|
+
* mintRecipient: '0x...',
|
|
1051
|
+
* maxFee: BigInt('1000'),
|
|
1052
|
+
* minFinalityThreshold: 65
|
|
1053
|
+
* })
|
|
1054
|
+
*
|
|
1055
|
+
* // Advanced usage with protocol fees
|
|
1056
|
+
* await adapter.action('cctp.v2.customBurn', {
|
|
1057
|
+
* amount: BigInt('1000000'),
|
|
1058
|
+
* mintRecipient: '0x...',
|
|
1059
|
+
* maxFee: BigInt('1000'),
|
|
1060
|
+
* minFinalityThreshold: 65,
|
|
1061
|
+
* protocolFee: BigInt('100'),
|
|
1062
|
+
* feeRecipient: '0xFeeRecipientAddress'
|
|
1063
|
+
* })
|
|
1064
|
+
* ```
|
|
1065
|
+
*/
|
|
1066
|
+
customBurn: ActionParameters & {
|
|
1067
|
+
/**
|
|
1068
|
+
* Amount of USDC to burn (in token's smallest unit).
|
|
1069
|
+
*
|
|
1070
|
+
* Specify the amount in the token's atomic units (e.g., for USDC with
|
|
1071
|
+
* 6 decimals, 1000000n represents 1 USDC). This amount will be burned
|
|
1072
|
+
* on the source chain and minted on the destination chain.
|
|
1073
|
+
*/
|
|
1074
|
+
amount: bigint;
|
|
1075
|
+
/**
|
|
1076
|
+
* Address of the recipient who will receive minted tokens on the destination chain.
|
|
1077
|
+
*
|
|
1078
|
+
* Provide the destination address as a 32-byte hex string (bytes32 format).
|
|
1079
|
+
*/
|
|
1080
|
+
mintRecipient: string;
|
|
1081
|
+
/**
|
|
1082
|
+
* Address authorized to call receiveMessage on the destination chain.
|
|
1083
|
+
*
|
|
1084
|
+
* Restrict who can execute the final minting step on the destination chain.
|
|
1085
|
+
* If not specified or set to bytes32(0), any address can call receiveMessage.
|
|
1086
|
+
* Use this for advanced integrations requiring specific execution control.
|
|
1087
|
+
*
|
|
1088
|
+
* @defaultValue bytes32(0) - allows any address to complete the transfer
|
|
1089
|
+
*/
|
|
1090
|
+
destinationCaller?: string;
|
|
1091
|
+
/**
|
|
1092
|
+
* Maximum fee to pay for fast transfer fulfillment.
|
|
1093
|
+
*
|
|
1094
|
+
* Specify the maximum amount (in the same units as `amount`) you're willing
|
|
1095
|
+
* to pay for immediate liquidity. Set to "0" for free transfers that wait
|
|
1096
|
+
* for full chain finality. Higher fees increase the likelihood of fast
|
|
1097
|
+
* fulfillment.
|
|
1098
|
+
*/
|
|
1099
|
+
maxFee: bigint;
|
|
1100
|
+
/**
|
|
1101
|
+
* Minimum finality threshold for attestation eligibility.
|
|
1102
|
+
*
|
|
1103
|
+
* Set the number of confirmations required before Circle's attestation
|
|
1104
|
+
* service will observe and attest to the burn event. Higher values
|
|
1105
|
+
* provide stronger finality guarantees but increase transfer time.
|
|
1106
|
+
* Typical values: 65 for standard transfers, 2000 for maximum security.
|
|
1107
|
+
*/
|
|
1108
|
+
minFinalityThreshold: number;
|
|
1109
|
+
/**
|
|
1110
|
+
* Protocol fee amount (in token's smallest unit).
|
|
1111
|
+
*
|
|
1112
|
+
* Additional fee charged by the custom bridge for enhanced functionality.
|
|
1113
|
+
* This fee is separate from the Circle fast transfer fee and is paid to
|
|
1114
|
+
* the specified fee recipient. Enables custom fee collection and revenue
|
|
1115
|
+
* sharing models for bridge operators.
|
|
1116
|
+
*
|
|
1117
|
+
* @defaultValue 0n - no protocol fee for basic usage
|
|
1118
|
+
*/
|
|
1119
|
+
protocolFee?: bigint;
|
|
1120
|
+
/**
|
|
1121
|
+
* Address to receive the protocol fee.
|
|
1122
|
+
*
|
|
1123
|
+
* Wallet address where the protocol fee will be sent. This enables
|
|
1124
|
+
* custom fee collection and revenue sharing models for bridge operators.
|
|
1125
|
+
* Only relevant when protocolFee is greater than 0.
|
|
1126
|
+
*
|
|
1127
|
+
* @defaultValue bridge contract address - safe fallback for zero fees
|
|
1128
|
+
*/
|
|
1129
|
+
feeRecipient?: string;
|
|
1130
|
+
/**
|
|
1131
|
+
* Source chain definition where tokens will be burned.
|
|
1132
|
+
*/
|
|
1133
|
+
fromChain: ChainDefinitionWithCCTPv2;
|
|
1134
|
+
/**
|
|
1135
|
+
* Destination chain definition where tokens will be minted.
|
|
1136
|
+
*/
|
|
1137
|
+
toChain: ChainDefinitionWithCCTPv2;
|
|
1138
|
+
/**
|
|
1139
|
+
* Permit parameters for the custom bridge contract.
|
|
1140
|
+
*/
|
|
1141
|
+
permitParams?: PermitParams;
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Central registry for Cross-Chain Transfer Protocol (CCTP) action namespaces.
|
|
1147
|
+
*
|
|
1148
|
+
* Define versioned action maps for CCTP operations across different protocol
|
|
1149
|
+
* versions. Each version key represents a specific CCTP implementation with
|
|
1150
|
+
* its own parameter schemas and operational requirements.
|
|
1151
|
+
*
|
|
1152
|
+
* @remarks
|
|
1153
|
+
* CCTP actions enable cross-chain USDC transfers through Circle's native
|
|
1154
|
+
* bridging protocol. Each version namespace contains actions specific to
|
|
1155
|
+
* that protocol iteration, allowing for protocol upgrades while maintaining
|
|
1156
|
+
* backward compatibility in the action system.
|
|
1157
|
+
*
|
|
1158
|
+
* This interface follows the same pattern as other action namespaces but
|
|
1159
|
+
* is organized by protocol version rather than token type.
|
|
1160
|
+
*
|
|
1161
|
+
* @see {@link CCTPv2ActionMap} for version 2 action definitions
|
|
1162
|
+
*/
|
|
1163
|
+
interface CCTPActionMap {
|
|
1164
|
+
/** CCTP version 2 operations for cross-chain USDC transfers. */
|
|
1165
|
+
readonly v2: CCTPv2ActionMap;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
interface TokenActionMap {
|
|
1169
|
+
/**
|
|
1170
|
+
* Set an allowance for a delegate to spend tokens on behalf of the wallet.
|
|
1171
|
+
*
|
|
1172
|
+
* On chains without native allowance support, this may return a noop result
|
|
1173
|
+
* indicating the step can be safely skipped.
|
|
1174
|
+
*/
|
|
1175
|
+
approve: ActionParameters & {
|
|
1176
|
+
/**
|
|
1177
|
+
* The contract address of the token.
|
|
1178
|
+
*/
|
|
1179
|
+
tokenAddress: string;
|
|
1180
|
+
/**
|
|
1181
|
+
* The address that will be approved to spend the tokens.
|
|
1182
|
+
*/
|
|
1183
|
+
delegate: string;
|
|
1184
|
+
/**
|
|
1185
|
+
* The amount of tokens to approve for spending (in token's smallest unit).
|
|
1186
|
+
*/
|
|
1187
|
+
amount: bigint;
|
|
1188
|
+
};
|
|
1189
|
+
/**
|
|
1190
|
+
* Check the current allowance between an owner and spender for any token.
|
|
1191
|
+
*
|
|
1192
|
+
* On chains without allowance support, this typically returns the maximum
|
|
1193
|
+
* possible value to indicate unlimited spending capability.
|
|
1194
|
+
*/
|
|
1195
|
+
allowance: ActionParameters & {
|
|
1196
|
+
/**
|
|
1197
|
+
* The contract address of the token.
|
|
1198
|
+
*/
|
|
1199
|
+
tokenAddress: string;
|
|
1200
|
+
/**
|
|
1201
|
+
* The address of the wallet that owns the tokens. If not provided, it will be
|
|
1202
|
+
* automatically derived from the adapter context.
|
|
1203
|
+
*/
|
|
1204
|
+
walletAddress?: string | undefined;
|
|
1205
|
+
/**
|
|
1206
|
+
* The address to check the allowance for.
|
|
1207
|
+
*/
|
|
1208
|
+
delegate: string;
|
|
1209
|
+
};
|
|
1210
|
+
/**
|
|
1211
|
+
* Transfer tokens directly from the wallet to another address.
|
|
1212
|
+
*/
|
|
1213
|
+
transfer: ActionParameters & {
|
|
1214
|
+
/**
|
|
1215
|
+
* The contract address of the token.
|
|
1216
|
+
*/
|
|
1217
|
+
tokenAddress: string;
|
|
1218
|
+
/**
|
|
1219
|
+
* The address to send the tokens to.
|
|
1220
|
+
*/
|
|
1221
|
+
to: string;
|
|
1222
|
+
/**
|
|
1223
|
+
* The amount of tokens to transfer (in token's smallest unit).
|
|
1224
|
+
*/
|
|
1225
|
+
amount: bigint;
|
|
1226
|
+
};
|
|
1227
|
+
/**
|
|
1228
|
+
* Transfer tokens from one address to another using a pre-approved allowance.
|
|
1229
|
+
*
|
|
1230
|
+
* On chains without allowance support, this may behave differently or throw
|
|
1231
|
+
* an error if the operation is not supported.
|
|
1232
|
+
*/
|
|
1233
|
+
transferFrom: ActionParameters & {
|
|
1234
|
+
/**
|
|
1235
|
+
* The contract address of the token.
|
|
1236
|
+
*/
|
|
1237
|
+
tokenAddress: string;
|
|
1238
|
+
/**
|
|
1239
|
+
* The address to transfer tokens from (must have given allowance to the caller).
|
|
1240
|
+
*/
|
|
1241
|
+
from: string;
|
|
1242
|
+
/**
|
|
1243
|
+
* The address to send the tokens to.
|
|
1244
|
+
*/
|
|
1245
|
+
to: string;
|
|
1246
|
+
/**
|
|
1247
|
+
* The amount of tokens to transfer (in token's smallest unit).
|
|
1248
|
+
*/
|
|
1249
|
+
amount: bigint;
|
|
1250
|
+
};
|
|
1251
|
+
/**
|
|
1252
|
+
* Get the current token balance for a wallet address.
|
|
1253
|
+
*/
|
|
1254
|
+
balanceOf: ActionParameters & {
|
|
1255
|
+
/**
|
|
1256
|
+
* The contract address of the token.
|
|
1257
|
+
*/
|
|
1258
|
+
tokenAddress: string;
|
|
1259
|
+
/**
|
|
1260
|
+
* The address to check the balance for. If not provided, it will be
|
|
1261
|
+
* automatically derived from the adapter context.
|
|
1262
|
+
*/
|
|
1263
|
+
walletAddress?: string | undefined;
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* USDC-specific operations that automatically resolve the token address.
|
|
1269
|
+
*
|
|
1270
|
+
* These include all standard ERC20 operations plus additional safety functions
|
|
1271
|
+
* that USDC supports. The interface provides the same core operations as
|
|
1272
|
+
* {@link TokenActionMap} but without requiring a `tokenAddress` parameter,
|
|
1273
|
+
* plus additional USDC-specific extensions.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```typescript
|
|
1277
|
+
* // USDC operations (address auto-resolved)
|
|
1278
|
+
* await adapter.action('usdc.approve', {
|
|
1279
|
+
* delegate: '0x1234...',
|
|
1280
|
+
* amount: '1000000' // 1 USDC
|
|
1281
|
+
* })
|
|
1282
|
+
*
|
|
1283
|
+
* // USDC-specific safe allowance functions
|
|
1284
|
+
* await adapter.action('usdc.increaseAllowance', {
|
|
1285
|
+
* delegate: '0x1234...',
|
|
1286
|
+
* amount: '500000' // increase by 0.5 USDC
|
|
1287
|
+
* })
|
|
1288
|
+
*
|
|
1289
|
+
* // vs. general token operations (address required)
|
|
1290
|
+
* await adapter.action('token.approve', {
|
|
1291
|
+
* tokenAddress: '0xA0b86a33E6441c8C1c7C16e4c5e3e5b5e4c5e3e5b5e4c5e',
|
|
1292
|
+
* delegate: '0x1234...',
|
|
1293
|
+
* amount: '1000000'
|
|
1294
|
+
* })
|
|
1295
|
+
* ```
|
|
1296
|
+
*/
|
|
1297
|
+
type BaseUSDCActions = {
|
|
1298
|
+
[K in keyof TokenActionMap]: Omit<TokenActionMap[K], 'tokenAddress'>;
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* USDC action map with both standard ERC20 operations and USDC-specific extensions.
|
|
1302
|
+
*
|
|
1303
|
+
* This provides all standard token operations plus additional safety functions
|
|
1304
|
+
* that USDC implements beyond the base ERC20 standard.
|
|
1305
|
+
*/
|
|
1306
|
+
interface USDCActionMap {
|
|
1307
|
+
/**
|
|
1308
|
+
* Set an allowance for a delegate to spend USDC tokens on behalf of the wallet.
|
|
1309
|
+
*
|
|
1310
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1311
|
+
* On chains without native allowance support, this may return a noop result.
|
|
1312
|
+
*/
|
|
1313
|
+
approve: BaseUSDCActions['approve'];
|
|
1314
|
+
/**
|
|
1315
|
+
* Check the current allowance between an owner and spender for USDC tokens.
|
|
1316
|
+
*
|
|
1317
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1318
|
+
* This is a read-only operation.
|
|
1319
|
+
*/
|
|
1320
|
+
allowance: BaseUSDCActions['allowance'];
|
|
1321
|
+
/**
|
|
1322
|
+
* Safely increase the allowance for a delegate to spend USDC tokens.
|
|
1323
|
+
*
|
|
1324
|
+
* This is a USDC-specific function that provides safer allowance management
|
|
1325
|
+
* compared to direct approve() calls. Automatically uses the USDC contract
|
|
1326
|
+
* address for the current chain.
|
|
1327
|
+
*/
|
|
1328
|
+
increaseAllowance: ActionParameters & {
|
|
1329
|
+
/**
|
|
1330
|
+
* The address that will have their allowance increased.
|
|
1331
|
+
*/
|
|
1332
|
+
delegate: string;
|
|
1333
|
+
/**
|
|
1334
|
+
* The amount to increase the allowance by (in USDC's smallest unit).
|
|
1335
|
+
*/
|
|
1336
|
+
amount: bigint;
|
|
1337
|
+
/**
|
|
1338
|
+
* The chain definition for the current chain.
|
|
1339
|
+
*/
|
|
1340
|
+
chain?: ChainDefinition;
|
|
1341
|
+
};
|
|
1342
|
+
/**
|
|
1343
|
+
* Safely decrease the allowance for a delegate to spend USDC tokens.
|
|
1344
|
+
*
|
|
1345
|
+
* This is a USDC-specific function that provides safer allowance management.
|
|
1346
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1347
|
+
*/
|
|
1348
|
+
decreaseAllowance: ActionParameters & {
|
|
1349
|
+
/**
|
|
1350
|
+
* The address that will have their allowance decreased.
|
|
1351
|
+
*/
|
|
1352
|
+
delegate: string;
|
|
1353
|
+
/**
|
|
1354
|
+
* The amount to decrease the allowance by (in USDC's smallest unit).
|
|
1355
|
+
*/
|
|
1356
|
+
amount: bigint;
|
|
1357
|
+
};
|
|
1358
|
+
/**
|
|
1359
|
+
* Transfer USDC tokens directly from the wallet to another address.
|
|
1360
|
+
*
|
|
1361
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1362
|
+
*/
|
|
1363
|
+
transfer: BaseUSDCActions['transfer'];
|
|
1364
|
+
/**
|
|
1365
|
+
* Transfer USDC tokens from one address to another using a pre-approved allowance.
|
|
1366
|
+
*
|
|
1367
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1368
|
+
* The caller must have sufficient allowance from the 'from' address.
|
|
1369
|
+
*/
|
|
1370
|
+
transferFrom: BaseUSDCActions['transferFrom'];
|
|
1371
|
+
/**
|
|
1372
|
+
* Get the current USDC balance for a wallet address.
|
|
1373
|
+
*
|
|
1374
|
+
* Automatically uses the USDC contract address for the current chain.
|
|
1375
|
+
* This is a read-only operation.
|
|
1376
|
+
*/
|
|
1377
|
+
balanceOf: Omit<BaseUSDCActions['balanceOf'], 'tokenAddress'>;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* Central registry of all available action namespaces and their operations.
|
|
1382
|
+
*
|
|
1383
|
+
* Define the complete action map structure used throughout the bridging kit.
|
|
1384
|
+
* Each top-level key represents a namespace (e.g., 'token', 'usdc') containing
|
|
1385
|
+
* related operations. The structure supports arbitrary nesting depth through
|
|
1386
|
+
* the recursive utility types provided in this module.
|
|
1387
|
+
*
|
|
1388
|
+
* @remarks
|
|
1389
|
+
* This interface serves as the foundation for type-safe action dispatching
|
|
1390
|
+
* and provides compile-time validation of action keys and payload types.
|
|
1391
|
+
* All action-related utility types derive from this central definition.
|
|
1392
|
+
*
|
|
1393
|
+
* @see {@link ActionKeys} for dot-notation action paths
|
|
1394
|
+
* @see {@link ActionPayload} for extracting payload types
|
|
1395
|
+
*/
|
|
1396
|
+
interface ActionMap {
|
|
1397
|
+
/** CCTP-specific operations with automatic address resolution. */
|
|
1398
|
+
readonly cctp: CCTPActionMap;
|
|
1399
|
+
/** General token operations requiring explicit token addresses. */
|
|
1400
|
+
readonly token: TokenActionMap;
|
|
1401
|
+
/** USDC-specific operations with automatic address resolution. */
|
|
1402
|
+
readonly usdc: USDCActionMap;
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* Determine if a type represents an action parameter object (leaf node).
|
|
1406
|
+
*
|
|
1407
|
+
* Check whether a type extends the ActionParameters interface, which provides
|
|
1408
|
+
* an explicit marker for identifying action parameter objects versus namespace
|
|
1409
|
+
* containers that should be traversed during type recursion.
|
|
1410
|
+
*
|
|
1411
|
+
* @typeParam T - The type to examine for parameter object characteristics
|
|
1412
|
+
*
|
|
1413
|
+
* @remarks
|
|
1414
|
+
* This utility type provides deterministic leaf detection for the recursive
|
|
1415
|
+
* type system. By requiring all action parameter objects to extend the
|
|
1416
|
+
* ActionParameters interface, we eliminate the need for property name
|
|
1417
|
+
* heuristics and make the system more maintainable.
|
|
1418
|
+
*
|
|
1419
|
+
* @see {@link ActionParameters} for the base interface
|
|
1420
|
+
* @see {@link NestedKeys} for usage in path extraction
|
|
1421
|
+
*/
|
|
1422
|
+
type IsActionParameterObject<T> = T extends ActionParameters ? true : false;
|
|
1423
|
+
/**
|
|
1424
|
+
* Recursively extract all nested keys from an object type as dot-notation string literals.
|
|
1425
|
+
*
|
|
1426
|
+
* Traverse object structures of arbitrary depth and generate string literal
|
|
1427
|
+
* types representing all possible paths through the structure using dot
|
|
1428
|
+
* notation. Stop recursion when encountering action parameter objects (leaves).
|
|
1429
|
+
*
|
|
1430
|
+
* @typeParam T - The object type to extract nested keys from
|
|
1431
|
+
*
|
|
1432
|
+
* @remarks
|
|
1433
|
+
* This type is the foundation for generating type-safe action paths in
|
|
1434
|
+
* dot notation. It automatically adapts to changes in the ActionMap
|
|
1435
|
+
* structure and supports unlimited nesting depth for future extensibility.
|
|
1436
|
+
*
|
|
1437
|
+
* The recursion stops when it encounters objects that match the
|
|
1438
|
+
* {@link IsActionParameterObject} criteria, ensuring that only valid
|
|
1439
|
+
* action paths are generated.
|
|
1440
|
+
*
|
|
1441
|
+
* @see {@link ActionKeys} for ActionMap-specific paths
|
|
1442
|
+
* @see {@link NestedValue} for extracting types at specific paths
|
|
1443
|
+
* @see {@link IsActionParameterObject} for leaf detection logic
|
|
1444
|
+
*/
|
|
1445
|
+
type NestedKeys<T> = {
|
|
1446
|
+
[K in Extract<keyof T, string>]: IsActionParameterObject<T[K]> extends true ? K : T[K] extends object ? `${K}.${NestedKeys<T[K]>}` : never;
|
|
1447
|
+
}[Extract<keyof T, string>];
|
|
1448
|
+
/**
|
|
1449
|
+
* Recursively extract the value type at a given dot-notation path.
|
|
1450
|
+
*
|
|
1451
|
+
* Navigate through nested object types using a dot-notation string path
|
|
1452
|
+
* and return the type of the value at that location. Parse the path
|
|
1453
|
+
* recursively by splitting on dots and traversing the object structure.
|
|
1454
|
+
*
|
|
1455
|
+
* @typeParam T - The object type to navigate through
|
|
1456
|
+
* @typeParam K - The dot-notation path as a string literal type
|
|
1457
|
+
*
|
|
1458
|
+
* @remarks
|
|
1459
|
+
* This utility type enables type-safe access to deeply nested object
|
|
1460
|
+
* properties using dot notation paths. It forms the foundation for
|
|
1461
|
+
* extracting payload types from action paths in the ActionMap.
|
|
1462
|
+
*
|
|
1463
|
+
* @see {@link ActionPayload} for ActionMap-specific value extraction
|
|
1464
|
+
* @see {@link NestedKeys} for generating valid path types
|
|
1465
|
+
*/
|
|
1466
|
+
type NestedValue<T, K extends string> = K extends `${infer First}.${infer Rest}` ? First extends keyof T ? NestedValue<T[First], Rest> : never : K extends keyof T ? T[K] : never;
|
|
1467
|
+
/**
|
|
1468
|
+
* Union type of all nested action keys in dot notation.
|
|
1469
|
+
*
|
|
1470
|
+
* Generate string literal types for all possible action paths in the
|
|
1471
|
+
* ActionMap structure. Automatically adapt to changes in the ActionMap
|
|
1472
|
+
* and support arbitrary levels of nesting for future extensibility.
|
|
1473
|
+
*
|
|
1474
|
+
* @remarks
|
|
1475
|
+
* This type serves as the canonical source for all valid action identifiers
|
|
1476
|
+
* in the bridging kit. It ensures compile-time validation of action keys
|
|
1477
|
+
* and enables type-safe action dispatching throughout the application.
|
|
1478
|
+
*
|
|
1479
|
+
* @see {@link ActionPayload} for extracting parameter types
|
|
1480
|
+
* @see {@link NamespaceActions} for namespace-specific actions
|
|
1481
|
+
* @see {@link ActionMap} for the underlying structure
|
|
1482
|
+
*/
|
|
1483
|
+
type ActionKeys = NestedKeys<ActionMap>;
|
|
1484
|
+
/**
|
|
1485
|
+
* Extract the payload type for a specific action based on its dot-notation key.
|
|
1486
|
+
*
|
|
1487
|
+
* Resolve the parameter type for any action by providing its complete path
|
|
1488
|
+
* in dot notation. Leverage the recursive NestedValue type to navigate to
|
|
1489
|
+
* the correct payload type regardless of nesting depth. The internal
|
|
1490
|
+
* ActionParameters marker is automatically removed from the result.
|
|
1491
|
+
*
|
|
1492
|
+
* @typeParam T - The action key in dot notation (must extend ActionKeys)
|
|
1493
|
+
*
|
|
1494
|
+
* @remarks
|
|
1495
|
+
* This utility type enables type-safe parameter passing for action
|
|
1496
|
+
* dispatching. It automatically infers the correct parameter shape
|
|
1497
|
+
* based on the action key, providing compile-time validation and
|
|
1498
|
+
* excellent IntelliSense support.
|
|
1499
|
+
*
|
|
1500
|
+
* The internal `__isActionParams` marker used for type system recursion
|
|
1501
|
+
* is automatically omitted from the resulting type, providing clean
|
|
1502
|
+
* parameter objects for consumers.
|
|
1503
|
+
*
|
|
1504
|
+
* @see {@link ActionKeys} for available action identifiers
|
|
1505
|
+
* @see {@link NestedValue} for the underlying path resolution logic
|
|
1506
|
+
*/
|
|
1507
|
+
type ActionPayload<T extends ActionKeys> = Omit<NestedValue<ActionMap, T>, '__isActionParams'>;
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* Type-safe action handler function signature for specific action types.
|
|
1511
|
+
*
|
|
1512
|
+
* Defines the contract for functions that process action payloads and return
|
|
1513
|
+
* prepared chain requests. Each handler is strongly typed to accept only the
|
|
1514
|
+
* payload structure corresponding to its specific action key.
|
|
1515
|
+
*
|
|
1516
|
+
* @typeParam TActionKey - The specific action key this handler processes.
|
|
1517
|
+
* @param params - The action payload matching the specified action key.
|
|
1518
|
+
* @returns A promise resolving to a prepared chain request.
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```typescript
|
|
1522
|
+
* import type { ActionHandler } from '@core/adapter'
|
|
1523
|
+
*
|
|
1524
|
+
* const depositHandler: ActionHandler<'cctp.v2.depositForBurn'> = async (params) => {
|
|
1525
|
+
* // Handler logic here
|
|
1526
|
+
* }
|
|
1527
|
+
* ```
|
|
1528
|
+
*/
|
|
1529
|
+
type ActionHandler<TActionKey extends ActionKeys> = (params: ActionPayload<TActionKey>) => Promise<PreparedChainRequest>;
|
|
1530
|
+
/**
|
|
1531
|
+
* Type-safe mapping of all available action keys to their corresponding handlers.
|
|
1532
|
+
*
|
|
1533
|
+
* This type defines a registry object where each key is a valid action key
|
|
1534
|
+
* (as defined by {@link ActionKeys}) and each value is an {@link ActionHandler}
|
|
1535
|
+
* capable of processing the payload for that action. This enables strongly-typed
|
|
1536
|
+
* handler registration and lookup for all supported actions in the Stablecoin Kits.
|
|
1537
|
+
*
|
|
1538
|
+
* @remarks
|
|
1539
|
+
* Each handler is typed as {@link ActionHandler<ActionKeys>}, which means the handler
|
|
1540
|
+
* must accept the payload type for the specific action key it is registered under.
|
|
1541
|
+
* This provides type safety for handler registration and execution, but does not
|
|
1542
|
+
* enforce per-key handler parameterization at the type level. For stricter per-key
|
|
1543
|
+
* typing, consider using mapped types or generic registry patterns.
|
|
1544
|
+
*
|
|
1545
|
+
* @example
|
|
1546
|
+
* ```typescript
|
|
1547
|
+
* import type { ActionHandlers } from '@core/adapter'
|
|
1548
|
+
* import type { ActionHandler } from '@core/adapter'
|
|
1549
|
+
*
|
|
1550
|
+
* const handlers: ActionHandlers = {
|
|
1551
|
+
* 'cctp.v2.depositForBurn': async (params) => {
|
|
1552
|
+
* // params is correctly typed for 'cctp.v2.depositForBurn'
|
|
1553
|
+
* // ...handler logic...
|
|
1554
|
+
* },
|
|
1555
|
+
* 'usdc.approve': async (params) => {
|
|
1556
|
+
* // params is correctly typed for 'usdc.approve'
|
|
1557
|
+
* // ...handler logic...
|
|
1558
|
+
* }
|
|
1559
|
+
* }
|
|
1560
|
+
* ```
|
|
1561
|
+
*/
|
|
1562
|
+
type ActionHandlers = {
|
|
1563
|
+
[K in ActionKeys]?: ActionHandler<K>;
|
|
1564
|
+
};
|
|
1565
|
+
/**
|
|
1566
|
+
* Type-safe registry for managing and executing blockchain action handlers.
|
|
1567
|
+
*
|
|
1568
|
+
* Provides a centralized system for registering action handlers with full
|
|
1569
|
+
* TypeScript type safety, ensuring that handlers can only be registered
|
|
1570
|
+
* with compatible action keys and payload types. Supports both individual
|
|
1571
|
+
* handler registration and batch registration operations.
|
|
1572
|
+
*
|
|
1573
|
+
* @remarks
|
|
1574
|
+
* The registry uses a Map internally for O(1) lookups and maintains type
|
|
1575
|
+
* safety through generic constraints and careful type assertions. All
|
|
1576
|
+
* type assertions are validated at registration time to ensure runtime
|
|
1577
|
+
* type safety matches compile-time guarantees.
|
|
1578
|
+
*/
|
|
1579
|
+
declare class ActionRegistry {
|
|
1580
|
+
readonly actionHandlers: Map<ActionKeys, ActionHandler<ActionKeys>>;
|
|
1581
|
+
/**
|
|
1582
|
+
* Register a type-safe action handler for a specific action key.
|
|
1583
|
+
*
|
|
1584
|
+
* Associates an action handler function with its corresponding action key,
|
|
1585
|
+
* ensuring compile-time type safety between the action and its expected
|
|
1586
|
+
* payload structure. The handler will be available for execution via
|
|
1587
|
+
* {@link executeAction}.
|
|
1588
|
+
*
|
|
1589
|
+
* @typeParam TActionKey - The specific action key being registered.
|
|
1590
|
+
* @param action - The action key to register the handler for.
|
|
1591
|
+
* @param handler - The handler function for processing this action type.
|
|
1592
|
+
* @returns Void.
|
|
1593
|
+
*
|
|
1594
|
+
* @throws {Error} When action parameter is not a valid string.
|
|
1595
|
+
* @throws {TypeError} When handler parameter is not a function.
|
|
1596
|
+
*
|
|
1597
|
+
* @example
|
|
1598
|
+
* ```typescript
|
|
1599
|
+
* import { ActionRegistry } from '@core/adapter'
|
|
1600
|
+
* import type { ActionHandler } from '@core/adapter'
|
|
1601
|
+
*
|
|
1602
|
+
* const registry = new ActionRegistry()
|
|
1603
|
+
*
|
|
1604
|
+
* // Register a CCTP deposit handler
|
|
1605
|
+
* const depositHandler: ActionHandler<'cctp.v2.depositForBurn'> = async (params) => {
|
|
1606
|
+
* console.log('Processing deposit:', params.amount)
|
|
1607
|
+
* return {
|
|
1608
|
+
* chainId: params.chainId,
|
|
1609
|
+
* data: '0x...',
|
|
1610
|
+
* to: '0x...',
|
|
1611
|
+
* value: '0'
|
|
1612
|
+
* }
|
|
1613
|
+
* }
|
|
1614
|
+
*
|
|
1615
|
+
* registry.registerHandler('cctp.v2.depositForBurn', depositHandler)
|
|
1616
|
+
* ```
|
|
1617
|
+
*/
|
|
1618
|
+
registerHandler<TActionKey extends ActionKeys>(action: TActionKey, handler: ActionHandler<TActionKey>): void;
|
|
1619
|
+
/**
|
|
1620
|
+
* Register multiple action handlers in a single operation.
|
|
1621
|
+
*
|
|
1622
|
+
* Efficiently register multiple handlers from a record object, where keys
|
|
1623
|
+
* are action identifiers and values are their corresponding handler
|
|
1624
|
+
* functions. Provides a convenient way to bulk-register handlers while
|
|
1625
|
+
* maintaining type safety.
|
|
1626
|
+
*
|
|
1627
|
+
* @param handlers - A record mapping action keys to their handler functions.
|
|
1628
|
+
* @returns Void.
|
|
1629
|
+
*
|
|
1630
|
+
* @throws {Error} When handlers parameter is not a valid object.
|
|
1631
|
+
* @throws {Error} When any individual handler registration fails.
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* ```typescript
|
|
1635
|
+
* import { ActionRegistry } from '@core/adapter'
|
|
1636
|
+
* import type { ActionHandler, ActionHandlers } from '@core/adapter'
|
|
1637
|
+
*
|
|
1638
|
+
* const registry = new ActionRegistry()
|
|
1639
|
+
*
|
|
1640
|
+
* // Register multiple handlers at once
|
|
1641
|
+
* const tokenHandlers: ActionHandlers = {
|
|
1642
|
+
* 'token.approve': async (params) => ({
|
|
1643
|
+
* chainId: params.chainId,
|
|
1644
|
+
* data: '0x095ea7b3...',
|
|
1645
|
+
* to: params.tokenAddress,
|
|
1646
|
+
* value: '0'
|
|
1647
|
+
* }),
|
|
1648
|
+
* 'token.transfer': async (params) => ({
|
|
1649
|
+
* chainId: params.chainId,
|
|
1650
|
+
* data: '0xa9059cbb...',
|
|
1651
|
+
* to: params.tokenAddress,
|
|
1652
|
+
* value: '0'
|
|
1653
|
+
* })
|
|
1654
|
+
* }
|
|
1655
|
+
*
|
|
1656
|
+
* registry.registerHandlers(tokenHandlers)
|
|
1657
|
+
* console.log('Registered multiple token handlers')
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
registerHandlers(handlers: ActionHandlers): void;
|
|
1661
|
+
/**
|
|
1662
|
+
* Check whether a specific action is supported by this registry.
|
|
1663
|
+
*
|
|
1664
|
+
* Determine if a handler has been registered for the given action key.
|
|
1665
|
+
* Use this method to conditionally execute actions or provide appropriate
|
|
1666
|
+
* error messages when actions are not available.
|
|
1667
|
+
*
|
|
1668
|
+
* @param action - The action key to check for support.
|
|
1669
|
+
* @returns True if the action is supported, false otherwise.
|
|
1670
|
+
*
|
|
1671
|
+
* @throws {Error} When action parameter is not a valid string.
|
|
1672
|
+
*
|
|
1673
|
+
* @example
|
|
1674
|
+
* ```typescript
|
|
1675
|
+
* import { ActionRegistry } from '@core/adapter'
|
|
1676
|
+
*
|
|
1677
|
+
* const registry = new ActionRegistry()
|
|
1678
|
+
*
|
|
1679
|
+
* // Check if actions are supported before attempting to use them
|
|
1680
|
+
* if (registry.supportsAction('token.approve')) {
|
|
1681
|
+
* console.log('Token approval is supported')
|
|
1682
|
+
* } else {
|
|
1683
|
+
* console.log('Token approval not available')
|
|
1684
|
+
* }
|
|
1685
|
+
*
|
|
1686
|
+
* // Conditional logic based on support
|
|
1687
|
+
* const action = 'cctp.v2.depositForBurn'
|
|
1688
|
+
* if (registry.supportsAction(action)) {
|
|
1689
|
+
* // Safe to execute
|
|
1690
|
+
* console.log(`${action} is available`)
|
|
1691
|
+
* } else {
|
|
1692
|
+
* console.warn(`${action} is not registered`)
|
|
1693
|
+
* }
|
|
1694
|
+
* ```
|
|
1695
|
+
*/
|
|
1696
|
+
supportsAction(action: ActionKeys): boolean;
|
|
1697
|
+
/**
|
|
1698
|
+
* Execute a registered action handler with type-safe parameters.
|
|
1699
|
+
*
|
|
1700
|
+
* Look up and execute the handler associated with the given action key,
|
|
1701
|
+
* passing the provided parameters and returning the resulting prepared
|
|
1702
|
+
* chain request. TypeScript ensures the parameters match the expected
|
|
1703
|
+
* structure for the specified action.
|
|
1704
|
+
*
|
|
1705
|
+
* @typeParam TActionKey - The specific action key being executed.
|
|
1706
|
+
* @param action - The action key identifying which handler to execute.
|
|
1707
|
+
* @param params - The parameters to pass to the action handler.
|
|
1708
|
+
* @returns A promise resolving to the prepared chain request.
|
|
1709
|
+
*
|
|
1710
|
+
* @throws {Error} When action parameter is not a valid string.
|
|
1711
|
+
* @throws {Error} When no handler is registered for the specified action.
|
|
1712
|
+
* @throws {Error} When the handler execution fails.
|
|
1713
|
+
*
|
|
1714
|
+
* @example
|
|
1715
|
+
* ```typescript
|
|
1716
|
+
* import { ActionRegistry } from '@core/adapter'
|
|
1717
|
+
* import type { ChainEnum } from '@core/chains'
|
|
1718
|
+
*
|
|
1719
|
+
* const registry = new ActionRegistry()
|
|
1720
|
+
*
|
|
1721
|
+
* // First register a handler
|
|
1722
|
+
* registry.registerHandler('token.approve', async (params) => ({
|
|
1723
|
+
* chainId: params.chainId,
|
|
1724
|
+
* data: '0x095ea7b3...',
|
|
1725
|
+
* to: params.tokenAddress,
|
|
1726
|
+
* value: '0'
|
|
1727
|
+
* }))
|
|
1728
|
+
*
|
|
1729
|
+
* // Execute the action with type-safe parameters
|
|
1730
|
+
* const result = await registry.executeAction('token.approve', {
|
|
1731
|
+
* chainId: ChainEnum.Ethereum,
|
|
1732
|
+
* tokenAddress: '0xA0b86a33E6441c8C1c7C16e4c5e3e5b5e4c5e3e5b5e4c5e',
|
|
1733
|
+
* delegate: '0x1234567890123456789012345678901234567890',
|
|
1734
|
+
* amount: '1000000'
|
|
1735
|
+
* })
|
|
1736
|
+
*
|
|
1737
|
+
* console.log('Transaction prepared:', result.data)
|
|
1738
|
+
* ```
|
|
1739
|
+
*/
|
|
1740
|
+
executeAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>): Promise<PreparedChainRequest>;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* Defines the capabilities of an adapter, including address handling patterns and supported chains.
|
|
1745
|
+
*
|
|
1746
|
+
* @interface AdapterCapabilities
|
|
1747
|
+
* @category Types
|
|
1748
|
+
* @description
|
|
1749
|
+
* This interface helps determine the behavior of an adapter, especially how it handles
|
|
1750
|
+
* address resolution and chain operations. Different adapter types have different
|
|
1751
|
+
* requirements for explicit context in operations.
|
|
1752
|
+
*
|
|
1753
|
+
* @example
|
|
1754
|
+
* ```typescript
|
|
1755
|
+
* // Single address adapter (private key)
|
|
1756
|
+
* const capabilities: AdapterCapabilities = {
|
|
1757
|
+
* addressContext: 'single',
|
|
1758
|
+
* supportedChains: [Ethereum, Base, Polygon],
|
|
1759
|
+
* availableAddresses: ['0x123...']
|
|
1760
|
+
* }
|
|
1761
|
+
*
|
|
1762
|
+
* // Multi-entity adapter (institutional)
|
|
1763
|
+
* const capabilities: AdapterCapabilities = {
|
|
1764
|
+
* addressContext: 'multi-entity',
|
|
1765
|
+
* supportedChains: [Ethereum, Base, Solana],
|
|
1766
|
+
* availableAddresses: undefined // Too many to fetch
|
|
1767
|
+
* }
|
|
1768
|
+
* ```
|
|
1769
|
+
*/
|
|
1770
|
+
interface AdapterCapabilities {
|
|
1771
|
+
/**
|
|
1772
|
+
* Defines how the adapter handles addresses.
|
|
1773
|
+
*
|
|
1774
|
+
* - `'single'`: Adapter controls exactly one address (e.g., private key adapter)
|
|
1775
|
+
* - `'user-accounts'`: Adapter controls user's personal addresses (e.g., MetaMask)
|
|
1776
|
+
* - `'multi-entity'`: Adapter manages addresses for multiple entities (e.g., Circle Wallets)
|
|
1777
|
+
*/
|
|
1778
|
+
addressContext: 'single' | 'user-accounts' | 'multi-entity';
|
|
1779
|
+
/**
|
|
1780
|
+
* List of blockchain networks that this adapter can interact with.
|
|
1781
|
+
* Used for validation and capability discovery.
|
|
1782
|
+
*/
|
|
1783
|
+
supportedChains: ChainDefinition[];
|
|
1784
|
+
/**
|
|
1785
|
+
* Available addresses for single and user-accounts adapters.
|
|
1786
|
+
*
|
|
1787
|
+
* - For `single` adapters: Contains exactly one address
|
|
1788
|
+
* - For `user-accounts` adapters: Contains user's available addresses
|
|
1789
|
+
* - For `multi-entity` adapters: Should be undefined (too many addresses to list)
|
|
1790
|
+
*
|
|
1791
|
+
* This is populated during adapter creation to avoid repeated network calls.
|
|
1792
|
+
*/
|
|
1793
|
+
availableAddresses?: string[];
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Abstract class defining the standard interface for an adapter that interacts with a specific blockchain.
|
|
1797
|
+
*
|
|
1798
|
+
* A `Adapter` is responsible for encapsulating chain-specific logic necessary to
|
|
1799
|
+
* perform operations like sending transactions, querying balances, or interacting with smart contracts.
|
|
1800
|
+
* Implementations of this class will provide concrete logic for a particular blockchain protocol.
|
|
1801
|
+
*
|
|
1802
|
+
* This abstraction allows the Stablecoin Kits to work with multiple blockchains in a uniform way.
|
|
1803
|
+
*
|
|
1804
|
+
*/
|
|
1805
|
+
declare abstract class Adapter {
|
|
1806
|
+
/**
|
|
1807
|
+
* The type of the chain.
|
|
1808
|
+
* @example 'evm', 'solana'
|
|
1809
|
+
*/
|
|
1810
|
+
abstract chainType: ChainType;
|
|
1811
|
+
/**
|
|
1812
|
+
* Capabilities of this adapter, defining address handling patterns and supported chains.
|
|
1813
|
+
*
|
|
1814
|
+
* This property helps determine how the adapter behaves, especially for address resolution
|
|
1815
|
+
* and chain operations. Different adapter types have different requirements for explicit
|
|
1816
|
+
* context in operations.
|
|
1817
|
+
*
|
|
1818
|
+
* @remarks
|
|
1819
|
+
* This is optional for backward compatibility during the migration period.
|
|
1820
|
+
* New adapters should always define this property.
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```typescript
|
|
1824
|
+
* // Private key adapter
|
|
1825
|
+
* capabilities = {
|
|
1826
|
+
* addressContext: 'single',
|
|
1827
|
+
* supportedChains: [Ethereum, Base],
|
|
1828
|
+
* availableAddresses: ['0x123...']
|
|
1829
|
+
* }
|
|
1830
|
+
*
|
|
1831
|
+
* // Browser wallet adapter
|
|
1832
|
+
* capabilities = {
|
|
1833
|
+
* addressContext: 'user-accounts',
|
|
1834
|
+
* supportedChains: [Ethereum, Base, Polygon],
|
|
1835
|
+
* availableAddresses: ['0x123...', '0x456...']
|
|
1836
|
+
* }
|
|
1837
|
+
* ```
|
|
1838
|
+
*/
|
|
1839
|
+
capabilities?: AdapterCapabilities;
|
|
1840
|
+
/**
|
|
1841
|
+
* Default chain for operations when none is explicitly provided.
|
|
1842
|
+
*
|
|
1843
|
+
* This allows adapters to have sensible defaults for chain operations,
|
|
1844
|
+
* reducing the need for explicit chain specification in every call.
|
|
1845
|
+
* Multi-entity adapters typically don't have a default chain.
|
|
1846
|
+
*
|
|
1847
|
+
* @remarks
|
|
1848
|
+
* This is optional for backward compatibility and because some adapter types
|
|
1849
|
+
* (like multi-entity adapters) may not have meaningful defaults.
|
|
1850
|
+
*
|
|
1851
|
+
* @example
|
|
1852
|
+
* ```typescript
|
|
1853
|
+
* // Private key adapter with default chain
|
|
1854
|
+
* defaultChain = Ethereum
|
|
1855
|
+
*
|
|
1856
|
+
* // Multi-entity adapter (no default)
|
|
1857
|
+
* defaultChain = undefined
|
|
1858
|
+
* ```
|
|
1859
|
+
*/
|
|
1860
|
+
defaultChain?: ChainDefinition;
|
|
1861
|
+
/**
|
|
1862
|
+
* Registry of available actions for this adapter.
|
|
1863
|
+
*
|
|
1864
|
+
* The {@link ActionRegistry} provides a catalog of supported operations
|
|
1865
|
+
* (such as token transfers, approvals, etc.) that can be performed by this adapter
|
|
1866
|
+
* on the connected blockchain. This enables dynamic discovery and invocation
|
|
1867
|
+
* of chain-specific or cross-chain actions in a type-safe manner.
|
|
1868
|
+
*
|
|
1869
|
+
* @readonly
|
|
1870
|
+
*/
|
|
1871
|
+
readonly actionRegistry: ActionRegistry;
|
|
1872
|
+
/**
|
|
1873
|
+
* Prepares (but does not execute) an action for the connected blockchain.
|
|
1874
|
+
*
|
|
1875
|
+
* This method looks up the appropriate action handler for the given action key
|
|
1876
|
+
* and prepares the transaction request using the provided parameters. The returned
|
|
1877
|
+
* {@link PreparedChainRequest} allows developers to estimate gas costs and execute
|
|
1878
|
+
* the transaction at a later time, enabling pre-flight simulation and deferred execution.
|
|
1879
|
+
*
|
|
1880
|
+
* @remarks
|
|
1881
|
+
* This method does not send any transaction to the network. Instead, it returns a
|
|
1882
|
+
* prepared request object with `estimate()` and `execute()` methods, allowing
|
|
1883
|
+
* developers to inspect, simulate, or submit the transaction as needed.
|
|
1884
|
+
*
|
|
1885
|
+
* @param action - The action key identifying which handler to use for preparation.
|
|
1886
|
+
* @param params - The parameters to pass to the action handler.
|
|
1887
|
+
* @returns A promise that resolves to a {@link PreparedChainRequest} for estimation and execution.
|
|
1888
|
+
*/
|
|
1889
|
+
prepareAction<TActionKey extends ActionKeys>(action: TActionKey, params: ActionPayload<TActionKey>): Promise<PreparedChainRequest>;
|
|
1890
|
+
/**
|
|
1891
|
+
* Prepares a transaction for future gas estimation and execution.
|
|
1892
|
+
*
|
|
1893
|
+
* This method should handle any preliminary steps required before a transaction
|
|
1894
|
+
* can be estimated or sent. This might include things like serializing transaction
|
|
1895
|
+
* data, but it should NOT yet send anything to the network.
|
|
1896
|
+
*
|
|
1897
|
+
* The returned object contains two functions:
|
|
1898
|
+
* - `estimate()`: Asynchronously calculates and returns the {@link EstimatedGas} for the prepared transaction.
|
|
1899
|
+
* - `execute()`: Asynchronously executes the prepared transaction and returns a promise that resolves
|
|
1900
|
+
* with the transaction result (e.g., a transaction hash, receipt, or other chain-specific response).
|
|
1901
|
+
*
|
|
1902
|
+
* @remarks
|
|
1903
|
+
* The specific parameters for `prepare` might vary greatly between chain implementations.
|
|
1904
|
+
* Consider defining a generic type or a base type for `transactionRequest` if common patterns emerge,
|
|
1905
|
+
* or allow `...args: any[]` if extreme flexibility is needed by implementers.
|
|
1906
|
+
* For this abstract definition, we keep it parameter-less, assuming implementations will add specific
|
|
1907
|
+
* parameters as needed for their `prepare` method (e.g. `prepare(txDetails: MyChainTxDetails)`).
|
|
1908
|
+
*
|
|
1909
|
+
* @returns An object containing `estimate` and `execute` methods for the prepared transaction.
|
|
1910
|
+
*/
|
|
1911
|
+
abstract prepare(params: PreparedChainRequestParams): Promise<PreparedChainRequest>;
|
|
1912
|
+
/**
|
|
1913
|
+
* Retrieves the public address of the connected wallet.
|
|
1914
|
+
*
|
|
1915
|
+
* This address is used as the default sender for transactions
|
|
1916
|
+
* and interactions initiated by this adapter.
|
|
1917
|
+
*
|
|
1918
|
+
* @returns A promise that resolves to the blockchain address as a string.
|
|
1919
|
+
*/
|
|
1920
|
+
abstract getAddress(): Promise<string>;
|
|
1921
|
+
/**
|
|
1922
|
+
* Retrieves the {@link ChainDefinition} object that describes the blockchain
|
|
1923
|
+
* this adapter is configured to interact with.
|
|
1924
|
+
*
|
|
1925
|
+
* This includes information such as the chain ID, name, native currency, etc.,
|
|
1926
|
+
* as defined by the `ChainDefinition` type.
|
|
1927
|
+
*
|
|
1928
|
+
* @returns A promise that resolves to the {@link ChainDefinition} for the current chain.
|
|
1929
|
+
*/
|
|
1930
|
+
abstract getChain(): Promise<ChainDefinition>;
|
|
1931
|
+
/**
|
|
1932
|
+
* Switches the adapter to operate on the specified chain.
|
|
1933
|
+
*
|
|
1934
|
+
* This abstract method must be implemented by concrete adapters to handle their specific
|
|
1935
|
+
* chain switching logic. The behavior varies by adapter type:
|
|
1936
|
+
* - **Private key adapters**: Recreate clients with new RPC endpoints
|
|
1937
|
+
* - **Browser wallet adapters**: Request chain switch via EIP-1193 or equivalent
|
|
1938
|
+
* - **Multi-entity adapters**: Typically a no-op (operations are contextual)
|
|
1939
|
+
*
|
|
1940
|
+
* @param chain - The target chain to switch to.
|
|
1941
|
+
* @returns A promise that resolves when the chain switch is complete.
|
|
1942
|
+
* @throws When the chain switching fails or is not supported.
|
|
1943
|
+
*
|
|
1944
|
+
* @remarks
|
|
1945
|
+
* This method is called by `ensureChain()` after validation is complete.
|
|
1946
|
+
* Implementations should focus only on the actual switching logic, not validation.
|
|
1947
|
+
*
|
|
1948
|
+
* @example
|
|
1949
|
+
* ```typescript
|
|
1950
|
+
* // EVM adapter implementation
|
|
1951
|
+
* protected async switchToChain(chain: ChainDefinition): Promise<void> {
|
|
1952
|
+
* if (chain.type !== 'evm') {
|
|
1953
|
+
* throw new Error('Only EVM chains supported')
|
|
1954
|
+
* }
|
|
1955
|
+
* await this.recreateWalletClient(chain)
|
|
1956
|
+
* }
|
|
1957
|
+
*
|
|
1958
|
+
* // Multi-entity adapter implementation
|
|
1959
|
+
* protected async switchToChain(chain: ChainDefinition): Promise<void> {
|
|
1960
|
+
* // No-op - operations are contextual
|
|
1961
|
+
* return
|
|
1962
|
+
* }
|
|
1963
|
+
* ```
|
|
1964
|
+
*/
|
|
1965
|
+
abstract switchToChain(chain: ChainDefinition): Promise<void>;
|
|
1966
|
+
/**
|
|
1967
|
+
* Ensures the adapter is operating on the specified chain, switching if necessary.
|
|
1968
|
+
*
|
|
1969
|
+
* This method provides a unified interface for establishing chain preconditions across different adapter types.
|
|
1970
|
+
* The behavior varies based on the adapter's capabilities:
|
|
1971
|
+
* - **Private key adapters**: Recreate clients with new RPC endpoints
|
|
1972
|
+
* - **Browser wallet adapters**: Request chain switch via EIP-1193 or equivalent
|
|
1973
|
+
* - **Multi-entity adapters**: Validate chain support (operations are contextual)
|
|
1974
|
+
*
|
|
1975
|
+
* @param chain - The target chain for operations. If not provided, uses the adapter's defaultChain.
|
|
1976
|
+
* @returns A promise that resolves when the adapter is operating on the specified chain.
|
|
1977
|
+
* @throws When the target chain is not supported or chain switching fails.
|
|
1978
|
+
*
|
|
1979
|
+
* @remarks
|
|
1980
|
+
* This method replaces the pattern of calling `getChain()` to check current chain and then
|
|
1981
|
+
* manually switching. It provides a declarative "ensure this chain" interface for operations.
|
|
1982
|
+
*
|
|
1983
|
+
* **Backward Compatibility**: The default implementation provides basic validation but
|
|
1984
|
+
* doesn't perform actual chain switching. Concrete adapter implementations should override
|
|
1985
|
+
* this method to provide proper chain switching logic.
|
|
1986
|
+
*
|
|
1987
|
+
* @example
|
|
1988
|
+
* ```typescript
|
|
1989
|
+
* // Private key adapter - switches chains seamlessly
|
|
1990
|
+
* await privateKeyAdapter.ensureChain(Base)
|
|
1991
|
+
*
|
|
1992
|
+
* // Browser wallet - requests user to switch chains
|
|
1993
|
+
* await metamaskAdapter.ensureChain(Polygon)
|
|
1994
|
+
*
|
|
1995
|
+
* // Multi-entity adapter - validates chain is supported
|
|
1996
|
+
* await circleWalletsAdapter.ensureChain(Ethereum)
|
|
1997
|
+
* ```
|
|
1998
|
+
*/
|
|
1999
|
+
ensureChain(chain?: ChainDefinition): Promise<void>;
|
|
2000
|
+
/**
|
|
2001
|
+
* Validate that the target chain is supported by this adapter.
|
|
2002
|
+
*
|
|
2003
|
+
* @param targetChain - The chain to validate.
|
|
2004
|
+
* @throws Error if the chain is not supported.
|
|
2005
|
+
*/
|
|
2006
|
+
validateChainSupport(targetChain: ChainDefinition): void;
|
|
2007
|
+
/**
|
|
2008
|
+
* Waits for a transaction to be mined and confirmed on the blockchain.
|
|
2009
|
+
*
|
|
2010
|
+
* This method should block until the transaction is confirmed on the blockchain.
|
|
2011
|
+
* The response includes comprehensive transaction details for the confirmed transaction.
|
|
2012
|
+
*
|
|
2013
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
2014
|
+
* @param config - Optional configuration for waiting behavior including timeout and confirmations.
|
|
2015
|
+
* @returns Promise resolving to comprehensive transaction details.
|
|
2016
|
+
*/
|
|
2017
|
+
abstract waitForTransaction(txHash: string, config?: WaitForTransactionConfig): Promise<WaitForTransactionResponse>;
|
|
2018
|
+
/**
|
|
2019
|
+
* Calculate the total transaction fee including compute cost and buffer for the configured chain.
|
|
2020
|
+
*
|
|
2021
|
+
* This method computes the fee by multiplying the base compute units by the current
|
|
2022
|
+
* fee rate, then adds a configurable buffer to account for fee fluctuations and ensure
|
|
2023
|
+
* transaction success. The buffer is specified in basis points (1 basis point = 0.01%).
|
|
2024
|
+
*
|
|
2025
|
+
* @param baseComputeUnits - The base compute units for the transaction (gas for EVM, compute units for Solana, etc.).
|
|
2026
|
+
* @param bufferBasisPoints - The buffer to add as basis points (e.g., 500 = 5%). Defaults to implementation-specific value.
|
|
2027
|
+
* @returns A promise that resolves to the total transaction fee as a bigint.
|
|
2028
|
+
*/
|
|
2029
|
+
abstract calculateTransactionFee(baseComputeUnits: bigint, bufferBasisPoints?: bigint): Promise<EstimatedGas>;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
/**
|
|
2033
|
+
* EIP-712 domain structure for typed data signing.
|
|
2034
|
+
*
|
|
2035
|
+
* Represents the domain separator fields as defined by the EIP-712 standard.
|
|
2036
|
+
* Used to prevent signature replay across different domains (contracts, chains, etc).
|
|
2037
|
+
*
|
|
2038
|
+
* @see {@link https://eips.ethereum.org/EIPS/eip-712}
|
|
2039
|
+
*
|
|
2040
|
+
* @example
|
|
2041
|
+
* ```typescript
|
|
2042
|
+
* const domain: EIP712Domain = {
|
|
2043
|
+
* name: "USD Coin",
|
|
2044
|
+
* version: "2",
|
|
2045
|
+
* chainId: 1,
|
|
2046
|
+
* verifyingContract: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
2047
|
+
* }
|
|
2048
|
+
* ```
|
|
2049
|
+
*/
|
|
2050
|
+
interface EIP712Domain {
|
|
2051
|
+
/** Human-readable name of the signing domain (e.g., "USD Coin") */
|
|
2052
|
+
name: string;
|
|
2053
|
+
/** Current major version of the signing domain (e.g., "2") */
|
|
2054
|
+
version: string;
|
|
2055
|
+
/** EVM chain ID where the contract is deployed */
|
|
2056
|
+
chainId: number | bigint;
|
|
2057
|
+
/** Address of the contract that will verify the signature */
|
|
2058
|
+
verifyingContract: `0x${string}`;
|
|
2059
|
+
/** Optional salt for domain separation (as hex string) */
|
|
2060
|
+
salt?: `0x${string}`;
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Field definition for EIP-712 typed data.
|
|
2064
|
+
*
|
|
2065
|
+
* Each field describes a property in a struct, including its name and Solidity type.
|
|
2066
|
+
*
|
|
2067
|
+
* @example
|
|
2068
|
+
* ```typescript
|
|
2069
|
+
* const field: TypedDataField = { name: "owner", type: "address" }
|
|
2070
|
+
* ```
|
|
2071
|
+
*/
|
|
2072
|
+
interface TypedDataField {
|
|
2073
|
+
/** Name of the struct field */
|
|
2074
|
+
name: string;
|
|
2075
|
+
/** Solidity type of the struct field (e.g., "address", "uint256") */
|
|
2076
|
+
type: string;
|
|
2077
|
+
}
|
|
2078
|
+
/**
|
|
2079
|
+
* EIP-712 Typed Data structure.
|
|
2080
|
+
*
|
|
2081
|
+
* Represents a fully-typed EIP-712 message, including domain, types, primary type, and message payload.
|
|
2082
|
+
*
|
|
2083
|
+
* @typeParam Types - Mapping of struct names to their field definitions
|
|
2084
|
+
* @typeParam Message - The message payload type
|
|
2085
|
+
*
|
|
2086
|
+
* @example
|
|
2087
|
+
* ```typescript
|
|
2088
|
+
* const typedData: TypedData<typeof types, typeof message> = {
|
|
2089
|
+
* domain,
|
|
2090
|
+
* types,
|
|
2091
|
+
* primaryType: "Permit",
|
|
2092
|
+
* message
|
|
2093
|
+
* }
|
|
2094
|
+
* ```
|
|
2095
|
+
*/
|
|
2096
|
+
interface TypedData<Types extends Record<string, TypedDataField[]>, Message extends Record<string, unknown>> {
|
|
2097
|
+
/** EIP-712 domain separator */
|
|
2098
|
+
domain: EIP712Domain;
|
|
2099
|
+
/** Mapping of struct names to their field definitions */
|
|
2100
|
+
types: Types;
|
|
2101
|
+
/** The root struct type being signed (must be a key of `types`) */
|
|
2102
|
+
primaryType: keyof Types & string;
|
|
2103
|
+
/** The message payload to be signed */
|
|
2104
|
+
message: Message;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
/**
|
|
2108
|
+
* Core type definitions for EVM-compatible blockchain transaction execution
|
|
2109
|
+
* and gas estimation.
|
|
2110
|
+
*
|
|
2111
|
+
* This module provides TypeScript interfaces and types for handling EVM-compatible
|
|
2112
|
+
* blockchain transactions across different networks.
|
|
2113
|
+
*
|
|
2114
|
+
* @module types
|
|
2115
|
+
*/
|
|
2116
|
+
|
|
2117
|
+
/**
|
|
2118
|
+
* Parameters for reading a contract function on an EVM-compatible chain.
|
|
2119
|
+
*
|
|
2120
|
+
* @interface ReadContractParams
|
|
2121
|
+
* @example
|
|
2122
|
+
* ```typescript
|
|
2123
|
+
* const params: ReadContractParams = {
|
|
2124
|
+
* address: '0x1234567890abcdef1234567890abcdef12345678',
|
|
2125
|
+
* abi: myAbi,
|
|
2126
|
+
* functionName: 'balanceOf',
|
|
2127
|
+
* args: ['0xabcdef...']
|
|
2128
|
+
* }
|
|
2129
|
+
* ```
|
|
2130
|
+
*/
|
|
2131
|
+
interface ReadContractParams {
|
|
2132
|
+
/**
|
|
2133
|
+
* The address of the contract to read from.
|
|
2134
|
+
* @example '0x1234567890abcdef1234567890abcdef12345678'
|
|
2135
|
+
*/
|
|
2136
|
+
address: `0x${string}`;
|
|
2137
|
+
/**
|
|
2138
|
+
* The ABI of the contract.
|
|
2139
|
+
*/
|
|
2140
|
+
abi: Abi;
|
|
2141
|
+
/**
|
|
2142
|
+
* The name of the function to call.
|
|
2143
|
+
* @example 'balanceOf'
|
|
2144
|
+
*/
|
|
2145
|
+
functionName: string;
|
|
2146
|
+
/**
|
|
2147
|
+
* The arguments to pass to the function.
|
|
2148
|
+
* @example ['0xabcdef...']
|
|
2149
|
+
*/
|
|
2150
|
+
args: unknown[];
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
* Abstract base class for EVM-compatible blockchain adapters.
|
|
2155
|
+
*
|
|
2156
|
+
* This class extends the generic `Adapter` to provide EVM-specific functionality
|
|
2157
|
+
* for interacting with Ethereum Virtual Machine compatible blockchains. It automatically
|
|
2158
|
+
* registers EVM-specific action handlers during construction and sets the chain type to 'evm'.
|
|
2159
|
+
*
|
|
2160
|
+
* The signTypedData method uses a generic TypedData interface from the signTypedData module,
|
|
2161
|
+
* making it compatible with any EIP-712 standard (EIP-2612, EIP-7597, ERC-3009, etc.) while
|
|
2162
|
+
* maintaining type safety throughout the signing process.
|
|
2163
|
+
*/
|
|
2164
|
+
declare abstract class EvmAdapter extends Adapter {
|
|
2165
|
+
/**
|
|
2166
|
+
* The type of chain this adapter is for.
|
|
2167
|
+
*/
|
|
2168
|
+
chainType: ChainType;
|
|
2169
|
+
/**
|
|
2170
|
+
* The constructor for the EVM adapter.
|
|
2171
|
+
*
|
|
2172
|
+
* @remarks
|
|
2173
|
+
* This constructor registers the action handlers for the EVM adapter.
|
|
2174
|
+
*/
|
|
2175
|
+
constructor();
|
|
2176
|
+
/**
|
|
2177
|
+
* Signs EIP-712 typed data using a generic, type-safe interface.
|
|
2178
|
+
*
|
|
2179
|
+
* This method accepts strongly-typed EIP-712 data that works with any standard
|
|
2180
|
+
* (EIP-2612, EIP-7597, ERC-3009, etc.) and delegates to the framework-specific
|
|
2181
|
+
* implementation (viem, ethers, web3.js) for actual signing.
|
|
2182
|
+
*
|
|
2183
|
+
* @typeParam Types - The EIP-712 types definition for the standard being signed
|
|
2184
|
+
* @typeParam Message - The message structure for the standard being signed
|
|
2185
|
+
* @param typedData - The EIP-712 typed data to sign with full type safety
|
|
2186
|
+
* @returns Promise resolving to the signature as a hex string
|
|
2187
|
+
* @throws Error when the wallet client is not available or signing fails
|
|
2188
|
+
*
|
|
2189
|
+
* @example
|
|
2190
|
+
* ```typescript
|
|
2191
|
+
* // Works with any EIP-712 standard
|
|
2192
|
+
* import { buildEIP2612TypedData } from '@core/adapter-evm'
|
|
2193
|
+
*
|
|
2194
|
+
* const typedData = await buildEIP2612TypedData(meta, adapter, options)
|
|
2195
|
+
* const signature = await adapter.signTypedData(typedData)
|
|
2196
|
+
* ```
|
|
2197
|
+
*/
|
|
2198
|
+
abstract signTypedData<Types extends Record<string, TypedDataField[]>, Message extends Record<string, unknown>>(typedData: TypedData<Types, Message>): Promise<`0x${string}`>;
|
|
2199
|
+
/**
|
|
2200
|
+
* Fetches the current EIP-2612 nonce for a token owner.
|
|
2201
|
+
*
|
|
2202
|
+
* This method queries the token contract's `nonces(address)` function to get
|
|
2203
|
+
* the current nonce value for permit signatures. It uses the adapter's `prepare`
|
|
2204
|
+
* method to handle the contract interaction, making it framework-agnostic.
|
|
2205
|
+
*
|
|
2206
|
+
* @param tokenAddress - The ERC-20 token contract address
|
|
2207
|
+
* @param ownerAddress - The address of the token owner
|
|
2208
|
+
* @returns Promise resolving to the current nonce value
|
|
2209
|
+
* @throws Error when the contract call fails or the token doesn't support EIP-2612
|
|
2210
|
+
*
|
|
2211
|
+
* @example
|
|
2212
|
+
* ```typescript
|
|
2213
|
+
* // Get current nonce for permit signing
|
|
2214
|
+
* const nonce = await adapter.fetchEIP2612Nonce(
|
|
2215
|
+
* '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
|
|
2216
|
+
* '0x123...' // owner address
|
|
2217
|
+
* )
|
|
2218
|
+
* ```
|
|
2219
|
+
*/
|
|
2220
|
+
fetchEIP2612Nonce(tokenAddress: `0x${string}`, ownerAddress: `0x${string}`): Promise<bigint>;
|
|
2221
|
+
/**
|
|
2222
|
+
* Read a contract function.
|
|
2223
|
+
*
|
|
2224
|
+
* @typeParam TReturnType - The expected return type of the contract function.
|
|
2225
|
+
* @param params - The parameters for the contract function read.
|
|
2226
|
+
* @returns A promise that resolves to the result of the contract function read.
|
|
2227
|
+
*/
|
|
2228
|
+
abstract readContract<TReturnType = unknown>(params: ReadContractParams): Promise<TReturnType>;
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
/**
|
|
2232
|
+
* @packageDocumentation
|
|
2233
|
+
* @module EthersAdapter
|
|
2234
|
+
*
|
|
2235
|
+
* A concrete EVM adapter implementation backed by the `ethers` library.
|
|
2236
|
+
* It provides functionality for gas estimation, contract interaction,
|
|
2237
|
+
* and transaction execution.
|
|
2238
|
+
*/
|
|
2239
|
+
/**
|
|
2240
|
+
* Direct client configuration for EthersAdapter using pre-configured Ethers.js clients.
|
|
2241
|
+
* @interface EthersAdapterOptions
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* ```typescript
|
|
2245
|
+
* import { JsonRpcProvider, Wallet } from 'ethers'
|
|
2246
|
+
* import type { EthersAdapterOptions } from '@circle-fin/adapter-ethers-v6'
|
|
2247
|
+
*
|
|
2248
|
+
* const options: EthersAdapterOptions = {
|
|
2249
|
+
* getProvider: ({ chain }) => new JsonRpcProvider('https://...'),
|
|
2250
|
+
* signer: new Wallet('0xabc...', new JsonRpcProvider('https://...')),
|
|
2251
|
+
* }
|
|
2252
|
+
* ```
|
|
2253
|
+
*/
|
|
2254
|
+
interface EthersAdapterOptions {
|
|
2255
|
+
/**
|
|
2256
|
+
* Returns a pre-configured Ethers.js Provider for the given chain.
|
|
2257
|
+
*/
|
|
2258
|
+
getProvider: (params: {
|
|
2259
|
+
chain: EVMChainDefinition;
|
|
2260
|
+
}) => Provider;
|
|
2261
|
+
/** Ethers.js Signer instance used for signing transactions and messages. */
|
|
2262
|
+
signer: Signer$1;
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* Creates a new EthersAdapter instance.
|
|
2266
|
+
*
|
|
2267
|
+
* @param options - Configuration options for the adapter.
|
|
2268
|
+
*/
|
|
2269
|
+
declare class EthersAdapter extends EvmAdapter {
|
|
2270
|
+
/** The configuration options for this adapter instance. */
|
|
2271
|
+
options: EthersAdapterOptions;
|
|
2272
|
+
/** Cached Ethers Signer instance. */
|
|
2273
|
+
private _signer;
|
|
2274
|
+
/** Cached address of the connected wallet. */
|
|
2275
|
+
private cachedAddress?;
|
|
2276
|
+
/** Cached providers for different chains. */
|
|
2277
|
+
private readonly cachedProviders;
|
|
2278
|
+
/** Cached gas price for the current network. */
|
|
2279
|
+
private cachedGasPrice?;
|
|
2280
|
+
/** Cached chain definition for the connected provider. */
|
|
2281
|
+
private cachedChain;
|
|
2282
|
+
/** The resolved chain definition that this adapter was created for. */
|
|
2283
|
+
private resolvedChain;
|
|
2284
|
+
constructor(options: EthersAdapterOptions);
|
|
2285
|
+
/**
|
|
2286
|
+
* Sets the resolved chain for this adapter.
|
|
2287
|
+
* @internal
|
|
2288
|
+
*/
|
|
2289
|
+
setResolvedChain(chain: EVMChainDefinition): void;
|
|
2290
|
+
/**
|
|
2291
|
+
* Switches the adapter to operate on the specified chain.
|
|
2292
|
+
*
|
|
2293
|
+
* This implementation recreates the signer with the new chain configuration.
|
|
2294
|
+
* All validation is handled by the base class ensureChain method.
|
|
2295
|
+
*
|
|
2296
|
+
* @param chain - The target chain to switch to (already validated by base class).
|
|
2297
|
+
* @returns A promise that resolves when the chain switch is complete.
|
|
2298
|
+
* @throws When chain switching fails.
|
|
2299
|
+
*/
|
|
2300
|
+
switchToChain(chain: ChainDefinition): Promise<void>;
|
|
2301
|
+
/**
|
|
2302
|
+
* Gets the cached Provider or initializes it from options if not already cached.
|
|
2303
|
+
*/
|
|
2304
|
+
getProvider(chain?: EVMChainDefinition): Promise<Provider>;
|
|
2305
|
+
/** Gets the current Signer instance used by the adapter. */
|
|
2306
|
+
getSigner(): Signer$1;
|
|
2307
|
+
/**
|
|
2308
|
+
* Creates a contract instance for the given address, ABI, and wallet.
|
|
2309
|
+
*/
|
|
2310
|
+
private createContractInstance;
|
|
2311
|
+
/**
|
|
2312
|
+
* Simulates a contract function call using Ethers v6 `.staticCall`.
|
|
2313
|
+
*/
|
|
2314
|
+
private simulateFunctionCall;
|
|
2315
|
+
/**
|
|
2316
|
+
* Estimates the gas required for executing a contract function call.
|
|
2317
|
+
*/
|
|
2318
|
+
private estimateGasForFunction;
|
|
2319
|
+
/**
|
|
2320
|
+
* Executes a contract function as a transaction on the blockchain.
|
|
2321
|
+
*/
|
|
2322
|
+
private executeTransaction;
|
|
2323
|
+
/**
|
|
2324
|
+
* Prepares a chain request for execution.
|
|
2325
|
+
*/
|
|
2326
|
+
prepare(params: EvmPreparedChainRequestParams): Promise<EvmPreparedChainRequest>;
|
|
2327
|
+
/** Gets the address of the connected wallet. */
|
|
2328
|
+
getAddress(): Promise<string>;
|
|
2329
|
+
/** Gets the current chain definition. */
|
|
2330
|
+
getChain(): Promise<ChainDefinition>;
|
|
2331
|
+
/**
|
|
2332
|
+
* Waits for a transaction to be mined and confirmed on the blockchain.
|
|
2333
|
+
*/
|
|
2334
|
+
waitForTransaction(txHash: string, config?: WaitForTransactionConfig): Promise<WaitForTransactionResponse>;
|
|
2335
|
+
/**
|
|
2336
|
+
* Calculate the total transaction fee including compute cost and buffer for the configured chain.
|
|
2337
|
+
*/
|
|
2338
|
+
calculateTransactionFee(baseComputeUnits: bigint, bufferBasisPoints?: bigint): Promise<EstimatedGas>;
|
|
2339
|
+
/**
|
|
2340
|
+
* Signs EIP-712 typed data using the configured signer.
|
|
2341
|
+
*/
|
|
2342
|
+
signTypedData<Types extends Record<string, TypedDataField[]>, Message extends Record<string, unknown>>(typedData: TypedData<Types, Message>): Promise<`0x${string}`>;
|
|
2343
|
+
/** Reads a contract function using Ethers v6. */
|
|
2344
|
+
readContract<TReturnType = unknown>(params: ReadContractParams): Promise<TReturnType>;
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
/**
|
|
2348
|
+
* Parameters for creating an {@link EthersAdapter} from a private key.
|
|
2349
|
+
*
|
|
2350
|
+
* @interface CreateAdapterFromPrivateKeyParams
|
|
2351
|
+
* @category Types
|
|
2352
|
+
* @description
|
|
2353
|
+
* Defines the configuration required to instantiate an {@link EthersAdapter}
|
|
2354
|
+
* using a raw private key for server-side or programmatic wallet operations.
|
|
2355
|
+
*
|
|
2356
|
+
* This is intended for secure, backend, or automated environments where direct
|
|
2357
|
+
* control of the private key is possible and safe. Do not use this pattern in
|
|
2358
|
+
* browser or client-side code.
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* ```typescript
|
|
2362
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
2363
|
+
* import { Blockchain } from '@core/chains'
|
|
2364
|
+
*
|
|
2365
|
+
* // Using a chain identifier (enum, string, or ChainDefinition)
|
|
2366
|
+
* const adapter = createAdapterFromPrivateKey({
|
|
2367
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2368
|
+
* defaultChain: Blockchain.Ethereum,
|
|
2369
|
+
* })
|
|
2370
|
+
*
|
|
2371
|
+
* // Advanced: custom provider logic (e.g., for custom endpoints or retry logic)
|
|
2372
|
+
* const adapter2 = createAdapterFromPrivateKey({
|
|
2373
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2374
|
+
* defaultChain: 'Ethereum',
|
|
2375
|
+
* getProvider: ({ chain }) => new JsonRpcProvider('https://...'),
|
|
2376
|
+
* })
|
|
2377
|
+
* ```
|
|
2378
|
+
*
|
|
2379
|
+
* @remarks
|
|
2380
|
+
* Supported parameter combinations:
|
|
2381
|
+
* - Provide `privateKey` and `defaultChain` (uses default provider logic).
|
|
2382
|
+
* - Optionally provide a custom `getProvider` function for advanced provider instantiation.
|
|
2383
|
+
*
|
|
2384
|
+
* The `privateKey` must be a valid 32-byte hex string prefixed with `0x`.
|
|
2385
|
+
* The `defaultChain` can be a {@link ChainDefinition}, a supported chain enum, or a string literal.
|
|
2386
|
+
* The `getProvider` function, if supplied, receives an object with a `chain` parameter.
|
|
2387
|
+
*/
|
|
2388
|
+
interface CreateAdapterFromPrivateKeyParams {
|
|
2389
|
+
/**
|
|
2390
|
+
* The private key for wallet operations.
|
|
2391
|
+
* @remarks
|
|
2392
|
+
* Must be a valid 32-byte hex string prefixed with '0x'. This should be:
|
|
2393
|
+
* - A securely generated private key
|
|
2394
|
+
* - Kept confidential and never exposed in client-side code
|
|
2395
|
+
* - Used only in server-side or secure environments
|
|
2396
|
+
*
|
|
2397
|
+
* The private key will be used to sign transactions and authenticate
|
|
2398
|
+
* with the blockchain network.
|
|
2399
|
+
*/
|
|
2400
|
+
privateKey: `0x${string}`;
|
|
2401
|
+
/**
|
|
2402
|
+
* The default blockchain network to connect to.
|
|
2403
|
+
* @remarks
|
|
2404
|
+
* Accepts a {@link ChainDefinition}, a supported chain enum, or a string literal representing the chain.
|
|
2405
|
+
* This determines which EVM-compatible network the adapter will operate on by default.
|
|
2406
|
+
* The adapter will use the canonical RPC URL for the specified chain unless a custom provider is supplied.
|
|
2407
|
+
* Examples: `Blockchain.Ethereum`, `'Ethereum'`, or a `ChainDefinition` object.
|
|
2408
|
+
*/
|
|
2409
|
+
defaultChain: ChainIdentifier;
|
|
2410
|
+
/**
|
|
2411
|
+
* Optional function to provide a custom Ethers Provider instance.
|
|
2412
|
+
* @remarks
|
|
2413
|
+
* If not provided, a default Provider will be created using the chain's RPC endpoints.
|
|
2414
|
+
* Use this to inject custom provider logic, such as:
|
|
2415
|
+
* - Custom retry or caching strategies
|
|
2416
|
+
* - Enhanced logging or monitoring
|
|
2417
|
+
* - Support for non-standard transports
|
|
2418
|
+
*
|
|
2419
|
+
* @param chain - The chain definition for which to create the provider.
|
|
2420
|
+
* @returns A configured Provider instance.
|
|
2421
|
+
*/
|
|
2422
|
+
getProvider?: (params: {
|
|
2423
|
+
chain: ChainDefinition;
|
|
2424
|
+
}) => Provider;
|
|
2425
|
+
}
|
|
2426
|
+
/**
|
|
2427
|
+
* Creates an EthersAdapter instance from a private key.
|
|
2428
|
+
*
|
|
2429
|
+
* This function creates an EthersAdapter for server-side or programmatic use
|
|
2430
|
+
* by deriving a wallet from the provided private key and connecting it to the specified chain.
|
|
2431
|
+
* It's ideal for automated systems, backend services, or scenarios where you have direct
|
|
2432
|
+
* control over the private key.
|
|
2433
|
+
*
|
|
2434
|
+
* @remarks
|
|
2435
|
+
* The function performs the following operations:
|
|
2436
|
+
* 1. Validates the input parameters at runtime
|
|
2437
|
+
* 2. Resolves the chain identifier to a ChainDefinition
|
|
2438
|
+
* 3. Determines the canonical RPC URL for the specified chain
|
|
2439
|
+
* 4. Creates a JsonRpcProvider using the resolved RPC URL (or a custom provider if getProvider is supplied)
|
|
2440
|
+
* 5. Instantiates a Wallet with the private key and provider
|
|
2441
|
+
* 6. Returns a configured EthersAdapter instance
|
|
2442
|
+
*
|
|
2443
|
+
* The adapter will be ready to use immediately after creation with the
|
|
2444
|
+
* specified provider and wallet active. If a custom provider factory is provided,
|
|
2445
|
+
* those settings will be respected for all operations.
|
|
2446
|
+
*
|
|
2447
|
+
* **Security Warning:** Never use this function in client-side code or expose
|
|
2448
|
+
* private keys in any way. This function is intended for server-side use only.
|
|
2449
|
+
*
|
|
2450
|
+
* @param params - Configuration parameters for creating the adapter
|
|
2451
|
+
* @returns A configured EthersAdapter instance
|
|
2452
|
+
* @throws Error when validation fails or wallet creation fails
|
|
2453
|
+
*
|
|
2454
|
+
* @example
|
|
2455
|
+
* ```typescript
|
|
2456
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
2457
|
+
* import { Blockchain, Ethereum } from '@core/chains'
|
|
2458
|
+
*
|
|
2459
|
+
* // Using ChainDefinition object
|
|
2460
|
+
* const adapter1 = createAdapterFromPrivateKey({
|
|
2461
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2462
|
+
* defaultChain: Ethereum,
|
|
2463
|
+
* })
|
|
2464
|
+
*
|
|
2465
|
+
* // Using Blockchain enum
|
|
2466
|
+
* const adapter2 = createAdapterFromPrivateKey({
|
|
2467
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2468
|
+
* defaultChain: Blockchain.Ethereum,
|
|
2469
|
+
* })
|
|
2470
|
+
*
|
|
2471
|
+
* // Using string literal
|
|
2472
|
+
* const adapter3 = createAdapterFromPrivateKey({
|
|
2473
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2474
|
+
* defaultChain: 'Ethereum',
|
|
2475
|
+
* })
|
|
2476
|
+
* ```
|
|
2477
|
+
*
|
|
2478
|
+
* @example
|
|
2479
|
+
* ```typescript
|
|
2480
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
2481
|
+
* import { JsonRpcProvider } from 'ethers'
|
|
2482
|
+
*
|
|
2483
|
+
* // Advanced usage with custom provider logic
|
|
2484
|
+
* const adapter = createAdapterFromPrivateKey({
|
|
2485
|
+
* privateKey: process.env.PRIVATE_KEY,
|
|
2486
|
+
* defaultChain: 'Ethereum',
|
|
2487
|
+
* getProvider: ({ chain }) => new JsonRpcProvider('https://...'),
|
|
2488
|
+
* })
|
|
2489
|
+
* ```
|
|
2490
|
+
*
|
|
2491
|
+
* @example
|
|
2492
|
+
* ```typescript
|
|
2493
|
+
* // Cross-chain transfer using a single adapter
|
|
2494
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
2495
|
+
* import { BridgingKit } from '@circle-fin/bridging-kit'
|
|
2496
|
+
*
|
|
2497
|
+
* const adapter = createAdapterFromPrivateKey({
|
|
2498
|
+
* privateKey: process.env.PRIVATE_KEY,
|
|
2499
|
+
* defaultChain: 'Ethereum',
|
|
2500
|
+
* })
|
|
2501
|
+
*
|
|
2502
|
+
* const kit = new BridgingKit()
|
|
2503
|
+
*
|
|
2504
|
+
* // Use the same adapter for both source and destination
|
|
2505
|
+
* const result = await kit.bridge({
|
|
2506
|
+
* from: { adapter, chain: 'Ethereum' },
|
|
2507
|
+
* to: { adapter, chain: 'Base' },
|
|
2508
|
+
* amount: '100.50'
|
|
2509
|
+
* })
|
|
2510
|
+
* ```
|
|
2511
|
+
*
|
|
2512
|
+
* @example
|
|
2513
|
+
* ```typescript
|
|
2514
|
+
* import { createAdapterFromPrivateKey } from '@circle-fin/adapter-ethers-v6'
|
|
2515
|
+
*
|
|
2516
|
+
* // Error handling example
|
|
2517
|
+
* try {
|
|
2518
|
+
* const adapter = createAdapterFromPrivateKey({
|
|
2519
|
+
* privateKey: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
2520
|
+
* defaultChain: 'Polygon',
|
|
2521
|
+
* })
|
|
2522
|
+
*
|
|
2523
|
+
* // Adapter is ready to use immediately
|
|
2524
|
+
* const balance = await adapter.getBalance()
|
|
2525
|
+
* console.log('Balance:', balance)
|
|
2526
|
+
* } catch (error) {
|
|
2527
|
+
* if (error.message.includes('Private key')) {
|
|
2528
|
+
* console.error('Invalid private key format')
|
|
2529
|
+
* } else {
|
|
2530
|
+
* console.error('Failed to create adapter:', error.message)
|
|
2531
|
+
* }
|
|
2532
|
+
* }
|
|
2533
|
+
* ```
|
|
2534
|
+
*/
|
|
2535
|
+
declare const createAdapterFromPrivateKey: (params: CreateAdapterFromPrivateKeyParams) => EthersAdapter;
|
|
2536
|
+
|
|
2537
|
+
/**
|
|
2538
|
+
* Parameters for creating an {@link EthersAdapter} from an EIP-1193 provider.
|
|
2539
|
+
*
|
|
2540
|
+
* @interface CreateAdapterFromProviderParams
|
|
2541
|
+
* @category Types
|
|
2542
|
+
* @description
|
|
2543
|
+
* Defines the parameters required to instantiate an {@link EthersAdapter} using an EIP-1193-compatible provider
|
|
2544
|
+
* (such as MetaMask, WalletConnect, or any injected browser wallet), and to specify the intended blockchain network.
|
|
2545
|
+
*
|
|
2546
|
+
* @example
|
|
2547
|
+
* ```typescript
|
|
2548
|
+
* import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
|
|
2549
|
+
*
|
|
2550
|
+
* // Basic usage with injected provider and explicit chain
|
|
2551
|
+
* const adapter = await createAdapterFromProvider({
|
|
2552
|
+
* provider: window.ethereum,
|
|
2553
|
+
* chain: 'Ethereum_Sepolia',
|
|
2554
|
+
* })
|
|
2555
|
+
* ```
|
|
2556
|
+
*
|
|
2557
|
+
* @example
|
|
2558
|
+
* ```typescript
|
|
2559
|
+
* import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
|
|
2560
|
+
* import { JsonRpcProvider } from 'ethers'
|
|
2561
|
+
*
|
|
2562
|
+
* // Advanced: custom provider logic for a specific chain
|
|
2563
|
+
* const adapter = await createAdapterFromProvider({
|
|
2564
|
+
* provider: window.ethereum,
|
|
2565
|
+
* chain: 'Base_Sepolia',
|
|
2566
|
+
* getProvider: ({ chain }) => new JsonRpcProvider('https://...'),
|
|
2567
|
+
* })
|
|
2568
|
+
* ```
|
|
2569
|
+
*
|
|
2570
|
+
* @remarks
|
|
2571
|
+
* Required parameters:
|
|
2572
|
+
* - `provider`: A valid EIP-1193 provider (e.g., MetaMask, WalletConnect, etc.).
|
|
2573
|
+
* - `chain`: The blockchain network to use for the adapter. Accepts a chain identifier string, enum, or chain definition.
|
|
2574
|
+
*
|
|
2575
|
+
* Optional:
|
|
2576
|
+
* - `getProvider`: A custom function to instantiate an Ethers Provider for the specified chain.
|
|
2577
|
+
* Receives an object with a `chain` property of type {@link EVMChainDefinition}.
|
|
2578
|
+
*
|
|
2579
|
+
* The `chain` parameter determines which network the adapter will operate on, regardless of the wallet's current network.
|
|
2580
|
+
* This enables cross-chain workflows and explicit network targeting.
|
|
2581
|
+
*/
|
|
2582
|
+
interface CreateAdapterFromProviderParams {
|
|
2583
|
+
/**
|
|
2584
|
+
* The EIP-1193-compatible provider for wallet operations.
|
|
2585
|
+
* @remarks
|
|
2586
|
+
* This should be a valid EIP-1193 provider such as:
|
|
2587
|
+
* - Browser wallet providers (MetaMask, WalletConnect, etc.)
|
|
2588
|
+
* - Custom providers that implement the EIP-1193 standard
|
|
2589
|
+
* - Mobile wallet providers via WalletConnect
|
|
2590
|
+
*
|
|
2591
|
+
* The provider must support the required methods:
|
|
2592
|
+
* - `request()` for making JSON-RPC calls
|
|
2593
|
+
* - `enable()` or equivalent for requesting account access
|
|
2594
|
+
*/
|
|
2595
|
+
provider: Eip1193Provider;
|
|
2596
|
+
/**
|
|
2597
|
+
* The blockchain network to use for the adapter.
|
|
2598
|
+
* @remarks
|
|
2599
|
+
* This chain will be used as the intended chain for the adapter.
|
|
2600
|
+
* The adapter will use this chain instead of the wallet's current network.
|
|
2601
|
+
*/
|
|
2602
|
+
chain: ChainIdentifier;
|
|
2603
|
+
/**
|
|
2604
|
+
* Optional function to provide a custom Ethers Provider instance.
|
|
2605
|
+
* @remarks
|
|
2606
|
+
* If not provided, a default Provider will be created using the chain's RPC endpoints.
|
|
2607
|
+
* Use this to inject custom provider logic, such as:
|
|
2608
|
+
* - Custom retry or caching strategies
|
|
2609
|
+
* - Enhanced logging or monitoring
|
|
2610
|
+
* - Support for non-standard transports
|
|
2611
|
+
*
|
|
2612
|
+
* @param chain - The chain definition for which to create the provider.
|
|
2613
|
+
* @returns A configured Provider instance.
|
|
2614
|
+
*/
|
|
2615
|
+
getProvider?: (params: {
|
|
2616
|
+
chain: EVMChainDefinition;
|
|
2617
|
+
}) => Provider;
|
|
2618
|
+
}
|
|
2619
|
+
/**
|
|
2620
|
+
* Creates an EthersAdapter instance from an EIP-1193 provider.
|
|
2621
|
+
*
|
|
2622
|
+
* This function creates an EthersAdapter for browser or injected wallet use
|
|
2623
|
+
* by connecting to the provided EIP-1193-compatible provider.
|
|
2624
|
+
* It's ideal for dApps, browser-based integrations, or scenarios where the user controls the wallet.
|
|
2625
|
+
*
|
|
2626
|
+
* @remarks
|
|
2627
|
+
* The function performs the following operations:
|
|
2628
|
+
* 1. Validates the input parameters at runtime
|
|
2629
|
+
* 2. Creates a cached provider factory (or uses a custom one if provided)
|
|
2630
|
+
* 3. Instantiates a BrowserProvider for the injected provider
|
|
2631
|
+
* 4. Requests account access and retrieves the signer
|
|
2632
|
+
* 5. Returns a configured EthersAdapter instance
|
|
2633
|
+
*
|
|
2634
|
+
* The adapter will be ready to use immediately after creation with the
|
|
2635
|
+
* specified provider and signer active. If a custom provider factory is provided,
|
|
2636
|
+
* those settings will be respected for all operations.
|
|
2637
|
+
*
|
|
2638
|
+
* **Supported parameter combinations:**
|
|
2639
|
+
* - Provide `provider` and `chain` (uses default provider logic).
|
|
2640
|
+
* - Provide `provider`, `chain`, and a custom `getProvider` function (for advanced provider instantiation).
|
|
2641
|
+
*
|
|
2642
|
+
* **Security Note:** This function is intended for use with injected/browser wallets.
|
|
2643
|
+
* Do not use in server-side code with private keys.
|
|
2644
|
+
*
|
|
2645
|
+
* @param params - Configuration parameters for creating the adapter. Must include:
|
|
2646
|
+
* - `provider`: An EIP-1193-compatible provider (e.g., MetaMask, WalletConnect, etc.)
|
|
2647
|
+
* - `chain`: The blockchain network identifier (string, enum, or ChainDefinition)
|
|
2648
|
+
* - `getProvider` (optional): A custom function to create a JsonRpcProvider
|
|
2649
|
+
* @returns A configured EthersAdapter instance
|
|
2650
|
+
* @throws Error when validation fails or provider/signing fails
|
|
2651
|
+
*
|
|
2652
|
+
* @example
|
|
2653
|
+
* ```typescript
|
|
2654
|
+
* import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
|
|
2655
|
+
*
|
|
2656
|
+
* // Basic usage with default provider
|
|
2657
|
+
* const adapter = await createAdapterFromProvider({
|
|
2658
|
+
* provider: window.ethereum,
|
|
2659
|
+
* chain: 'Ethereum'
|
|
2660
|
+
* })
|
|
2661
|
+
* ```
|
|
2662
|
+
*
|
|
2663
|
+
* @example
|
|
2664
|
+
* ```typescript
|
|
2665
|
+
* import { createAdapterFromProvider } from '@circle-fin/adapter-ethers-v6'
|
|
2666
|
+
* import { JsonRpcProvider } from 'ethers'
|
|
2667
|
+
*
|
|
2668
|
+
* // Advanced usage with custom provider logic
|
|
2669
|
+
* const adapter = await createAdapterFromProvider({
|
|
2670
|
+
* provider: window.ethereum,
|
|
2671
|
+
* chain: 'Ethereum',
|
|
2672
|
+
* getProvider: ({ chain }) => new JsonRpcProvider('https://...')
|
|
2673
|
+
* })
|
|
2674
|
+
* ```
|
|
2675
|
+
*/
|
|
2676
|
+
declare const createAdapterFromProvider: (params: CreateAdapterFromProviderParams) => Promise<EthersAdapter>;
|
|
2677
|
+
|
|
2678
|
+
export { EthersAdapter, createAdapterFromPrivateKey, createAdapterFromProvider };
|
|
2679
|
+
export type { ChainIdentifier, CreateAdapterFromPrivateKeyParams, CreateAdapterFromProviderParams, EthersAdapterOptions };
|