@circle-fin/bridge-kit 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/QUICKSTART.md +1 -1
- package/README.md +54 -17
- package/chains.cjs +6 -3
- package/chains.d.ts +3 -3
- package/chains.mjs +6 -3
- package/index.cjs +413 -60
- package/index.d.ts +2599 -10
- package/index.mjs +405 -61
- package/package.json +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @circle-fin/bridge-kit
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add optional filtering to `getSupportedChains()` method to filter chains by type (EVM, Solana) and network (mainnet/testnet)
|
|
8
|
+
|
|
9
|
+
## 1.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- **Enhanced bridge estimate response**: `EstimateResult` now includes `token`, `amount`, `source`, `destination` fields to provide complete transfer information alongside cost estimates.
|
|
14
|
+
- Export error handling utilities and constants.
|
|
15
|
+
|
|
16
|
+
New exports include:
|
|
17
|
+
|
|
18
|
+
- Error type guards: isKitError, isBalanceError, isOnchainError, isRpcError, isNetworkError, isRetryableError, isFatalError
|
|
19
|
+
- Error constants: BalanceError, OnchainError, RpcError, NetworkError, InputError
|
|
20
|
+
- Utility: getErrorCode, getErrorMessage
|
|
21
|
+
|
|
3
22
|
## 1.2.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/QUICKSTART.md
CHANGED
|
@@ -1421,7 +1421,7 @@ const attestation = await retryWithBackoff(
|
|
|
1421
1421
|
|
|
1422
1422
|
## Next Steps
|
|
1423
1423
|
|
|
1424
|
-
- **Explore Examples**: Check out the [examples directory](https://github.com/
|
|
1424
|
+
- **Explore Examples**: Check out the [examples directory](https://github.com/crcl-main/stablecoin-kits-private/tree/main/examples) for more detailed implementations
|
|
1425
1425
|
- **Join the community**: Connect with other developers on [discord](https://discord.com/invite/buildoncircle) building on Circle's stablecoin infrastructure
|
|
1426
1426
|
|
|
1427
1427
|
Ready to start bridging? Let's make cross-chain bridging as easy as a single function call! 🌉
|
package/README.md
CHANGED
|
@@ -194,26 +194,50 @@ const resultWithDifferentAdapter = await kit.bridge({
|
|
|
194
194
|
|
|
195
195
|
**Best for**: Production applications, better reliability, custom configuration
|
|
196
196
|
|
|
197
|
+
Bridging involves **two chains** (source and destination), and both require properly configured RPC endpoints. Use dynamic RPC mapping by chain ID to support multiple chains in a single adapter:
|
|
198
|
+
|
|
197
199
|
```typescript
|
|
198
|
-
import
|
|
200
|
+
import 'dotenv/config'
|
|
201
|
+
import { BridgeKit } from '@circle-fin/bridge-kit'
|
|
202
|
+
import { Ethereum, Base } from '@circle-fin/bridge-kit/chains'
|
|
203
|
+
import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
|
|
204
|
+
import { createPublicClient, http, fallback } from 'viem'
|
|
205
|
+
|
|
206
|
+
// Define RPCs mapped by chain ID
|
|
207
|
+
const RPC_BY_CHAIN_ID: Record<number, string[]> = {
|
|
208
|
+
// The array allows providing multiple RPC URLs for fallback, e.g.,
|
|
209
|
+
// `[ "https://primary-rpc-url.com/...", "https://secondary-rpc-url.com/..." ]`
|
|
210
|
+
[Ethereum.chainId]: [
|
|
211
|
+
`https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`,
|
|
212
|
+
],
|
|
213
|
+
[Base.chainId]: [
|
|
214
|
+
`https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`,
|
|
215
|
+
],
|
|
216
|
+
}
|
|
199
217
|
|
|
200
|
-
// Production-ready setup with custom RPC endpoints
|
|
201
218
|
const adapter = createViemAdapterFromPrivateKey({
|
|
202
|
-
privateKey: process.env.PRIVATE_KEY as string
|
|
203
|
-
getPublicClient: ({ chain }) =>
|
|
204
|
-
|
|
219
|
+
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
|
|
220
|
+
getPublicClient: ({ chain }) => {
|
|
221
|
+
const rpcUrls = RPC_BY_CHAIN_ID[chain.id]
|
|
222
|
+
if (!rpcUrls) {
|
|
223
|
+
throw new Error(`No RPC configured for chainId=${chain.id}`)
|
|
224
|
+
}
|
|
225
|
+
return createPublicClient({
|
|
205
226
|
chain,
|
|
206
|
-
transport:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
227
|
+
transport: fallback(
|
|
228
|
+
rpcUrls.map((url) =>
|
|
229
|
+
http(url, {
|
|
230
|
+
timeout: 10_000,
|
|
231
|
+
retryCount: 3,
|
|
232
|
+
}),
|
|
233
|
+
),
|
|
212
234
|
),
|
|
213
|
-
})
|
|
235
|
+
})
|
|
236
|
+
},
|
|
214
237
|
})
|
|
215
238
|
|
|
216
|
-
|
|
239
|
+
const kit = new BridgeKit()
|
|
240
|
+
|
|
217
241
|
const result = await kit.bridge({
|
|
218
242
|
from: { adapter, chain: 'Ethereum' },
|
|
219
243
|
to: { adapter, chain: 'Base' },
|
|
@@ -221,13 +245,22 @@ const result = await kit.bridge({
|
|
|
221
245
|
})
|
|
222
246
|
```
|
|
223
247
|
|
|
248
|
+
**Best practices:**
|
|
249
|
+
|
|
250
|
+
- **Use paid RPC providers** (Alchemy, Infura, QuickNode) for improved reliability
|
|
251
|
+
- **Implement `fallback()` transport** for automatic failover between endpoints
|
|
252
|
+
- **Configure timeout and retry options** to handle network variability
|
|
253
|
+
|
|
224
254
|
### 🌐 Browser/Wallet Provider Support
|
|
225
255
|
|
|
226
256
|
**Best for**: Browser applications, wallet integrations, user-controlled transactions
|
|
227
257
|
|
|
228
258
|
```typescript
|
|
259
|
+
import { BridgeKit } from '@circle-fin/bridge-kit'
|
|
229
260
|
import { createViemAdapterFromProvider } from '@circle-fin/adapter-viem-v2'
|
|
230
261
|
|
|
262
|
+
const kit = new BridgeKit()
|
|
263
|
+
|
|
231
264
|
// Create adapters from browser wallet providers
|
|
232
265
|
const adapter = await createViemAdapterFromProvider({
|
|
233
266
|
provider: window.ethereum,
|
|
@@ -254,10 +287,10 @@ import { privateKeyToAccount } from 'viem/accounts'
|
|
|
254
287
|
|
|
255
288
|
const account = privateKeyToAccount(process.env.PRIVATE_KEY as string)
|
|
256
289
|
|
|
257
|
-
// Chain-specific RPC URLs
|
|
258
|
-
const rpcUrls = {
|
|
259
|
-
[Ethereum.
|
|
260
|
-
[Base.
|
|
290
|
+
// Chain-specific RPC URLs mapped by chain ID
|
|
291
|
+
const rpcUrls: Record<number, string> = {
|
|
292
|
+
[Ethereum.chainId]: 'https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY',
|
|
293
|
+
[Base.chainId]: 'https://base-mainnet.g.alchemy.com/v2/YOUR_KEY',
|
|
261
294
|
}
|
|
262
295
|
|
|
263
296
|
// Create one multi-chain adapter with chain-specific RPC configuration
|
|
@@ -445,8 +478,12 @@ For dynamic fee calculation across all transfers, use kit-level policies:
|
|
|
445
478
|
|
|
446
479
|
```typescript
|
|
447
480
|
import { BridgeKit } from '@circle-fin/bridge-kit'
|
|
481
|
+
import { createViemAdapterFromPrivateKey } from '@circle-fin/adapter-viem-v2'
|
|
448
482
|
|
|
449
483
|
const kit = new BridgeKit()
|
|
484
|
+
const adapter = createViemAdapterFromPrivateKey({
|
|
485
|
+
privateKey: process.env.PRIVATE_KEY as `0x${string}`,
|
|
486
|
+
})
|
|
450
487
|
|
|
451
488
|
kit.setCustomFeePolicy({
|
|
452
489
|
computeFee: (params) => {
|
package/chains.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
@@ -366,8 +366,11 @@ const ArcTestnet = defineChain({
|
|
|
366
366
|
name: 'Arc Testnet',
|
|
367
367
|
title: 'ArcTestnet',
|
|
368
368
|
nativeCurrency: {
|
|
369
|
-
name: '
|
|
370
|
-
symbol: '
|
|
369
|
+
name: 'USDC',
|
|
370
|
+
symbol: 'USDC',
|
|
371
|
+
// Arc uses native USDC with 18 decimals for gas payments (EVM standard).
|
|
372
|
+
// Note: The ERC-20 USDC contract at usdcAddress uses 6 decimals.
|
|
373
|
+
// See: https://docs.arc.network/arc/references/contract-addresses
|
|
371
374
|
decimals: 18,
|
|
372
375
|
},
|
|
373
376
|
chainId: 5042002,
|
package/chains.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
@@ -184,8 +184,8 @@ declare const ArcTestnet: {
|
|
|
184
184
|
readonly name: "Arc Testnet";
|
|
185
185
|
readonly title: "ArcTestnet";
|
|
186
186
|
readonly nativeCurrency: {
|
|
187
|
-
readonly name: "
|
|
188
|
-
readonly symbol: "
|
|
187
|
+
readonly name: "USDC";
|
|
188
|
+
readonly symbol: "USDC";
|
|
189
189
|
readonly decimals: 18;
|
|
190
190
|
};
|
|
191
191
|
readonly chainId: 5042002;
|
package/chains.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) 2026, Circle Internet Group, Inc. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*
|
|
@@ -364,8 +364,11 @@ const ArcTestnet = defineChain({
|
|
|
364
364
|
name: 'Arc Testnet',
|
|
365
365
|
title: 'ArcTestnet',
|
|
366
366
|
nativeCurrency: {
|
|
367
|
-
name: '
|
|
368
|
-
symbol: '
|
|
367
|
+
name: 'USDC',
|
|
368
|
+
symbol: 'USDC',
|
|
369
|
+
// Arc uses native USDC with 18 decimals for gas payments (EVM standard).
|
|
370
|
+
// Note: The ERC-20 USDC contract at usdcAddress uses 6 decimals.
|
|
371
|
+
// See: https://docs.arc.network/arc/references/contract-addresses
|
|
369
372
|
decimals: 18,
|
|
370
373
|
},
|
|
371
374
|
chainId: 5042002,
|