@circle-fin/provider-cctp-v2 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 +375 -0
- package/index.cjs.js +4648 -0
- package/index.cjs.js.map +1 -0
- package/index.d.ts +3267 -0
- package/index.mjs +4642 -0
- package/index.mjs.map +1 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Circle Internet Financial Limited
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# CCTPv2 Bridging Provider
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/@circle-fin%2Fprovider-cctp-v2)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
8
|
+
|
|
9
|
+
**Circle's Cross-Chain Transfer Protocol v2 provider for Stablecoin Kits**
|
|
10
|
+
|
|
11
|
+
_Native USDC bridging across 24+ chains using Circle's battle-tested protocols._
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [CCTPv2 Bridging Provider](#cctpv2-bridging-provider)
|
|
20
|
+
- [Table of Contents](#table-of-contents)
|
|
21
|
+
- [Overview](#overview)
|
|
22
|
+
- [Why CCTPv2 Provider?](#why-cctpv2-provider)
|
|
23
|
+
- [Installation](#installation)
|
|
24
|
+
- [Quick Start](#quick-start)
|
|
25
|
+
- [Option 1: With Bridging Kit (Recommended)](#option-1-with-bridging-kit-recommended)
|
|
26
|
+
- [Option 2: Direct Provider Usage](#option-2-direct-provider-usage)
|
|
27
|
+
- [Features](#features)
|
|
28
|
+
- [Supported Chains \& Routes](#supported-chains--routes)
|
|
29
|
+
- [Mainnet Chains (12 chains)](#mainnet-chains-12-chains)
|
|
30
|
+
- [Testnet Chains (12 chains)](#testnet-chains-12-chains)
|
|
31
|
+
- [Usage Examples](#usage-examples)
|
|
32
|
+
- [Basic Bridge Operation](#basic-bridge-operation)
|
|
33
|
+
- [Route Validation](#route-validation)
|
|
34
|
+
- [Bridge Configurations](#bridge-configurations)
|
|
35
|
+
- [Error Handling](#error-handling)
|
|
36
|
+
- [Bridge Process](#bridge-process)
|
|
37
|
+
- [Integration with Bridging Kit](#integration-with-bridging-kit)
|
|
38
|
+
- [API Reference](#api-reference)
|
|
39
|
+
- [Core Methods](#core-methods)
|
|
40
|
+
- [Transfer Parameters](#transfer-parameters)
|
|
41
|
+
- [Development](#development)
|
|
42
|
+
- [Contributing](#contributing)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
## Overview
|
|
46
|
+
|
|
47
|
+
The CCTPv2 Bridging Provider is a strongly-typed implementation of Circle's Cross-Chain Transfer Protocol (CCTP) version 2 that enables **native USDC bridging** between 24+ supported blockchain networks.
|
|
48
|
+
|
|
49
|
+
While primarily designed to power the [Bridging Kit](https://github.com/circlefin/stablecoin-kits-private/tree/main/kits/bridging-kit), this provider can also be used **directly in applications** that need fine-grained control over the CCTP transfer process or want to integrate CCTP without the full Stablecoin Kits framework.
|
|
50
|
+
|
|
51
|
+
### Why CCTPv2 Provider?
|
|
52
|
+
|
|
53
|
+
- **🔒 Circle's official protocol**: Uses Circle's native CCTP infrastructure for maximum security
|
|
54
|
+
- **⚡ 24+ chain support**: Enables bridging across all CCTPv2-supported networks
|
|
55
|
+
- **🎯 Native USDC**: Bridges actual USDC tokens, not wrapped or synthetic versions
|
|
56
|
+
- **🔧 Type-safe operations**: Built with TypeScript strict mode and comprehensive validation
|
|
57
|
+
- **🛠️ Direct integration**: Use standalone or with custom orchestration logic
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install @circle-fin/provider-cctp-v2
|
|
63
|
+
# or
|
|
64
|
+
yarn add @circle-fin/provider-cctp-v2
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> **Note**: This provider is included by default with the [Bridging Kit](https://github.com/circlefin/stablecoin-kits-private/tree/main/kits/bridging-kit). You can import this provider if you need to do a custom CCTP integration.
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
### Option 1: With Bridging Kit (Recommended)
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { BridgingKit } from '@circle-fin/bridging-kit'
|
|
75
|
+
|
|
76
|
+
// Provider included by default
|
|
77
|
+
const kit = new BridgingKit()
|
|
78
|
+
|
|
79
|
+
const result = await kit.bridge({
|
|
80
|
+
source: { adapter: sourceAdapter },
|
|
81
|
+
destination: { adapter: destAdapter },
|
|
82
|
+
amount: '100.50',
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Option 2: Direct Provider Usage
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { CCTPV2BridgingProvider } from '@circle-fin/provider-cctp-v2'
|
|
90
|
+
import { ViemAdapter } from '@circle-fin/adapter-viem-v2'
|
|
91
|
+
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
92
|
+
import { mainnet, base } from 'viem/chains'
|
|
93
|
+
import { privateKeyToAccount } from 'viem/accounts'
|
|
94
|
+
|
|
95
|
+
const account = privateKeyToAccount(process.env.PRIVATE_KEY)
|
|
96
|
+
const provider = new CCTPV2BridgingProvider()
|
|
97
|
+
|
|
98
|
+
// Create adapters
|
|
99
|
+
const sourceAdapter = new ViemAdapter({
|
|
100
|
+
publicClient: createPublicClient({ chain: mainnet, transport: http() }),
|
|
101
|
+
walletClient: createWalletClient({
|
|
102
|
+
account,
|
|
103
|
+
chain: mainnet,
|
|
104
|
+
transport: http(),
|
|
105
|
+
}),
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const destAdapter = new ViemAdapter({
|
|
109
|
+
publicClient: createPublicClient({ chain: base, transport: http() }),
|
|
110
|
+
walletClient: createWalletClient({ account, chain: base, transport: http() }),
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
// Check route support
|
|
114
|
+
const isSupported = provider.supportsRoute('Ethereum', 'Base', 'USDC')
|
|
115
|
+
|
|
116
|
+
// Get bridge estimate
|
|
117
|
+
const estimate = await provider.estimate({
|
|
118
|
+
source: { adapter: sourceAdapter },
|
|
119
|
+
destination: { adapter: destAdapter },
|
|
120
|
+
amount: '100.50',
|
|
121
|
+
config: { transferSpeed: 'FAST' },
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// Execute bridge operation with custom logic
|
|
125
|
+
const result = await provider.bridge({
|
|
126
|
+
source: { adapter: sourceAdapter },
|
|
127
|
+
destination: { adapter: destAdapter },
|
|
128
|
+
amount: '100.50',
|
|
129
|
+
config: { transferSpeed: 'FAST' },
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Features
|
|
134
|
+
|
|
135
|
+
- ✅ **Native USDC bridging** - Move real USDC between supported networks
|
|
136
|
+
- ✅ **CCTP v2 integration** - Direct integration with Circle's CCTP v2 protocol
|
|
137
|
+
- ✅ **Comprehensive validation** - Route validation and parameter checking
|
|
138
|
+
- ✅ **Multi-chain support** - Works across all 24 CCTPv2-supported chains
|
|
139
|
+
- ✅ **Type safety** - Full TypeScript support with detailed error handling
|
|
140
|
+
- ✅ **Bridge speeds** - Support for both FAST and SLOW bridge configurations
|
|
141
|
+
|
|
142
|
+
## Supported Chains & Routes
|
|
143
|
+
|
|
144
|
+
The provider supports **264 total bridge routes** across these networks:
|
|
145
|
+
|
|
146
|
+
### Mainnet Chains (12 chains)
|
|
147
|
+
|
|
148
|
+
**Arbitrum**, **Avalanche**, **Base**, **Codex**, **Ethereum**, **Linea**, **OP Mainnet**, **Polygon PoS**, **Solana**, **Sonic**, **Unichain**, **World Chain**
|
|
149
|
+
|
|
150
|
+
### Testnet Chains (12 chains)
|
|
151
|
+
|
|
152
|
+
**Arbitrum Sepolia**, **Avalanche Fuji**, **Base Sepolia**, **Codex Testnet**, **Ethereum Sepolia**, **Linea Sepolia**, **OP Sepolia**, **Polygon PoS Amoy**, **Solana Devnet**, **Sonic Testnet**, **Unichain Sepolia**, **World Chain Sepolia**
|
|
153
|
+
|
|
154
|
+
## Usage Examples
|
|
155
|
+
|
|
156
|
+
### Basic Bridge Operation
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { BridgingKit } from '@circle-fin/bridging-kit'
|
|
160
|
+
import { ViemAdapter } from '@circle-fin/adapter-viem-v2'
|
|
161
|
+
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
162
|
+
import { mainnet, base } from 'viem/chains'
|
|
163
|
+
import { privateKeyToAccount } from 'viem/accounts'
|
|
164
|
+
|
|
165
|
+
const account = privateKeyToAccount(process.env.PRIVATE_KEY)
|
|
166
|
+
const kit = new BridgingKit() // CCTPv2 provider included by default
|
|
167
|
+
|
|
168
|
+
const ethereumAdapter = new ViemAdapter({
|
|
169
|
+
publicClient: createPublicClient({ chain: mainnet, transport: http() }),
|
|
170
|
+
walletClient: createWalletClient({
|
|
171
|
+
account,
|
|
172
|
+
chain: mainnet,
|
|
173
|
+
transport: http(),
|
|
174
|
+
}),
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
const baseAdapter = new ViemAdapter({
|
|
178
|
+
publicClient: createPublicClient({ chain: base, transport: http() }),
|
|
179
|
+
walletClient: createWalletClient({ account, chain: base, transport: http() }),
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const result = await kit.bridge({
|
|
183
|
+
source: { adapter: ethereumAdapter },
|
|
184
|
+
destination: { adapter: baseAdapter },
|
|
185
|
+
amount: '100.50',
|
|
186
|
+
config: { transferSpeed: 'FAST' },
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Route Validation
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { CCTPV2BridgingProvider } from '@circle-fin/provider-cctp-v2'
|
|
194
|
+
import { BridgingKit } from '@circle-fin/bridging-kit'
|
|
195
|
+
|
|
196
|
+
const provider = new CCTPV2BridgingProvider()
|
|
197
|
+
const kit = new BridgingKit()
|
|
198
|
+
|
|
199
|
+
// Check if a route is supported
|
|
200
|
+
const isSupported = provider.supportsRoute('Ethereum', 'Base', 'USDC')
|
|
201
|
+
console.log('Ethereum → Base:', isSupported ? '✅' : '❌')
|
|
202
|
+
|
|
203
|
+
// Validate before bridging
|
|
204
|
+
const sourceChain = 'Ethereum'
|
|
205
|
+
const destChain = 'Base'
|
|
206
|
+
if (!kit.supportsRoute(sourceChain, destChain, 'USDC')) {
|
|
207
|
+
throw new Error('Route not supported')
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Bridge Configurations
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// Using the same kit and adapters from the examples above
|
|
215
|
+
// Fast bridge (higher fees, faster processing)
|
|
216
|
+
const fastResult = await kit.bridge({
|
|
217
|
+
source: { adapter: ethereumAdapter },
|
|
218
|
+
destination: { adapter: baseAdapter },
|
|
219
|
+
amount: '50.0',
|
|
220
|
+
config: { transferSpeed: 'FAST' },
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
// Slow bridge (lower fees, longer processing)
|
|
224
|
+
const slowResult = await kit.bridge({
|
|
225
|
+
source: { adapter: ethereumAdapter },
|
|
226
|
+
destination: { adapter: baseAdapter },
|
|
227
|
+
amount: '50.0',
|
|
228
|
+
config: { transferSpeed: 'SLOW' },
|
|
229
|
+
})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Error Handling
|
|
233
|
+
|
|
234
|
+
The provider implements thoughtful error handling for different scenarios:
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
// Using the same kit and adapters from the examples above
|
|
238
|
+
const params = {
|
|
239
|
+
source: { adapter: ethereumAdapter },
|
|
240
|
+
destination: { adapter: baseAdapter },
|
|
241
|
+
amount: '100.50',
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
const result = await kit.bridge(params)
|
|
246
|
+
|
|
247
|
+
if (result.state === 'success') {
|
|
248
|
+
console.log('Bridge completed successfully!')
|
|
249
|
+
|
|
250
|
+
// Display explorer URLs for each step
|
|
251
|
+
result.steps.forEach((step) => {
|
|
252
|
+
if (step.explorerUrl) {
|
|
253
|
+
console.log(`${step.name}: ${step.explorerUrl}`)
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
} else {
|
|
257
|
+
// Handle partial completion
|
|
258
|
+
const successfulSteps = result.steps.filter((s) => s.state === 'success')
|
|
259
|
+
const failedStep = result.steps.find((s) => s.state === 'error')
|
|
260
|
+
|
|
261
|
+
console.log('Successful steps:', successfulSteps)
|
|
262
|
+
console.log('Failed at:', failedStep)
|
|
263
|
+
}
|
|
264
|
+
} catch (error) {
|
|
265
|
+
// Handle validation or configuration errors
|
|
266
|
+
console.error('Bridge failed:', error.message)
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Bridge Process
|
|
271
|
+
|
|
272
|
+
The CCTPv2 provider handles the complete cross-chain bridging flow:
|
|
273
|
+
|
|
274
|
+
1. **Approval** - Approve USDC spending (if needed)
|
|
275
|
+
2. **Burn** - Burn USDC on source chain via `depositForBurn`
|
|
276
|
+
3. **Attestation** - Fetch Circle's attestation for the burn
|
|
277
|
+
4. **Mint** - Mint USDC on destination chain using attestation
|
|
278
|
+
|
|
279
|
+
Each step is tracked and can be monitored through the Provider's event system. Transaction details for each step include explorer URLs for easy verification on block explorers.
|
|
280
|
+
|
|
281
|
+
## Integration with Bridging Kit
|
|
282
|
+
|
|
283
|
+
This provider is designed specifically for the [Bridging Kit](https://github.com/circlefin/stablecoin-kits-private/tree/main/kits/bridging-kit):
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { BridgingKit } from '@circle-fin/bridging-kit'
|
|
287
|
+
import { ViemAdapter } from '@circle-fin/adapter-viem-v2'
|
|
288
|
+
import { createPublicClient, createWalletClient, http } from 'viem'
|
|
289
|
+
import { mainnet, base } from 'viem/chains'
|
|
290
|
+
import { privateKeyToAccount } from 'viem/accounts'
|
|
291
|
+
|
|
292
|
+
const account = privateKeyToAccount(process.env.PRIVATE_KEY)
|
|
293
|
+
|
|
294
|
+
// Provider is included by default
|
|
295
|
+
const kit = new BridgingKit()
|
|
296
|
+
|
|
297
|
+
const sourceAdapter = new ViemAdapter({
|
|
298
|
+
publicClient: createPublicClient({ chain: mainnet, transport: http() }),
|
|
299
|
+
walletClient: createWalletClient({
|
|
300
|
+
account,
|
|
301
|
+
chain: mainnet,
|
|
302
|
+
transport: http(),
|
|
303
|
+
}),
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
const destAdapter = new ViemAdapter({
|
|
307
|
+
publicClient: createPublicClient({ chain: base, transport: http() }),
|
|
308
|
+
walletClient: createWalletClient({ account, chain: base, transport: http() }),
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
// Monitor transfer events
|
|
312
|
+
kit.on('*', (event) => console.log('Event:', event)) // subscribe to all events
|
|
313
|
+
kit.on('approve', (event) => console.log('Approval:', event.values.txHash))
|
|
314
|
+
kit.on('depositForBurn', (event) => console.log('Burn:', event.values.txHash))
|
|
315
|
+
kit.on('attestation', (event) => console.log('Burn:', event.attestation))
|
|
316
|
+
kit.on('mint', (event) => console.log('Mint:', event.values.txHash))
|
|
317
|
+
|
|
318
|
+
// Execute transfer
|
|
319
|
+
const result = await kit.bridge({
|
|
320
|
+
source: { adapter: sourceAdapter },
|
|
321
|
+
destination: { adapter: destAdapter },
|
|
322
|
+
amount: '25.0',
|
|
323
|
+
})
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## API Reference
|
|
327
|
+
|
|
328
|
+
### Core Methods
|
|
329
|
+
|
|
330
|
+
- `supportsRoute(source, destination, token)` - Check if transfer route is supported
|
|
331
|
+
- `bridge(params)` - Execute cross-chain bridge operation
|
|
332
|
+
- `estimate(params)` - Get cost estimates for transfer
|
|
333
|
+
|
|
334
|
+
### Transfer Parameters
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
interface BridgeParams {
|
|
338
|
+
source: WalletContextWithFlexibleChain
|
|
339
|
+
destination: WalletContextWithFlexibleChain
|
|
340
|
+
amount: string
|
|
341
|
+
config?: BridgeConfig
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Development
|
|
346
|
+
|
|
347
|
+
This package is part of the Stablecoin Kits monorepo.
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
# Build
|
|
351
|
+
nx build @circle-fin/provider-cctp-v2
|
|
352
|
+
|
|
353
|
+
# Test
|
|
354
|
+
nx test @circle-fin/provider-cctp-v2
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## Contributing
|
|
358
|
+
|
|
359
|
+
We welcome contributions! Please see our [Contributing Guide](https://github.com/circlefin/stablecoin-kits-private/blob/main/CONTRIBUTING.md) for details.
|
|
360
|
+
|
|
361
|
+
## License
|
|
362
|
+
|
|
363
|
+
This project is licensed under the Apache 2.0 License - see the [LICENSE](https://github.com/circlefin/stablecoin-kits-private/blob/main/LICENSE) file for details.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
<div align="center">
|
|
368
|
+
|
|
369
|
+
**Ready for cross-chain bridging?**
|
|
370
|
+
|
|
371
|
+
[View Stablecoin Kits](https://github.com/circlefin/stablecoin-kits-private) • [Join Discord](https://discord.com/invite/buildoncircle) • [Report Issues](https://github.com/circlefin/stablecoin-kits-private/issues)
|
|
372
|
+
|
|
373
|
+
_Built with ❤️ by Circle_
|
|
374
|
+
|
|
375
|
+
</div>
|