@@ -18,7 +18,6 @@ import {
18
18
CircleAttestation ,
19
19
CircleBridge ,
20
20
Contracts ,
21
- UnsignedTransaction ,
22
21
VAA ,
23
22
keccak256 ,
24
23
} from "@wormhole-foundation/sdk-definitions" ;
@@ -30,8 +29,9 @@ import {
30
29
SolanaTransaction ,
31
30
SolanaUnsignedTransaction ,
32
31
} from "@wormhole-foundation/sdk-solana" ;
33
- import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core " ;
32
+ import { vaaHash } from "../common " ;
34
33
import { AuctionParameters , MatchingEngineProgram , ProgramId } from "../matchingEngine" ;
34
+ import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core" ;
35
35
36
36
export interface SolanaMatchingEngineContracts {
37
37
matchingEngine : string ;
@@ -42,6 +42,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
42
42
extends MatchingEngineProgram
43
43
implements MatchingEngine < N , C >
44
44
{
45
+ coreBridge : SolanaWormholeCore < N , C > ;
46
+
45
47
constructor (
46
48
readonly _network : N ,
47
49
readonly _chain : C ,
@@ -54,6 +56,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
54
56
_contracts . matchingEngine as ProgramId ,
55
57
new PublicKey ( _contracts . usdcMint ) ,
56
58
) ;
59
+
60
+ this . coreBridge = new SolanaWormholeCore ( _network , _chain , _connection , {
61
+ coreBridge : this . coreBridgeProgramId ( ) . toBase58 ( ) ,
62
+ ...this . _contracts ,
63
+ } ) ;
57
64
}
58
65
59
66
static async fromRpc < N extends Network > (
@@ -160,6 +167,10 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
160
167
throw new Error ( "Method not implemented." ) ;
161
168
}
162
169
170
+ async * postVaa ( sender : AnySolanaAddress , vaa : FastTransfer . VAA ) {
171
+ yield * this . coreBridge . postVaa ( sender , vaa ) ;
172
+ }
173
+
163
174
async * placeInitialOffer (
164
175
sender : AnySolanaAddress ,
165
176
vaa : VAA < "FastTransfer:FastMarketOrder" > ,
@@ -168,10 +179,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
168
179
) {
169
180
const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
170
181
171
- const vaaAddress = coreUtils . derivePostedVaaKey (
172
- this . coreBridgeProgramId ( ) ,
173
- Buffer . from ( vaa . hash ) ,
174
- ) ;
182
+ const vaaAddress = this . pdas . postedVaa ( vaa ) ;
175
183
176
184
const ixs = await this . placeInitialOfferCctpIx (
177
185
{ payer, fastVaa : vaaAddress } ,
@@ -196,6 +204,10 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
196
204
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.improveOffer" ) ;
197
205
}
198
206
207
+ async * reserveFastFillSequence ( ) {
208
+ throw new Error ( "Method not implemented." ) ;
209
+ }
210
+
199
211
async * executeFastOrder (
200
212
sender : AnySolanaAddress ,
201
213
vaa : VAA < "FastTransfer:FastMarketOrder" > ,
@@ -207,16 +219,15 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
207
219
? new SolanaAddress ( participant ) . unwrap ( )
208
220
: undefined ;
209
221
210
- const fastVaa = coreUtils . derivePostedVaaKey (
211
- this . coreBridgeProgramId ( ) ,
212
- Buffer . from ( vaa . hash ) ,
213
- ) ;
222
+ const fastVaa = this . pdas . postedVaa ( vaa ) ;
214
223
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 ) ;
217
228
218
229
// TODO: make sure this has already been done, or do it here
219
- const reservedSequence = this . reservedFastFillSequenceAddress ( digest ) ;
230
+ // yield* this.reserveFastFillSequence( );
220
231
221
232
const { targetChain } = vaa . payload ;
222
233
@@ -258,15 +269,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
258
269
) {
259
270
const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
260
271
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 ) ;
270
274
271
275
const preparedAddress = this . preparedOrderResponseAddress ( keccak256 ( fast . hash ) ) ;
272
276
@@ -340,10 +344,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
340
344
const digest = keccak256 ( fast . hash ) ;
341
345
const preparedOrderResponse = this . preparedOrderResponseAddress ( digest ) ;
342
346
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 ) ;
347
348
348
349
const settleIx = await ( async ( ) => {
349
350
if ( finalized && ! cctp ) {
0 commit comments