11import {
2+ ComputeBudgetProgram ,
23 Connection ,
34 PublicKey ,
45 TransactionInstruction ,
@@ -17,8 +18,10 @@ import {
1718 Contracts ,
1819 UnsignedTransaction ,
1920 VAA ,
21+ keccak256 ,
2022} from "@wormhole-foundation/sdk-definitions" ;
2123import {
24+ AnySolanaAddress ,
2225 SolanaAddress ,
2326 SolanaChains ,
2427 SolanaPlatform ,
@@ -67,11 +70,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
6770 }
6871
6972 async * initialize (
70- owner : AccountAddress < C > ,
71- ownerAssistant : AccountAddress < C > ,
72- feeRecipient : AccountAddress < C > ,
73+ owner : AnySolanaAddress ,
74+ ownerAssistant : AnySolanaAddress ,
75+ feeRecipient : AnySolanaAddress ,
7376 params : AuctionParameters ,
74- mint ?: AccountAddress < C > ,
77+ mint ?: AnySolanaAddress ,
7578 ) {
7679 const ix = await this . initializeIx (
7780 {
@@ -86,22 +89,24 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
8689 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.initialize" ) ;
8790 }
8891
89- async * setPause ( sender : AccountAddress < C > , pause : boolean ) {
92+ async * setPause ( sender : AnySolanaAddress , pause : boolean ) {
9093 const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
9194 const ix = await this . setPauseIx ( { ownerOrAssistant : payer } , pause ) ;
9295 const transaction = await this . createTx ( payer , [ ix ] ) ;
9396 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.setPause" ) ;
9497 }
9598
9699 async * registerRouter < RC extends Chain > (
97- sender : AccountAddress < C > ,
100+ sender : AnySolanaAddress ,
98101 chain : RC ,
99102 cctpDomain : number ,
100103 router : AccountAddress < RC > ,
101- tokenAccount ?: AccountAddress < C > ,
104+ tokenAccount ?: AnySolanaAddress ,
102105 ) {
103106 const ownerOrAssistant = new SolanaAddress ( sender ) . unwrap ( ) ;
104- const mintRecipient = tokenAccount ?. toUniversalAddress ( ) . toUint8Array ( ) ?? null ;
107+ const mintRecipient = tokenAccount
108+ ? new SolanaAddress ( tokenAccount ) . toUniversalAddress ( ) . toUint8Array ( )
109+ : null ;
105110 const ix = await this . addCctpRouterEndpointIx (
106111 { ownerOrAssistant } ,
107112 {
@@ -116,6 +121,40 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
116121 yield this . createUnsignedTx ( { transaction } , "MatchingEngine.registerRouter" ) ;
117122 }
118123
124+ async * updateRouter < RC extends Chain > (
125+ sender : AnySolanaAddress ,
126+ chain : RC ,
127+ cctpDomain : number ,
128+ router : AccountAddress < RC > ,
129+ tokenAccount ?: AnySolanaAddress ,
130+ ) {
131+ const owner = new SolanaAddress ( sender ) . unwrap ( ) ;
132+ const mintRecipient = tokenAccount
133+ ? new SolanaAddress ( tokenAccount ) . toUniversalAddress ( ) . toUint8Array ( )
134+ : null ;
135+
136+ const ix = await this . updateCctpRouterEndpointIx (
137+ { owner } ,
138+ {
139+ chain : toChainId ( chain ) ,
140+ cctpDomain : cctpDomain ,
141+ address : Array . from ( router . toUniversalAddress ( ) . toUint8Array ( ) ) ,
142+ mintRecipient : mintRecipient ? Array . from ( mintRecipient ) : null ,
143+ } ,
144+ ) ;
145+
146+ const transaction = await this . createTx ( owner , [ ix ] ) ;
147+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.updateRouter" ) ;
148+ }
149+
150+ async * disableRouter < RC extends Chain > ( sender : AnySolanaAddress , chain : RC ) {
151+ const owner = new SolanaAddress ( sender ) . unwrap ( ) ;
152+ const ix = await this . disableRouterEndpointIx ( { owner } , toChainId ( chain ) ) ;
153+
154+ const transaction = await this . createTx ( owner , [ ix ] ) ;
155+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.disableRouter" ) ;
156+ }
157+
119158 async * setConfiguration ( config : {
120159 enabled : boolean ;
121160 maxAmount : bigint ;
@@ -126,7 +165,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
126165 }
127166
128167 async * placeInitialOffer (
129- sender : AccountAddress < C > ,
168+ sender : AnySolanaAddress ,
130169 vaa : FastTransfer . VAA ,
131170 offerPrice : bigint ,
132171 totalDeposit ?: bigint ,
@@ -144,26 +183,48 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
144183 ) ;
145184
146185 const transaction = await this . createTx ( payer , ixs ) ;
147- yield this . createUnsignedTx (
148- { transaction : transaction } ,
149- "MatchingEngine.placeInitialOffer" ,
150- ) ;
186+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.placeInitialOffer" ) ;
151187 }
152188
153- improveOffer (
154- id : Uint8Array ,
155- bid : bigint ,
156- ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
157- throw new Error ( "Method not implemented." ) ;
189+ async * improveOffer ( sender : AnySolanaAddress , vaa : FastTransfer . VAA , offer : bigint ) {
190+ const participant = new SolanaAddress ( sender ) . unwrap ( ) ;
191+ const auction = this . auctionAddress ( keccak256 ( vaa . hash ) ) ;
192+
193+ const ixs = await this . improveOfferIx ( { participant, auction } , { offerPrice : offer } ) ;
194+
195+ const transaction = await this . createTx ( participant , ixs ) ;
196+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.improveOffer" ) ;
158197 }
159- executeFastOrder (
160- vaa : FastTransfer . VAA ,
161- ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
198+
199+ async * executeFastOrder ( sender : AnySolanaAddress , vaa : FastTransfer . VAA ) {
200+ const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
201+
202+ const fastVaa = coreUtils . derivePostedVaaKey (
203+ this . coreBridgeProgramId ( ) ,
204+ Buffer . from ( vaa . hash ) ,
205+ ) ;
206+
207+ const ix = await this . executeFastOrderCctpIx ( {
208+ payer,
209+ fastVaa,
210+ } ) ;
211+
212+ const computeIx = ComputeBudgetProgram . setComputeUnitLimit ( {
213+ units : 300_000 ,
214+ } ) ;
215+
216+ const transaction = await this . createTx ( payer , [ ix , computeIx ] ) ;
217+ yield this . createUnsignedTx ( { transaction } , "MatchingEngine.improveOffer" ) ;
218+ }
219+
220+ async * settleAuctionComplete ( ) {
162221 throw new Error ( "Method not implemented." ) ;
163222 }
164- settleAuctionComplete ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
223+
224+ settleAuction ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
165225 throw new Error ( "Method not implemented." ) ;
166226 }
227+
167228 getAuctionGracePeriod ( ) : Promise < number > {
168229 throw new Error ( "Method not implemented." ) ;
169230 }
0 commit comments