@@ -169,7 +169,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
169169
170170 async * placeInitialOffer (
171171 sender : AnySolanaAddress ,
172- vaa : FastTransfer . VAA ,
172+ vaa : VAA < "FastTransfer:FastMarketOrder" > ,
173173 offerPrice : bigint ,
174174 totalDeposit ?: bigint ,
175175 ) {
@@ -189,7 +189,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
189189 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.placeInitialOffer" ) ;
190190 }
191191
192- async * improveOffer ( sender : AnySolanaAddress , vaa : FastTransfer . VAA , offer : bigint ) {
192+ async * improveOffer (
193+ sender : AnySolanaAddress ,
194+ vaa : VAA < "FastTransfer:FastMarketOrder" > ,
195+ offer : bigint ,
196+ ) {
193197 const participant = new SolanaAddress ( sender ) . unwrap ( ) ;
194198 const auction = this . auctionAddress ( keccak256 ( vaa . hash ) ) ;
195199
@@ -201,11 +205,9 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
201205
202206 async * executeFastOrder (
203207 sender : AnySolanaAddress ,
204- vaa : FastTransfer . VAA ,
208+ vaa : VAA < "FastTransfer:FastMarketOrder" > ,
205209 participant ?: AnySolanaAddress ,
206210 ) {
207- if ( vaa . payloadLiteral !== "FastTransfer:FastMarketOrder" ) throw new Error ( "Invalid VAA" ) ;
208-
209211 const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
210212
211213 const initialParticipant = participant
@@ -219,6 +221,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
219221
220222 const digest = keccak256 ( vaa . hash ) ;
221223 const auction = this . auctionAddress ( digest ) ;
224+
225+ // TODO: make sure this has already been done, or do it here
222226 const reservedSequence = this . reservedFastFillSequenceAddress ( digest ) ;
223227
224228 const { targetChain } = vaa . payload ;
@@ -272,6 +276,14 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
272276 Buffer . from ( finalized . hash ) ,
273277 ) ;
274278
279+ const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
280+
281+ try {
282+ // Check if its already been prepared
283+ await this . fetchPreparedOrderResponse ( { address : preparedAddress } ) ;
284+ return ;
285+ } catch { }
286+
275287 const ix = await this . prepareOrderResponseCctpIx (
276288 { payer, fastVaa, finalizedVaa } ,
277289 {
@@ -288,75 +300,34 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
288300 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.prepareOrderResponse" ) ;
289301 }
290302
291- async * settleAuctionComplete (
303+ async * settleOrder (
292304 sender : AnySolanaAddress ,
293305 fast : VAA < "FastTransfer:FastMarketOrder" > ,
294- finalized : VAA < "FastTransfer:CctpDeposit" > ,
295- cctp : {
306+ finalized ? : VAA < "FastTransfer:CctpDeposit" > ,
307+ cctp ? : {
296308 message : CircleBridge . Message ;
297309 attestation : CircleAttestation ;
298310 } ,
299311 lookupTables ?: AddressLookupTableAccount [ ] ,
300312 ) {
301- const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
302-
303- const fastVaa = coreUtils . derivePostedVaaKey (
304- this . coreBridgeProgramId ( ) ,
305- Buffer . from ( fast . hash ) ,
306- ) ;
307-
308- const finalizedVaa = coreUtils . derivePostedVaaKey (
309- this . coreBridgeProgramId ( ) ,
310- Buffer . from ( finalized . hash ) ,
311- ) ;
312-
313- const prepareIx = await this . prepareOrderResponseCctpIx (
314- { payer, fastVaa, finalizedVaa } ,
315- {
316- encodedCctpMessage : Buffer . from ( CircleBridge . serialize ( cctp . message ) ) ,
317- cctpAttestation : Buffer . from ( cctp . attestation , "hex" ) ,
318- } ,
319- ) ;
313+ // If the finalized VAA and CCTP message/attestation are passed
314+ // we may try to prepare the order response
315+ if ( finalized && cctp )
316+ yield * this . prepareOrderResponse ( sender , fast , finalized , cctp , lookupTables ) ;
320317
318+ const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
321319 const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
322320
323- const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
324- units : 300_000 ,
325- } ) ;
326-
327- const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
328321 const settleIx = await this . settleAuctionCompleteIx ( {
329322 executor,
330323 preparedOrderResponse : preparedAddress ,
331324 } ) ;
332325
333- const transaction = await this . createTx (
334- executor ,
335- [ prepareIx , settleIx , computeIx ] ,
336- undefined ,
337- lookupTables ,
338- ) ;
326+ const transaction = await this . createTx ( executor , [ settleIx ] , undefined , lookupTables ) ;
339327
340328 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.settleAuctionComplete" ) ;
341329 }
342330
343- settleAuction ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
344- throw new Error ( "Method not implemented." ) ;
345- }
346-
347- getAuctionGracePeriod ( ) : Promise < number > {
348- throw new Error ( "Method not implemented." ) ;
349- }
350- getAuctionDuration ( ) : Promise < number > {
351- throw new Error ( "Method not implemented." ) ;
352- }
353- getPenaltyBlocks ( ) : Promise < number > {
354- throw new Error ( "Method not implemented." ) ;
355- }
356- getInitialPenaltyBps ( ) : Promise < number > {
357- throw new Error ( "Method not implemented." ) ;
358- }
359-
360331 private async createTx (
361332 payerKey : PublicKey ,
362333 instructions : TransactionInstruction [ ] ,
0 commit comments