@@ -254,15 +254,14 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
254
254
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.executeFastOrder" ) ;
255
255
}
256
256
257
- async * prepareOrderResponse (
257
+ private async _prepareOrderResponseIx (
258
258
sender : AnySolanaAddress ,
259
259
fast : VAA < "FastTransfer:FastMarketOrder" > ,
260
260
finalized : VAA < "FastTransfer:CctpDeposit" > ,
261
261
cctp : {
262
262
message : CircleBridge . Message ;
263
263
attestation : CircleAttestation ;
264
264
} ,
265
- lookupTables ?: AddressLookupTableAccount [ ] ,
266
265
) {
267
266
const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
268
267
@@ -292,12 +291,26 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
292
291
} ,
293
292
) ;
294
293
295
- const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
296
- units : 300_000 ,
297
- } ) ;
294
+ return ix ;
295
+ }
298
296
299
- const transaction = await this . createTx ( payer , [ ix , computeIx ] , undefined , lookupTables ) ;
297
+ async * prepareOrderResponse (
298
+ sender : AnySolanaAddress ,
299
+ fast : VAA < "FastTransfer:FastMarketOrder" > ,
300
+ finalized : VAA < "FastTransfer:CctpDeposit" > ,
301
+ cctp : {
302
+ message : CircleBridge . Message ;
303
+ attestation : CircleAttestation ;
304
+ } ,
305
+ lookupTables ?: AddressLookupTableAccount [ ] ,
306
+ ) {
307
+ const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
308
+ const ix = await this . _prepareOrderResponseIx ( sender , fast , finalized , cctp ) ;
309
+ if ( ix === undefined ) return ;
310
+
311
+ const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( { units : 300_000 } ) ;
300
312
313
+ const transaction = await this . createTx ( payer , [ ix , computeIx ] , undefined , lookupTables ) ;
301
314
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.prepareOrderResponse" ) ;
302
315
}
303
316
@@ -311,20 +324,51 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
311
324
} ,
312
325
lookupTables ?: AddressLookupTableAccount [ ] ,
313
326
) {
327
+ const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
328
+
314
329
// If the finalized VAA and CCTP message/attestation are passed
315
330
// we may try to prepare the order response
331
+ // this yields its own transaction
316
332
if ( finalized && cctp )
317
333
yield * this . prepareOrderResponse ( sender , fast , finalized , cctp , lookupTables ) ;
318
334
319
- const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
320
- const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
321
-
322
- const settleIx = await this . settleAuctionCompleteIx ( {
323
- executor ,
324
- preparedOrderResponse : preparedAddress ,
325
- } ) ;
335
+ const digest = keccak256 ( fast . hash ) ;
336
+ const preparedOrderResponse = this . preparedOrderResponseAddress ( digest ) ;
337
+ const auction = this . auctionAddress ( digest ) ;
338
+ const fastVaa = coreUtils . derivePostedVaaKey (
339
+ this . coreBridgeProgramId ( ) ,
340
+ Buffer . from ( fast . hash ) ,
341
+ ) ;
326
342
327
- const transaction = await this . createTx ( executor , [ settleIx ] , undefined , lookupTables ) ;
343
+ const settleIx = await ( async ( ) => {
344
+ if ( finalized && ! cctp ) {
345
+ if ( fast . payload . targetChain === "Solana" ) {
346
+ const reservedSequence = this . reservedFastFillSequenceAddress ( digest ) ;
347
+ return await this . settleAuctionNoneLocalIx ( {
348
+ payer,
349
+ reservedSequence,
350
+ preparedOrderResponse,
351
+ auction,
352
+ } ) ;
353
+ } else {
354
+ return this . settleAuctionNoneCctpIx (
355
+ {
356
+ payer,
357
+ fastVaa,
358
+ preparedOrderResponse,
359
+ } ,
360
+ { targetChain : toChainId ( fast . payload . targetChain ) } ,
361
+ ) ;
362
+ }
363
+ } else {
364
+ return await this . settleAuctionCompleteIx ( {
365
+ executor : payer ,
366
+ preparedOrderResponse,
367
+ } ) ;
368
+ }
369
+ } ) ( ) ;
370
+
371
+ const transaction = await this . createTx ( payer , [ settleIx ] , undefined , lookupTables ) ;
328
372
329
373
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.settleAuctionComplete" ) ;
330
374
}
0 commit comments