@@ -18,7 +18,6 @@ import {
1818 CircleAttestation ,
1919 CircleBridge ,
2020 Contracts ,
21- UnsignedTransaction ,
2221 VAA ,
2322 keccak256 ,
2423} from "@wormhole-foundation/sdk-definitions" ;
@@ -30,8 +29,9 @@ import {
3029 SolanaTransaction ,
3130 SolanaUnsignedTransaction ,
3231} from "@wormhole-foundation/sdk-solana" ;
33- import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core " ;
32+ import { vaaHash } from "../common " ;
3433import { AuctionParameters , MatchingEngineProgram , ProgramId } from "../matchingEngine" ;
34+ import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core" ;
3535
3636export interface SolanaMatchingEngineContracts {
3737 matchingEngine : string ;
@@ -42,6 +42,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
4242 extends MatchingEngineProgram
4343 implements MatchingEngine < N , C >
4444{
45+ coreBridge : SolanaWormholeCore < N , C > ;
46+
4547 constructor (
4648 readonly _network : N ,
4749 readonly _chain : C ,
@@ -54,6 +56,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
5456 _contracts . matchingEngine as ProgramId ,
5557 new PublicKey ( _contracts . usdcMint ) ,
5658 ) ;
59+
60+ this . coreBridge = new SolanaWormholeCore ( _network , _chain , _connection , {
61+ coreBridge : this . coreBridgeProgramId ( ) . toBase58 ( ) ,
62+ ...this . _contracts ,
63+ } ) ;
5764 }
5865
5966 static async fromRpc < N extends Network > (
@@ -160,6 +167,10 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
160167 throw new Error ( "Method not implemented." ) ;
161168 }
162169
170+ async * postVaa ( sender : AnySolanaAddress , vaa : FastTransfer . VAA ) {
171+ yield * this . coreBridge . postVaa ( sender , vaa ) ;
172+ }
173+
163174 async * placeInitialOffer (
164175 sender : AnySolanaAddress ,
165176 vaa : VAA < "FastTransfer:FastMarketOrder" > ,
@@ -168,10 +179,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
168179 ) {
169180 const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
170181
171- const vaaAddress = coreUtils . derivePostedVaaKey (
172- this . coreBridgeProgramId ( ) ,
173- Buffer . from ( vaa . hash ) ,
174- ) ;
182+ const vaaAddress = this . pdas . postedVaa ( vaa ) ;
175183
176184 const ixs = await this . placeInitialOfferCctpIx (
177185 { payer, fastVaa : vaaAddress } ,
@@ -196,6 +204,10 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
196204 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.improveOffer" ) ;
197205 }
198206
207+ async * reserveFastFillSequence ( ) {
208+ throw new Error ( "Method not implemented." ) ;
209+ }
210+
199211 async * executeFastOrder (
200212 sender : AnySolanaAddress ,
201213 vaa : VAA < "FastTransfer:FastMarketOrder" > ,
@@ -207,16 +219,15 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
207219 ? new SolanaAddress ( participant ) . unwrap ( )
208220 : undefined ;
209221
210- const fastVaa = coreUtils . derivePostedVaaKey (
211- this . coreBridgeProgramId ( ) ,
212- Buffer . from ( vaa . hash ) ,
213- ) ;
222+ const fastVaa = this . pdas . postedVaa ( vaa ) ;
214223
215- const digest = keccak256 ( vaa . hash ) ;
216- const auction = this . auctionAddress ( digest ) ;
224+ const digest = vaaHash ( vaa ) ;
225+ const auction = this . pdas . auction ( digest ) ;
226+
227+ const reservedSequence = this . pdas . reservedFastFillSequence ( digest ) ;
217228
218229 // TODO: make sure this has already been done, or do it here
219- const reservedSequence = this . reservedFastFillSequenceAddress ( digest ) ;
230+ // yield* this.reserveFastFillSequence( );
220231
221232 const { targetChain } = vaa . payload ;
222233
@@ -258,15 +269,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
258269 ) {
259270 const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
260271
261- const fastVaa = coreUtils . derivePostedVaaKey (
262- this . coreBridgeProgramId ( ) ,
263- Buffer . from ( fast . hash ) ,
264- ) ;
265-
266- const finalizedVaa = coreUtils . derivePostedVaaKey (
267- this . coreBridgeProgramId ( ) ,
268- Buffer . from ( finalized . hash ) ,
269- ) ;
272+ const fastVaa = this . pdas . postedVaa ( fast ) ;
273+ const finalizedVaa = this . pdas . postedVaa ( finalized ) ;
270274
271275 const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
272276
@@ -340,10 +344,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
340344 const digest = keccak256 ( fast . hash ) ;
341345 const preparedOrderResponse = this . preparedOrderResponseAddress ( digest ) ;
342346 const auction = this . auctionAddress ( digest ) ;
343- const fastVaa = coreUtils . derivePostedVaaKey (
344- this . coreBridgeProgramId ( ) ,
345- Buffer . from ( fast . hash ) ,
346- ) ;
347+ const fastVaa = this . pdas . postedVaa ( fast ) ;
347348
348349 const settleIx = await ( async ( ) => {
349350 if ( finalized && ! cctp ) {
0 commit comments