@@ -10,19 +10,15 @@ import {
1010} from "@solana/web3.js" ;
1111import {
1212 FastMarketOrder ,
13- FastTransfer ,
14- Message ,
1513 TokenRouter ,
1614} 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" ;
1816import {
19- AccountAddress ,
20- ChainAddress ,
2117 ChainsConfig ,
2218 CircleBridge ,
2319 Contracts ,
24- UniversalAddress ,
2520 UnsignedTransaction ,
21+ VAA ,
2622} from "@wormhole-foundation/sdk-definitions" ;
2723import {
2824 AnySolanaAddress ,
@@ -33,31 +29,36 @@ import {
3329 SolanaUnsignedTransaction ,
3430} from "@wormhole-foundation/sdk-solana" ;
3531import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core" ;
36- import { ProgramId , TokenRouterProgram } from "../tokenRouter" ;
32+ import { TokenRouterProgram } from "../tokenRouter" ;
33+ import { SolanaMatchingEngine } from "./matchingEngine" ;
3734
3835export interface SolanaTokenRouterContracts {
3936 tokenRouter : string ;
4037 usdcMint : string ;
38+ coreBridge : string ;
39+ matchingEngine : string ;
40+ messageTransmitter : string ;
41+ tokenMessenger : string ;
42+ upgradeManager : string ;
4143}
4244
4345export class SolanaTokenRouter < N extends Network , C extends SolanaChains >
4446 extends TokenRouterProgram
4547 implements TokenRouter < N , C >
4648{
4749 coreBridge : SolanaWormholeCore < N , C > ;
50+ matchingEngine : SolanaMatchingEngine < N , C > ;
4851
4952 constructor (
5053 readonly _network : N ,
5154 readonly _chain : C ,
5255 readonly _connection : Connection ,
5356 readonly _contracts : Contracts & SolanaTokenRouterContracts ,
5457 ) {
55- super ( _connection , _contracts . tokenRouter as ProgramId , new PublicKey ( _contracts . usdcMint ) ) ;
58+ super ( _connection , _contracts . tokenRouter , _contracts ) ;
5659
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 ) ;
6162 }
6263
6364 static async fromRpc < N extends Network > (
@@ -89,7 +90,7 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
8990 const ix = await this . initializeIx ( {
9091 owner : sender ,
9192 ownerAssistant : new SolanaAddress ( ownerAssistant ) . unwrap ( ) ,
92- mint : mint ? new SolanaAddress ( mint ) . unwrap ( ) : undefined ,
93+ mint : mint ? new SolanaAddress ( mint ) . unwrap ( ) : this . mint ,
9394 } ) ;
9495
9596 const transaction = this . createTx ( sender , [ ix ] ) ;
@@ -231,23 +232,42 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
231232 yield this . createUnsignedTx ( { transaction, signers } , "TokenRouter.PlaceMarketOrder" ) ;
232233 }
233234
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" > ,
249238 cctp : CircleBridge . Attestation ,
250239 ) : 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+
251271 throw new Error ( "Method not implemented." ) ;
252272 }
253273
0 commit comments