@@ -169,7 +169,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
169
169
170
170
async * placeInitialOffer (
171
171
sender : AnySolanaAddress ,
172
- vaa : FastTransfer . VAA ,
172
+ vaa : VAA < "FastTransfer:FastMarketOrder" > ,
173
173
offerPrice : bigint ,
174
174
totalDeposit ?: bigint ,
175
175
) {
@@ -189,7 +189,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
189
189
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.placeInitialOffer" ) ;
190
190
}
191
191
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
+ ) {
193
197
const participant = new SolanaAddress ( sender ) . unwrap ( ) ;
194
198
const auction = this . auctionAddress ( keccak256 ( vaa . hash ) ) ;
195
199
@@ -201,11 +205,9 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
201
205
202
206
async * executeFastOrder (
203
207
sender : AnySolanaAddress ,
204
- vaa : FastTransfer . VAA ,
208
+ vaa : VAA < "FastTransfer:FastMarketOrder" > ,
205
209
participant ?: AnySolanaAddress ,
206
210
) {
207
- if ( vaa . payloadLiteral !== "FastTransfer:FastMarketOrder" ) throw new Error ( "Invalid VAA" ) ;
208
-
209
211
const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
210
212
211
213
const initialParticipant = participant
@@ -219,6 +221,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
219
221
220
222
const digest = keccak256 ( vaa . hash ) ;
221
223
const auction = this . auctionAddress ( digest ) ;
224
+
225
+ // TODO: make sure this has already been done, or do it here
222
226
const reservedSequence = this . reservedFastFillSequenceAddress ( digest ) ;
223
227
224
228
const { targetChain } = vaa . payload ;
@@ -272,6 +276,14 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
272
276
Buffer . from ( finalized . hash ) ,
273
277
) ;
274
278
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
+
275
287
const ix = await this . prepareOrderResponseCctpIx (
276
288
{ payer, fastVaa, finalizedVaa } ,
277
289
{
@@ -288,75 +300,34 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
288
300
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.prepareOrderResponse" ) ;
289
301
}
290
302
291
- async * settleAuctionComplete (
303
+ async * settleOrder (
292
304
sender : AnySolanaAddress ,
293
305
fast : VAA < "FastTransfer:FastMarketOrder" > ,
294
- finalized : VAA < "FastTransfer:CctpDeposit" > ,
295
- cctp : {
306
+ finalized ? : VAA < "FastTransfer:CctpDeposit" > ,
307
+ cctp ? : {
296
308
message : CircleBridge . Message ;
297
309
attestation : CircleAttestation ;
298
310
} ,
299
311
lookupTables ?: AddressLookupTableAccount [ ] ,
300
312
) {
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 ) ;
320
317
318
+ const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
321
319
const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
322
320
323
- const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
324
- units : 300_000 ,
325
- } ) ;
326
-
327
- const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
328
321
const settleIx = await this . settleAuctionCompleteIx ( {
329
322
executor,
330
323
preparedOrderResponse : preparedAddress ,
331
324
} ) ;
332
325
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 ) ;
339
327
340
328
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.settleAuctionComplete" ) ;
341
329
}
342
330
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
-
360
331
private async createTx (
361
332
payerKey : PublicKey ,
362
333
instructions : TransactionInstruction [ ] ,
0 commit comments