11import {
2+ AddressLookupTableAccount ,
23 ComputeBudgetProgram ,
34 Connection ,
45 PublicKey ,
@@ -10,11 +11,12 @@ import {
1011 FastTransfer ,
1112 MatchingEngine ,
1213} from "@wormhole-foundation/example-liquidity-layer-definitions" ;
13- import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core" ;
1414import { Chain , Network , Platform , toChainId } from "@wormhole-foundation/sdk-base" ;
1515import {
1616 AccountAddress ,
1717 ChainsConfig ,
18+ CircleAttestation ,
19+ CircleBridge ,
1820 Contracts ,
1921 UnsignedTransaction ,
2022 VAA ,
@@ -28,12 +30,8 @@ import {
2830 SolanaTransaction ,
2931 SolanaUnsignedTransaction ,
3032} 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" ;
3735
3836export interface SolanaMatchingEngineContracts {
3937 matchingEngine : string ;
@@ -249,11 +247,97 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
249247 } ) ;
250248
251249 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" ) ;
253289 }
254290
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" ) ;
257341 }
258342
259343 settleAuction ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
@@ -277,6 +361,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
277361 payerKey : PublicKey ,
278362 instructions : TransactionInstruction [ ] ,
279363 recentBlockhash ?: string ,
364+ lookupTables ?: AddressLookupTableAccount [ ] ,
280365 ) : Promise < VersionedTransaction > {
281366 if ( ! recentBlockhash )
282367 ( { blockhash : recentBlockhash } = await this . _connection . getLatestBlockhash ( ) ) ;
@@ -285,7 +370,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
285370 payerKey,
286371 recentBlockhash,
287372 instructions,
288- } ) . compileToV0Message ( ) ;
373+ } ) . compileToV0Message ( lookupTables ) ;
289374 return new VersionedTransaction ( messageV0 ) ;
290375 }
291376
0 commit comments