1
+ import * as splToken from "@solana/spl-token" ;
1
2
import {
2
3
AddressLookupTableAccount ,
3
4
Connection ,
5
+ Keypair ,
4
6
PublicKey ,
5
7
TransactionInstruction ,
6
8
TransactionMessage ,
@@ -10,15 +12,14 @@ import {
10
12
FastTransfer ,
11
13
TokenRouter ,
12
14
} from "@wormhole-foundation/example-liquidity-layer-definitions" ;
13
- import { Chain , Network , Platform } from "@wormhole-foundation/sdk-base" ;
15
+ import { Chain , Network , Platform , toChainId } from "@wormhole-foundation/sdk-base" ;
14
16
import {
15
17
AccountAddress ,
16
18
ChainAddress ,
17
19
ChainsConfig ,
18
20
CircleBridge ,
19
21
Contracts ,
20
22
UnsignedTransaction ,
21
- VAA ,
22
23
} from "@wormhole-foundation/sdk-definitions" ;
23
24
import {
24
25
AnySolanaAddress ,
@@ -88,8 +89,47 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
88
89
yield this . createUnsignedTx ( { transaction } , "TokenRouter.Initialize" ) ;
89
90
}
90
91
91
- getInitialAuctionFee ( ) : Promise < bigint > {
92
- throw new Error ( "Method not implemented." ) ;
92
+ async * prepareMarketOrder (
93
+ sender : AnySolanaAddress ,
94
+ amount : bigint ,
95
+ redeemer : ChainAddress < Chain > ,
96
+ minAmountOut ?: bigint ,
97
+ redeemerMessage ?: Uint8Array ,
98
+ preparedOrder ?: Keypair ,
99
+ ) {
100
+ const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
101
+
102
+ // assume sender token is the usdc mint address
103
+ const senderToken = splToken . getAssociatedTokenAddressSync ( this . mint , payer ) ;
104
+
105
+ // Where we'll write the prepared order
106
+ preparedOrder = preparedOrder ?? Keypair . generate ( ) ;
107
+
108
+ const [ approveIx , prepareIx ] = await this . prepareMarketOrderIx (
109
+ {
110
+ payer,
111
+ senderToken,
112
+ preparedOrder : preparedOrder . publicKey ,
113
+ } ,
114
+ {
115
+ amountIn : amount ,
116
+ minAmountOut : minAmountOut ? minAmountOut : null ,
117
+ targetChain : toChainId ( redeemer . chain ) ,
118
+ redeemer : Array . from ( redeemer . address . toUniversalAddress ( ) . toUint8Array ( ) ) ,
119
+ redeemerMessage : redeemerMessage ? Buffer . from ( redeemerMessage ) : Buffer . from ( "" ) ,
120
+ } ,
121
+ ) ;
122
+
123
+ // TODO: fix prepareMarketOrderIx to not return null at all
124
+ const ixs = [ ] ;
125
+ if ( approveIx ) ixs . push ( approveIx ) ;
126
+ ixs . push ( prepareIx ) ;
127
+
128
+ const transaction = this . createTx ( payer , ixs ) ;
129
+ yield this . createUnsignedTx (
130
+ { transaction, signers : [ preparedOrder ] } ,
131
+ "TokenRouter.PrepareMarketOrder" ,
132
+ ) ;
93
133
}
94
134
95
135
placeMarketOrder (
@@ -101,6 +141,7 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
101
141
) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
102
142
throw new Error ( "Method not implemented." ) ;
103
143
}
144
+
104
145
placeFastMarketOrder < RC extends Chain > (
105
146
amount : bigint ,
106
147
chain : RC ,
@@ -113,6 +154,7 @@ export class SolanaTokenRouter<N extends Network, C extends SolanaChains>
113
154
) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
114
155
throw new Error ( "Method not implemented." ) ;
115
156
}
157
+
116
158
redeemFill (
117
159
vaa : FastTransfer . VAA ,
118
160
cctp : CircleBridge . Attestation ,
0 commit comments