@@ -21,6 +21,7 @@ import type {
21
21
ValidatedTransferParams ,
22
22
ValidationResult ,
23
23
} from "../types.js" ;
24
+ import type { RouteTransferRequest } from "../request.js" ;
24
25
25
26
export namespace AutomaticCCTPRoute {
26
27
export type Options = {
@@ -80,19 +81,16 @@ export class AutomaticCCTPRoute<N extends Network>
80
81
return [ Wormhole . chainAddress ( chain , circle . usdcContract . get ( network , chain ) ! ) ] ;
81
82
}
82
83
83
- // get the liist of destination tokens that may be recieved on the destination chain
84
+ // get the list of destination tokens that may be received on the destination chain
84
85
static async supportedDestinationTokens < N extends Network > (
85
86
sourceToken : TokenId ,
86
87
fromChain : ChainContext < N > ,
87
88
toChain : ChainContext < N > ,
88
89
) : Promise < TokenId [ ] > {
89
90
// Ensure the source token is USDC
90
- const sourceChainUsdcContract = circle . usdcContract . get ( fromChain . network , fromChain . chain ) ;
91
- if ( ! sourceChainUsdcContract ) return [ ] ;
92
- if ( ! isSameToken (
93
- sourceToken ,
94
- Wormhole . tokenId ( fromChain . chain , sourceChainUsdcContract ) ,
95
- ) ) {
91
+ const sourceChainUsdcContract = circle . usdcContract . get ( fromChain . network , fromChain . chain ) ;
92
+ if ( ! sourceChainUsdcContract ) return [ ] ;
93
+ if ( ! isSameToken ( sourceToken , Wormhole . tokenId ( fromChain . chain , sourceChainUsdcContract ) ) ) {
96
94
return [ ] ;
97
95
}
98
96
@@ -115,10 +113,10 @@ export class AutomaticCCTPRoute<N extends Network>
115
113
return true ;
116
114
}
117
115
118
- async validate ( params : Tp ) : Promise < Vr > {
116
+ async validate ( request : RouteTransferRequest < N > , params : Tp ) : Promise < Vr > {
119
117
try {
120
118
const options = params . options ?? this . getDefaultOptions ( ) ;
121
- const normalizedParams = await this . normalizeTransferParams ( params ) ;
119
+ const normalizedParams = await this . normalizeTransferParams ( request , params ) ;
122
120
123
121
const validatedParams : Vp = {
124
122
normalizedParams,
@@ -136,10 +134,10 @@ export class AutomaticCCTPRoute<N extends Network>
136
134
}
137
135
}
138
136
139
- async quote ( params : Vp ) : Promise < QR > {
137
+ async quote ( request : RouteTransferRequest < N > , params : Vp ) : Promise < QR > {
140
138
try {
141
- return this . request . displayQuote (
142
- await CircleTransfer . quoteTransfer ( this . request . fromChain , this . request . toChain , {
139
+ return request . displayQuote (
140
+ await CircleTransfer . quoteTransfer ( request . fromChain , request . toChain , {
143
141
automatic : true ,
144
142
amount : amount . units ( params . normalizedParams . amount ) ,
145
143
nativeGas : amount . units ( params . normalizedParams . nativeGasAmount ) ,
@@ -154,16 +152,19 @@ export class AutomaticCCTPRoute<N extends Network>
154
152
}
155
153
}
156
154
157
- private async normalizeTransferParams ( params : Tp ) : Promise < AutomaticCCTPRoute . NormalizedParams > {
158
- const amt = this . request . parseAmount ( params . amount ) ;
155
+ private async normalizeTransferParams (
156
+ request : RouteTransferRequest < N > ,
157
+ params : Tp ,
158
+ ) : Promise < AutomaticCCTPRoute . NormalizedParams > {
159
+ const amt = request . parseAmount ( params . amount ) ;
159
160
160
- const ctb = await this . request . fromChain . getAutomaticCircleBridge ( ) ;
161
- const fee = await ctb . getRelayerFee ( this . request . toChain . chain ) ;
161
+ const ctb = await request . fromChain . getAutomaticCircleBridge ( ) ;
162
+ const fee = await ctb . getRelayerFee ( request . toChain . chain ) ;
162
163
163
164
const minAmount = ( fee * 105n ) / 100n ;
164
165
if ( amount . units ( amt ) < minAmount ) {
165
166
throw new Error (
166
- `Minimum amount is ${ amount . display ( this . request . amountFromBaseUnits ( minAmount ) ) } ` ,
167
+ `Minimum amount is ${ amount . display ( request . amountFromBaseUnits ( minAmount ) ) } ` ,
167
168
) ;
168
169
}
169
170
@@ -184,9 +185,9 @@ export class AutomaticCCTPRoute<N extends Network>
184
185
}
185
186
186
187
return {
187
- fee : this . request . amountFromBaseUnits ( fee ) ,
188
+ fee : request . amountFromBaseUnits ( fee ) ,
188
189
amount : amt ,
189
- nativeGasAmount : this . request . amountFromBaseUnits ( nativeGasAmount ) ,
190
+ nativeGasAmount : request . amountFromBaseUnits ( nativeGasAmount ) ,
190
191
} ;
191
192
}
192
193
@@ -204,17 +205,22 @@ export class AutomaticCCTPRoute<N extends Network>
204
205
} ;
205
206
}
206
207
207
- async initiate ( signer : Signer , quote : Q , to : ChainAddress ) : Promise < R > {
208
+ async initiate (
209
+ request : RouteTransferRequest < N > ,
210
+ signer : Signer ,
211
+ quote : Q ,
212
+ to : ChainAddress ,
213
+ ) : Promise < R > {
208
214
const { params } = quote ;
209
215
let transfer = this . toTransferDetails (
210
216
params ,
211
217
Wormhole . chainAddress ( signer . chain ( ) , signer . address ( ) ) ,
212
218
to ,
213
219
) ;
214
- let txids = await CircleTransfer . transfer < N > ( this . request . fromChain , transfer , signer ) ;
220
+ let txids = await CircleTransfer . transfer < N > ( request . fromChain , transfer , signer ) ;
215
221
216
222
const msg = await CircleTransfer . getTransferMessage (
217
- this . request . fromChain ,
223
+ request . fromChain ,
218
224
txids [ txids . length - 1 ] ! . txid ,
219
225
) ;
220
226
@@ -228,12 +234,6 @@ export class AutomaticCCTPRoute<N extends Network>
228
234
}
229
235
230
236
public override async * track ( receipt : R , timeout ?: number ) {
231
- yield * CircleTransfer . track (
232
- this . wh ,
233
- receipt ,
234
- timeout ,
235
- this . request . fromChain ,
236
- this . request . toChain ,
237
- ) ;
237
+ yield * CircleTransfer . track ( this . wh , receipt , timeout ) ;
238
238
}
239
239
}
0 commit comments