1
1
export * from "./state" ;
2
-
3
2
import { BN , Program , utils } from "@coral-xyz/anchor" ;
4
3
import * as splToken from "@solana/spl-token" ;
5
4
import {
@@ -15,6 +14,7 @@ import {
15
14
SystemProgram ,
16
15
TransactionInstruction ,
17
16
} from "@solana/web3.js" ;
17
+ import { MatchingEngine } from "@wormhole-foundation/example-liquidity-layer-definitions" ;
18
18
import { ChainId , isChainId , toChainId } from "@wormhole-foundation/sdk-base" ;
19
19
import { PreparedTransaction , PreparedTransactionOptions } from ".." ;
20
20
import { MessageTransmitterProgram , TokenMessengerMinterProgram } from "../cctp" ;
@@ -43,177 +43,41 @@ import {
43
43
Custodian ,
44
44
EndpointInfo ,
45
45
FastFill ,
46
- FastFillInfo ,
47
- FastFillSeeds ,
48
46
FastFillSequencer ,
49
- MessageProtocol ,
50
47
PreparedOrderResponse ,
51
48
Proposal ,
52
- ProposalAction ,
53
49
ReservedFastFillSequence ,
54
50
RouterEndpoint ,
55
51
} from "./state" ;
56
- import { MatchingEngine } from "@wormhole-foundation/example-liquidity-layer-definitions" ;
52
+ import {
53
+ AddCctpRouterEndpointArgs ,
54
+ AuctionSettled ,
55
+ AuctionUpdated ,
56
+ BurnAndPublishAccounts ,
57
+ CctpMessageArgs ,
58
+ Enacted ,
59
+ FastFillRedeemed ,
60
+ FastFillSequenceReserved ,
61
+ FastOrderPathComposite ,
62
+ LocalFastOrderFilled ,
63
+ MatchingEngineCommonAccounts ,
64
+ OrderExecuted ,
65
+ Proposed ,
66
+ PublishMessageAccounts ,
67
+ RedeemFastFillAccounts ,
68
+ ReserveFastFillSequenceCompositeOpts ,
69
+ } from "./types" ;
57
70
58
71
export const PROGRAM_IDS = [
59
72
"MatchingEngine11111111111111111111111111111" ,
60
73
"mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS" ,
61
74
] as const ;
75
+ export type ProgramId = ( typeof PROGRAM_IDS ) [ number ] | string ;
62
76
63
77
export const FEE_PRECISION_MAX = 1_000_000n ;
64
78
65
79
export const CPI_EVENT_IX_SELECTOR = Uint8Array . from ( [ 228 , 69 , 165 , 46 , 81 , 203 , 154 , 29 ] ) ;
66
80
67
- export type ProgramId = ( typeof PROGRAM_IDS ) [ number ] | string ;
68
-
69
- export type AddCctpRouterEndpointArgs = {
70
- chain : ChainId ;
71
- cctpDomain : number ;
72
- address : Array < number > ;
73
- mintRecipient : Array < number > | null ;
74
- } ;
75
-
76
- export type WormholeCoreBridgeAccounts = {
77
- coreBridgeConfig : PublicKey ;
78
- coreEmitterSequence : PublicKey ;
79
- coreFeeCollector : PublicKey ;
80
- coreBridgeProgram : PublicKey ;
81
- } ;
82
-
83
- export type PublishMessageAccounts = WormholeCoreBridgeAccounts & {
84
- custodian : PublicKey ;
85
- coreMessage : PublicKey ;
86
- } ;
87
-
88
- export type MatchingEngineCommonAccounts = WormholeCoreBridgeAccounts & {
89
- matchingEngineProgram : PublicKey ;
90
- systemProgram : PublicKey ;
91
- rent : PublicKey ;
92
- clock : PublicKey ;
93
- custodian : PublicKey ;
94
- cctpMintRecipient : PublicKey ;
95
- tokenMessenger : PublicKey ;
96
- tokenMinter : PublicKey ;
97
- tokenMessengerMinterSenderAuthority : PublicKey ;
98
- tokenMessengerMinterProgram : PublicKey ;
99
- messageTransmitterAuthority : PublicKey ;
100
- messageTransmitterConfig : PublicKey ;
101
- messageTransmitterProgram : PublicKey ;
102
- tokenProgram : PublicKey ;
103
- mint : PublicKey ;
104
- localToken : PublicKey ;
105
- tokenMessengerMinterCustodyToken : PublicKey ;
106
- } ;
107
-
108
- export type BurnAndPublishAccounts = {
109
- custodian : PublicKey ;
110
- routerEndpoint : PublicKey ;
111
- coreMessage : PublicKey ;
112
- cctpMessage : PublicKey ;
113
- coreBridgeConfig : PublicKey ;
114
- coreEmitterSequence : PublicKey ;
115
- coreFeeCollector : PublicKey ;
116
- coreBridgeProgram : PublicKey ;
117
- tokenMessengerMinterSenderAuthority : PublicKey ;
118
- messageTransmitterConfig : PublicKey ;
119
- tokenMessenger : PublicKey ;
120
- remoteTokenMessenger : PublicKey ;
121
- tokenMinter : PublicKey ;
122
- localToken : PublicKey ;
123
- tokenMessengerMinterEventAuthority : PublicKey ;
124
- messageTransmitterProgram : PublicKey ;
125
- tokenMessengerMinterProgram : PublicKey ;
126
- } ;
127
-
128
- export type RedeemFastFillAccounts = {
129
- custodian : PublicKey ;
130
- fromRouterEndpoint : PublicKey ;
131
- toRouterEndpoint : PublicKey ;
132
- localCustodyToken : PublicKey ;
133
- matchingEngineProgram : PublicKey ;
134
- } ;
135
-
136
- export type CctpMessageArgs = {
137
- encodedCctpMessage : Buffer ;
138
- cctpAttestation : Buffer ;
139
- } ;
140
-
141
- export type SettledTokenAccountInfo = {
142
- key : PublicKey ;
143
- balanceAfter : BN ;
144
- } ;
145
-
146
- export type AuctionSettled = {
147
- auction : PublicKey ;
148
- bestOfferToken : SettledTokenAccountInfo | null ;
149
- executorToken : SettledTokenAccountInfo | null ;
150
- withExecute : MessageProtocol | null ;
151
- } ;
152
-
153
- export type AuctionUpdated = {
154
- configId : number ;
155
- auction : PublicKey ;
156
- vaa : PublicKey | null ;
157
- sourceChain : number ;
158
- targetProtocol : MessageProtocol ;
159
- redeemerMessageLen : number ;
160
- endSlot : BN ;
161
- bestOfferToken : PublicKey ;
162
- tokenBalanceBefore : BN ;
163
- amountIn : BN ;
164
- totalDeposit : BN ;
165
- maxOfferPriceAllowed : BN | null ;
166
- } ;
167
-
168
- export type OrderExecuted = {
169
- auction : PublicKey ;
170
- vaa : PublicKey ;
171
- targetProtocol : MessageProtocol ;
172
- } ;
173
-
174
- export type Proposed = {
175
- action : ProposalAction ;
176
- } ;
177
-
178
- export type Enacted = {
179
- action : ProposalAction ;
180
- } ;
181
-
182
- export type LocalFastOrderFilled = {
183
- seeds : FastFillSeeds ;
184
- info : FastFillInfo ;
185
- auction : PublicKey | null ;
186
- } ;
187
-
188
- export type FastFillSequenceReserved = {
189
- fastVaaHash : Array < number > ;
190
- fastFillSeeds : FastFillSeeds ;
191
- } ;
192
-
193
- export type FastFillRedeemed = {
194
- preparedBy : PublicKey ;
195
- fastFill : PublicKey ;
196
- } ;
197
-
198
- export type FastOrderPathComposite = {
199
- fastVaa : {
200
- vaa : PublicKey ;
201
- } ;
202
- path : {
203
- fromEndpoint : {
204
- endpoint : PublicKey ;
205
- } ;
206
- toEndpoint : { endpoint : PublicKey } ;
207
- } ;
208
- } ;
209
-
210
- export type ReserveFastFillSequenceCompositeOpts = {
211
- fastVaaHash ?: VaaHash ;
212
- sourceChain ?: ChainId ;
213
- orderSender ?: Array < number > ;
214
- targetChain ?: ChainId ;
215
- } ;
216
-
217
81
export class MatchingEngineProgram {
218
82
private _programId : ProgramId ;
219
83
private _mint : PublicKey ;
@@ -229,7 +93,7 @@ export class MatchingEngineProgram {
229
93
private _addresses : MatchingEngine . Addresses ,
230
94
) {
231
95
this . _programId = programId ;
232
- this . _mint = new PublicKey ( _addresses . usdcMint ) ;
96
+ this . _mint = new PublicKey ( _addresses . cctp . usdcMint ) ;
233
97
this . pdas = programDerivedAddresses (
234
98
new PublicKey ( programId ) ,
235
99
this . _mint ,
@@ -2375,23 +2239,22 @@ export class MatchingEngineProgram {
2375
2239
upgradeManagerProgram ( ) : UpgradeManagerProgram {
2376
2240
return new UpgradeManagerProgram (
2377
2241
this . program . provider . connection ,
2378
- this . _addresses . upgradeManager ,
2379
- // TODO: matching engine does not require token router
2380
- { ...this . _addresses , tokenRouter : "" } ,
2242
+ this . _addresses . upgradeManager ! ,
2243
+ { ...this . _addresses , tokenRouter : this . _addresses . tokenRouter ! } ,
2381
2244
) ;
2382
2245
}
2383
2246
2384
2247
tokenMessengerMinterProgram ( ) : TokenMessengerMinterProgram {
2385
2248
return new TokenMessengerMinterProgram (
2386
2249
this . program . provider . connection ,
2387
- this . _addresses . tokenMessenger ,
2250
+ this . _addresses . cctp . tokenMessenger ,
2388
2251
) ;
2389
2252
}
2390
2253
2391
2254
messageTransmitterProgram ( ) : MessageTransmitterProgram {
2392
2255
return new MessageTransmitterProgram (
2393
2256
this . program . provider . connection ,
2394
- this . _addresses . messageTransmitter ,
2257
+ this . _addresses . cctp . messageTransmitter ,
2395
2258
) ;
2396
2259
}
2397
2260
0 commit comments