@@ -68,6 +68,9 @@ import {
68
68
toUniversalAddress ,
69
69
waitUntilSlot ,
70
70
waitUntilTimestamp ,
71
+ getSdkSigner ,
72
+ SDKSigner ,
73
+ postLiquidityLayerVaav2 ,
71
74
} from "../src/testing" ;
72
75
import { VaaAccount } from "../src/wormhole" ;
73
76
@@ -78,32 +81,21 @@ chai.config.truncateThreshold = 0;
78
81
// Set to true to add debug logs for Signer
79
82
const SIGNER_DEBUG = false ;
80
83
81
- type SDKSigner = SolanaSendSigner < "Devnet" , "Solana" > ;
82
-
83
- function getSdkStuff (
84
- connection : Connection ,
85
- key : Keypair ,
86
- ) : { signer : SDKSigner ; address : SolanaAddress } {
87
- const signer = new SolanaSendSigner ( connection , "Solana" , key , SIGNER_DEBUG , { } ) ;
88
- const address = new SolanaAddress ( key . publicKey ) ;
89
- return { signer, address } ;
90
- }
91
-
92
84
describe ( "Matching Engine" , function ( ) {
93
85
const connection = new Connection ( LOCALHOST , "processed" ) ;
94
86
95
87
// owner is also the recipient in all tests
96
88
const payer = PAYER_KEYPAIR ;
97
- const { signer : payerSigner , address : payerAddress } = getSdkStuff ( connection , payer ) ;
89
+ const { signer : payerSigner , address : payerAddress } = getSdkSigner ( connection , payer ) ;
98
90
99
91
const owner = OWNER_KEYPAIR ;
100
- const { signer : ownerSigner , address : ownerAddress } = getSdkStuff ( connection , owner ) ;
92
+ const { signer : ownerSigner , address : ownerAddress } = getSdkSigner ( connection , owner ) ;
101
93
102
94
const relayer = Keypair . generate ( ) ;
103
- const { signer : relayerSigner , address : relayerAddress } = getSdkStuff ( connection , relayer ) ;
95
+ const { signer : relayerSigner , address : relayerAddress } = getSdkSigner ( connection , relayer ) ;
104
96
105
97
const ownerAssistant = OWNER_ASSISTANT_KEYPAIR ;
106
- const { signer : ownerAssistantSigner , address : ownerAssistantAddress } = getSdkStuff (
98
+ const { signer : ownerAssistantSigner , address : ownerAssistantAddress } = getSdkSigner (
107
99
connection ,
108
100
ownerAssistant ,
109
101
) ;
@@ -116,17 +108,17 @@ describe("Matching Engine", function () {
116
108
) ;
117
109
const newFeeRecipient = Keypair . generate ( ) . publicKey ;
118
110
const playerOne = PLAYER_ONE_KEYPAIR ;
119
- const { signer : playerOneSigner , address : playerOneAddress } = getSdkStuff (
111
+ const { signer : playerOneSigner , address : playerOneAddress } = getSdkSigner (
120
112
connection ,
121
113
playerOne ,
122
114
) ;
123
115
const playerTwo = Keypair . generate ( ) ;
124
- const { signer : playerTwoSigner , address : playerTwoAddress } = getSdkStuff (
116
+ const { signer : playerTwoSigner , address : playerTwoAddress } = getSdkSigner (
125
117
connection ,
126
118
playerTwo ,
127
119
) ;
128
120
const liquidator = Keypair . generate ( ) ;
129
- const { signer : liquidatorSigner , address : liquidatorAddress } = getSdkStuff (
121
+ const { signer : liquidatorSigner , address : liquidatorAddress } = getSdkSigner (
130
122
connection ,
131
123
liquidator ,
132
124
) ;
@@ -1447,18 +1439,15 @@ describe("Matching Engine", function () {
1447
1439
} ) ;
1448
1440
1449
1441
it ( "Cannot Place Initial Offer (Invalid VAA)" , async function ( ) {
1450
- const fastVaa = await postLiquidityLayerVaa (
1442
+ const { address : fastVaa , account : account } = await postLiquidityLayerVaav2 (
1451
1443
connection ,
1452
- playerOne ,
1453
- MOCK_GUARDIANS ,
1444
+ playerOneSigner ,
1454
1445
ethRouter ,
1455
1446
wormholeSequence ++ ,
1456
1447
Buffer . from ( "deadbeef" , "hex" ) ,
1457
1448
) ;
1458
1449
1459
- const auction = await VaaAccount . fetch ( connection , fastVaa ) . then ( ( vaa ) =>
1460
- engine . auctionAddress ( vaa . digest ( ) ) ,
1461
- ) ;
1450
+ const auction = engine . auctionAddress ( account . digest ( ) ) ;
1462
1451
await placeInitialOfferCctpForTest (
1463
1452
{
1464
1453
payer : playerOne . publicKey ,
@@ -1559,10 +1548,9 @@ describe("Matching Engine", function () {
1559
1548
} ) ;
1560
1549
1561
1550
it ( "Cannot Place Initial Offer (Invalid Payload)" , async function ( ) {
1562
- const fastVaa = await postLiquidityLayerVaa (
1551
+ const { address : fastVaa , account } = await postLiquidityLayerVaav2 (
1563
1552
connection ,
1564
- playerOne ,
1565
- MOCK_GUARDIANS ,
1553
+ playerOneSigner ,
1566
1554
ethRouter ,
1567
1555
wormholeSequence ++ ,
1568
1556
new LiquidityLayerMessage ( {
@@ -1585,9 +1573,7 @@ describe("Matching Engine", function () {
1585
1573
} ) ,
1586
1574
) ;
1587
1575
1588
- const auction = await VaaAccount . fetch ( connection , fastVaa ) . then ( ( vaa ) =>
1589
- engine . auctionAddress ( vaa . digest ( ) ) ,
1590
- ) ;
1576
+ const auction = engine . auctionAddress ( account . digest ( ) ) ;
1591
1577
await placeInitialOfferCctpForTest (
1592
1578
{
1593
1579
payer : playerOne . publicKey ,
@@ -2438,7 +2424,7 @@ describe("Matching Engine", function () {
2438
2424
2439
2425
it ( "Execute Fast Order After Grace Period with Liquidator (Initial Offer Token is Closed)" , async function ( ) {
2440
2426
const tmpOwner = Keypair . generate ( ) ;
2441
- const { signer : tmpOwnerSiner } = getSdkStuff ( connection , tmpOwner ) ;
2427
+ const { signer : tmpOwnerSiner } = getSdkSigner ( connection , tmpOwner ) ;
2442
2428
const transferLamportsToTmpOwnerIx = SystemProgram . transfer ( {
2443
2429
fromPubkey : payer . publicKey ,
2444
2430
toPubkey : tmpOwner . publicKey ,
@@ -4369,13 +4355,13 @@ describe("Matching Engine", function () {
4369
4355
} ) ;
4370
4356
4371
4357
interface TestOptions {
4372
- signers ?: SDKSigner [ ] ;
4358
+ signers ?: SDKSigner < "Devnet" > [ ] ;
4373
4359
errorMsg ?: string | null ;
4374
4360
}
4375
4361
4376
4362
function addDefaultOptions < T extends TestOptions > (
4377
4363
opts : T ,
4378
- ) : [ { signers : SDKSigner [ ] ; errorMsg : string | null } , Omit < T , keyof TestOptions > ] {
4364
+ ) : [ { signers : SDKSigner < "Devnet" > [ ] ; errorMsg : string | null } , Omit < T , keyof TestOptions > ] {
4379
4365
let { signers, errorMsg } = opts ;
4380
4366
signers ??= [ payerSigner ] ;
4381
4367
delete opts . signers ;
@@ -4445,6 +4431,7 @@ describe("Matching Engine", function () {
4445
4431
// Place the initial offer.
4446
4432
const txs = engine . placeInitialOffer (
4447
4433
new SolanaAddress ( accounts . payer ) ,
4434
+ // @ts -expect-error may be Uint8Array typed for payload
4448
4435
fastMarketOrderVAA ,
4449
4436
args . offerPrice ,
4450
4437
args . totalDeposit ,
@@ -4454,6 +4441,10 @@ describe("Matching Engine", function () {
4454
4441
return expectTxsErr ( signers [ 0 ] , txs , errorMsg ) ;
4455
4442
}
4456
4443
4444
+ // If we still have a Uint8Array, we failed to deserialize it earlier but it was accepted
4445
+ // and not caught by the above error check. Why?
4446
+ if ( fastMarketOrderVAA . payloadLiteral === "Uint8Array" ) throw "Invalid VAA" ;
4447
+
4457
4448
const offerToken =
4458
4449
accounts . offerToken ??
4459
4450
splToken . getAssociatedTokenAddressSync ( USDC_MINT_ADDRESS , accounts . payer ) ;
@@ -4486,7 +4477,7 @@ describe("Matching Engine", function () {
4486
4477
4487
4478
const auctionCustodyBalanceAfter = await engine . fetchAuctionCustodyTokenBalance ( auction ) ;
4488
4479
4489
- const { fastMarketOrder } = LiquidityLayerMessage . decode ( fast . vaaAccount . payload ( ) ) ;
4480
+ const fastMarketOrder = fastMarketOrderVAA . payload ;
4490
4481
expect ( fastMarketOrder ) . is . not . undefined ;
4491
4482
const { amountIn, maxFee, targetChain, redeemerMessage } = fastMarketOrder ! ;
4492
4483
@@ -5172,20 +5163,6 @@ describe("Matching Engine", function () {
5172
5163
} ;
5173
5164
}
5174
5165
5175
- type VaaResult = {
5176
- vaa : PublicKey ;
5177
- vaaAccount : VaaAccount ;
5178
- } ;
5179
-
5180
- type FastObservedResult = VaaResult & {
5181
- fastMarketOrder : FastMarketOrder ;
5182
- } ;
5183
-
5184
- type FinalizedObservedResult = VaaResult & {
5185
- slowOrderResponse : SlowOrderResponse ;
5186
- cctp : CctpMessageArgs ;
5187
- } ;
5188
-
5189
5166
type ObserveCctpOrderVaasOpts = {
5190
5167
sourceChain ?: Chain ;
5191
5168
emitter ?: Array < number > ;
@@ -5199,10 +5176,7 @@ describe("Matching Engine", function () {
5199
5176
finalizedVaaTimestamp ?: number ;
5200
5177
} ;
5201
5178
5202
- async function observeCctpOrderVaas ( opts : ObserveCctpOrderVaasOpts = { } ) : Promise < {
5203
- fast : FastObservedResult ;
5204
- finalized ?: FinalizedObservedResult ;
5205
- } > {
5179
+ async function observeCctpOrderVaas ( opts : ObserveCctpOrderVaasOpts = { } ) {
5206
5180
let {
5207
5181
sourceChain,
5208
5182
emitter,
@@ -5231,18 +5205,14 @@ describe("Matching Engine", function () {
5231
5205
throw new Error ( `Invalid source chain: ${ sourceChain } ` ) ;
5232
5206
}
5233
5207
5234
- const fastVaa = await postLiquidityLayerVaa (
5208
+ const { address : fastVaa , account : fastVaaAccount } = await postLiquidityLayerVaav2 (
5235
5209
connection ,
5236
- payer ,
5237
- MOCK_GUARDIANS ,
5210
+ payerSigner ,
5238
5211
emitter ,
5239
5212
wormholeSequence ++ ,
5240
- new LiquidityLayerMessage ( {
5241
- fastMarketOrder,
5242
- } ) ,
5213
+ new LiquidityLayerMessage ( { fastMarketOrder } ) ,
5243
5214
{ sourceChain, timestamp : vaaTimestamp } ,
5244
5215
) ;
5245
- const fastVaaAccount = await VaaAccount . fetch ( connection , fastVaa ) ;
5246
5216
const fast = { fastMarketOrder, vaa : fastVaa , vaaAccount : fastVaaAccount } ;
5247
5217
5248
5218
if ( finalized ) {
@@ -5266,16 +5236,15 @@ describe("Matching Engine", function () {
5266
5236
} ) ,
5267
5237
} ) ;
5268
5238
5269
- const finalizedVaa = await postLiquidityLayerVaa (
5270
- connection ,
5271
- payer ,
5272
- MOCK_GUARDIANS ,
5273
- finalizedEmitter ,
5274
- finalizedSequence ,
5275
- finalizedMessage ,
5276
- { sourceChain : finalizedSourceChain , timestamp : finalizedVaaTimestamp } ,
5277
- ) ;
5278
- const finalizedVaaAccount = await VaaAccount . fetch ( connection , finalizedVaa ) ;
5239
+ const { address : finalizedVaa , account : finalizedVaaAccount } =
5240
+ await postLiquidityLayerVaav2 (
5241
+ connection ,
5242
+ payerSigner ,
5243
+ finalizedEmitter ,
5244
+ finalizedSequence ,
5245
+ finalizedMessage ,
5246
+ { sourceChain : finalizedSourceChain , timestamp : finalizedVaaTimestamp } ,
5247
+ ) ;
5279
5248
return {
5280
5249
fast,
5281
5250
finalized : {
0 commit comments