@@ -10,19 +10,15 @@ import {
10
10
} from "@solana/web3.js" ;
11
11
import {
12
12
FastMarketOrder ,
13
- FastTransfer ,
14
- Message ,
15
13
TokenRouter ,
16
14
} from "@wormhole-foundation/example-liquidity-layer-definitions" ;
17
- import { Chain , ChainId , Network , Platform , toChainId } from "@wormhole-foundation/sdk-base" ;
15
+ import { ChainId , Network , Platform , toChainId } from "@wormhole-foundation/sdk-base" ;
18
16
import {
19
- AccountAddress ,
20
- ChainAddress ,
21
17
ChainsConfig ,
22
18
CircleBridge ,
23
19
Contracts ,
24
- UniversalAddress ,
25
20
UnsignedTransaction ,
21
+ VAA ,
26
22
} from "@wormhole-foundation/sdk-definitions" ;
27
23
import {
28
24
AnySolanaAddress ,
@@ -33,31 +29,36 @@ import {
33
29
SolanaUnsignedTransaction ,
34
30
} from "@wormhole-foundation/sdk-solana" ;
35
31
import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core" ;
36
- import { ProgramId , TokenRouterProgram } from "../tokenRouter" ;
32
+ import { TokenRouterProgram } from "../tokenRouter" ;
33
+ import { SolanaMatchingEngine } from "./matchingEngine" ;
37
34
38
35
export interface SolanaTokenRouterContracts {
39
36
tokenRouter : string ;
40
37
usdcMint : string ;
38
+ coreBridge : string ;
39
+ matchingEngine : string ;
40
+ messageTransmitter : string ;
41
+ tokenMessenger : string ;
42
+ upgradeManager : string ;
41
43
}
42
44
43
45
export class SolanaTokenRouter < N extends Network , C extends SolanaChains >
44
46
extends TokenRouterProgram
45
47
implements TokenRouter < N , C >
46
48
{
47
49
coreBridge : SolanaWormholeCore < N , C > ;
50
+ matchingEngine : SolanaMatchingEngine < N , C > ;
48
51
49
52
constructor (
50
53
readonly _network : N ,
51
54
readonly _chain : C ,
52
55
readonly _connection : Connection ,
53
56
readonly _contracts : Contracts & SolanaTokenRouterContracts ,
54
57
) {
55
- super ( _connection , _contracts . tokenRouter as ProgramId , new PublicKey ( _contracts . usdcMint ) ) ;
58
+ super ( _connection , _contracts . tokenRouter , _contracts ) ;
56
59
57
- this . coreBridge = new SolanaWormholeCore ( _network , _chain , _connection , {
58
- coreBridge : this . coreBridgeProgramId ( ) . toBase58 ( ) ,
59
- ...this . _contracts ,
60
- } ) ;
60
+ this . coreBridge = new SolanaWormholeCore ( _network , _chain , _connection , _contracts ) ;
61
+ this . matchingEngine = new SolanaMatchingEngine ( _network , _chain , _connection , _contracts ) ;
61
62
}
62
63
63
64
static async fromRpc < N extends Network > (
@@ -89,7 +90,7 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
89
90
const ix = await this . initializeIx ( {
90
91
owner : sender ,
91
92
ownerAssistant : new SolanaAddress ( ownerAssistant ) . unwrap ( ) ,
92
- mint : mint ? new SolanaAddress ( mint ) . unwrap ( ) : undefined ,
93
+ mint : mint ? new SolanaAddress ( mint ) . unwrap ( ) : this . mint ,
93
94
} ) ;
94
95
95
96
const transaction = this . createTx ( sender , [ ix ] ) ;
@@ -231,23 +232,42 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
231
232
yield this . createUnsignedTx ( { transaction, signers } , "TokenRouter.PlaceMarketOrder" ) ;
232
233
}
233
234
234
- placeFastMarketOrder < RC extends Chain > (
235
- amount : bigint ,
236
- chain : RC ,
237
- redeemer : AccountAddress < RC > ,
238
- redeemerMessage : Uint8Array ,
239
- maxFee : bigint ,
240
- deadline : number ,
241
- minAmountOut ?: bigint | undefined ,
242
- refundAddress ?: string | undefined ,
243
- ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
244
- throw new Error ( "Method not implemented." ) ;
245
- }
246
-
247
- redeemFill (
248
- vaa : FastTransfer . VAA ,
235
+ async * redeemFill (
236
+ sender : AnySolanaAddress ,
237
+ vaa : VAA < "FastTransfer:CctpDeposit" > ,
249
238
cctp : CircleBridge . Attestation ,
250
239
) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
240
+ // const payer = new SolanaAddress(sender).unwrap();
241
+
242
+ // //
243
+ // const { payload: fill } = vaa.payload;
244
+ // if (!Payload.is(fill, "Fill")) {
245
+ // throw new Error("Invalid VAA payload");
246
+ // }
247
+
248
+ // const postedVaaAddress = coreUtils.derivePostedVaaKey(
249
+ // this.coreBridge.address,
250
+ // Buffer.from(vaa.hash),
251
+ // );
252
+
253
+ // const ix = await this.redeemCctpFillIx(
254
+ // {
255
+ // payer: payer,
256
+ // vaa: postedVaaAddress,
257
+ // sourceRouterEndpoint: this.matchingEngine.routerEndpointAddress(
258
+ // toChainId(fill.sourceChain),
259
+ // ),
260
+ // },
261
+ // {
262
+ // encodedCctpMessage,
263
+ // cctpAttestation,
264
+ // },
265
+ // );
266
+
267
+ // //const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
268
+ // // units: 300_000,
269
+ // // });
270
+
251
271
throw new Error ( "Method not implemented." ) ;
252
272
}
253
273
0 commit comments