1
1
import {
2
+ AddressLookupTableAccount ,
2
3
ComputeBudgetProgram ,
3
4
Connection ,
4
5
PublicKey ,
@@ -10,11 +11,12 @@ import {
10
11
FastTransfer ,
11
12
MatchingEngine ,
12
13
} from "@wormhole-foundation/example-liquidity-layer-definitions" ;
13
- import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core" ;
14
14
import { Chain , Network , Platform , toChainId } from "@wormhole-foundation/sdk-base" ;
15
15
import {
16
16
AccountAddress ,
17
17
ChainsConfig ,
18
+ CircleAttestation ,
19
+ CircleBridge ,
18
20
Contracts ,
19
21
UnsignedTransaction ,
20
22
VAA ,
@@ -28,12 +30,8 @@ import {
28
30
SolanaTransaction ,
29
31
SolanaUnsignedTransaction ,
30
32
} from "@wormhole-foundation/sdk-solana" ;
31
- import {
32
- AuctionInfo ,
33
- AuctionParameters ,
34
- MatchingEngineProgram ,
35
- ProgramId ,
36
- } from "../matchingEngine" ;
33
+ import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core" ;
34
+ import { AuctionParameters , MatchingEngineProgram , ProgramId } from "../matchingEngine" ;
37
35
38
36
export interface SolanaMatchingEngineContracts {
39
37
matchingEngine : string ;
@@ -249,11 +247,97 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
249
247
} ) ;
250
248
251
249
const transaction = await this . createTx ( payer , [ ix , computeIx ] ) ;
252
- yield this . createUnsignedTx ( { transaction } , "MatchingEngine.improveOffer" ) ;
250
+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.executeFastOrder" ) ;
251
+ }
252
+
253
+ async * prepareOrderResponse (
254
+ sender : AnySolanaAddress ,
255
+ fast : VAA < "FastTransfer:FastMarketOrder" > ,
256
+ finalized : VAA < "FastTransfer:CctpDeposit" > ,
257
+ cctp : {
258
+ message : CircleBridge . Message ;
259
+ attestation : CircleAttestation ;
260
+ } ,
261
+ lookupTables ?: AddressLookupTableAccount [ ] ,
262
+ ) {
263
+ const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
264
+
265
+ const fastVaa = coreUtils . derivePostedVaaKey (
266
+ this . coreBridgeProgramId ( ) ,
267
+ Buffer . from ( fast . hash ) ,
268
+ ) ;
269
+
270
+ const finalizedVaa = coreUtils . derivePostedVaaKey (
271
+ this . coreBridgeProgramId ( ) ,
272
+ Buffer . from ( finalized . hash ) ,
273
+ ) ;
274
+
275
+ const ix = await this . prepareOrderResponseCctpIx (
276
+ { payer, fastVaa, finalizedVaa } ,
277
+ {
278
+ encodedCctpMessage : Buffer . from ( CircleBridge . serialize ( cctp . message ) ) ,
279
+ cctpAttestation : Buffer . from ( cctp . attestation , "hex" ) ,
280
+ } ,
281
+ ) ;
282
+
283
+ const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
284
+ units : 300_000 ,
285
+ } ) ;
286
+
287
+ const transaction = await this . createTx ( payer , [ ix , computeIx ] , undefined , lookupTables ) ;
288
+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.prepareOrderResponse" ) ;
253
289
}
254
290
255
- async * settleAuctionComplete ( ) {
256
- throw "Not implemented" ;
291
+ async * settleAuctionComplete (
292
+ sender : AnySolanaAddress ,
293
+ fast : VAA < "FastTransfer:FastMarketOrder" > ,
294
+ finalized : VAA < "FastTransfer:CctpDeposit" > ,
295
+ cctp : {
296
+ message : CircleBridge . Message ;
297
+ attestation : CircleAttestation ;
298
+ } ,
299
+ lookupTables ?: AddressLookupTableAccount [ ] ,
300
+ ) {
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
+ ) ;
320
+
321
+ const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
322
+
323
+ const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
324
+ units : 300_000 ,
325
+ } ) ;
326
+
327
+ const executor = new SolanaAddress ( sender ) . unwrap ( ) ;
328
+ const settleIx = await this . settleAuctionCompleteIx ( {
329
+ executor,
330
+ preparedOrderResponse : preparedAddress ,
331
+ } ) ;
332
+
333
+ const transaction = await this . createTx (
334
+ executor ,
335
+ [ prepareIx , settleIx , computeIx ] ,
336
+ undefined ,
337
+ lookupTables ,
338
+ ) ;
339
+
340
+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.settleAuctionComplete" ) ;
257
341
}
258
342
259
343
settleAuction ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
@@ -277,6 +361,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
277
361
payerKey : PublicKey ,
278
362
instructions : TransactionInstruction [ ] ,
279
363
recentBlockhash ?: string ,
364
+ lookupTables ?: AddressLookupTableAccount [ ] ,
280
365
) : Promise < VersionedTransaction > {
281
366
if ( ! recentBlockhash )
282
367
( { blockhash : recentBlockhash } = await this . _connection . getLatestBlockhash ( ) ) ;
@@ -285,7 +370,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
285
370
payerKey,
286
371
recentBlockhash,
287
372
instructions,
288
- } ) . compileToV0Message ( ) ;
373
+ } ) . compileToV0Message ( lookupTables ) ;
289
374
return new VersionedTransaction ( messageV0 ) ;
290
375
}
291
376
0 commit comments