1
1
import {
2
+ ComputeBudgetProgram ,
2
3
Connection ,
3
4
PublicKey ,
4
5
TransactionInstruction ,
@@ -17,8 +18,10 @@ import {
17
18
Contracts ,
18
19
UnsignedTransaction ,
19
20
VAA ,
21
+ keccak256 ,
20
22
} from "@wormhole-foundation/sdk-definitions" ;
21
23
import {
24
+ AnySolanaAddress ,
22
25
SolanaAddress ,
23
26
SolanaChains ,
24
27
SolanaPlatform ,
@@ -67,11 +70,11 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
67
70
}
68
71
69
72
async * initialize (
70
- owner : AccountAddress < C > ,
71
- ownerAssistant : AccountAddress < C > ,
72
- feeRecipient : AccountAddress < C > ,
73
+ owner : AnySolanaAddress ,
74
+ ownerAssistant : AnySolanaAddress ,
75
+ feeRecipient : AnySolanaAddress ,
73
76
params : AuctionParameters ,
74
- mint ?: AccountAddress < C > ,
77
+ mint ?: AnySolanaAddress ,
75
78
) {
76
79
const ix = await this . initializeIx (
77
80
{
@@ -86,22 +89,24 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
86
89
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.initialize" ) ;
87
90
}
88
91
89
- async * setPause ( sender : AccountAddress < C > , pause : boolean ) {
92
+ async * setPause ( sender : AnySolanaAddress , pause : boolean ) {
90
93
const payer = new SolanaAddress ( sender ) . unwrap ( ) ;
91
94
const ix = await this . setPauseIx ( { ownerOrAssistant : payer } , pause ) ;
92
95
const transaction = await this . createTx ( payer , [ ix ] ) ;
93
96
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.setPause" ) ;
94
97
}
95
98
96
99
async * registerRouter < RC extends Chain > (
97
- sender : AccountAddress < C > ,
100
+ sender : AnySolanaAddress ,
98
101
chain : RC ,
99
102
cctpDomain : number ,
100
103
router : AccountAddress < RC > ,
101
- tokenAccount ?: AccountAddress < C > ,
104
+ tokenAccount ?: AnySolanaAddress ,
102
105
) {
103
106
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 ;
105
110
const ix = await this . addCctpRouterEndpointIx (
106
111
{ ownerOrAssistant } ,
107
112
{
@@ -116,6 +121,40 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
116
121
yield this . createUnsignedTx ( { transaction } , "MatchingEngine.registerRouter" ) ;
117
122
}
118
123
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
+
119
158
async * setConfiguration ( config : {
120
159
enabled : boolean ;
121
160
maxAmount : bigint ;
@@ -126,7 +165,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
126
165
}
127
166
128
167
async * placeInitialOffer (
129
- sender : AccountAddress < C > ,
168
+ sender : AnySolanaAddress ,
130
169
vaa : FastTransfer . VAA ,
131
170
offerPrice : bigint ,
132
171
totalDeposit ?: bigint ,
@@ -144,26 +183,48 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
144
183
) ;
145
184
146
185
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" ) ;
151
187
}
152
188
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" ) ;
158
197
}
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 ( ) {
162
221
throw new Error ( "Method not implemented." ) ;
163
222
}
164
- settleAuctionComplete ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
223
+
224
+ settleAuction ( ) : AsyncGenerator < UnsignedTransaction < N , C > , any , unknown > {
165
225
throw new Error ( "Method not implemented." ) ;
166
226
}
227
+
167
228
getAuctionGracePeriod ( ) : Promise < number > {
168
229
throw new Error ( "Method not implemented." ) ;
169
230
}
0 commit comments