Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Commit e6f3d3b

Browse files
committed
cleanup
1 parent 3026ec7 commit e6f3d3b

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

solana/ts/src/protocol/matchingEngine.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
CircleBridge,
2020
Contracts,
2121
VAA,
22-
keccak256,
2322
} from "@wormhole-foundation/sdk-definitions";
2423
import {
2524
AnySolanaAddress,
@@ -177,8 +176,10 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
177176
offerPrice: bigint,
178177
totalDeposit?: bigint,
179178
) {
180-
const payer = new SolanaAddress(sender).unwrap();
179+
// If the VAA has not yet been posted, do so now
180+
yield* this.postVaa(sender, vaa);
181181

182+
const payer = new SolanaAddress(sender).unwrap();
182183
const vaaAddress = this.pdas.postedVaa(vaa);
183184

184185
const ixs = await this.placeInitialOfferCctpIx(
@@ -196,7 +197,9 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
196197
offer: bigint,
197198
) {
198199
const participant = new SolanaAddress(sender).unwrap();
199-
const auction = this.auctionAddress(keccak256(vaa.hash));
200+
201+
const digest = vaaHash(vaa);
202+
const auction = this.pdas.auction(digest);
200203

201204
const ixs = await this.improveOfferIx({ participant, auction }, { offerPrice: offer });
202205

@@ -223,7 +226,6 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
223226

224227
const digest = vaaHash(vaa);
225228
const auction = this.pdas.auction(digest);
226-
227229
const reservedSequence = this.pdas.reservedFastFillSequence(digest);
228230

229231
// TODO: make sure this has already been done, or do it here
@@ -272,7 +274,8 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
272274
const fastVaa = this.pdas.postedVaa(fast);
273275
const finalizedVaa = this.pdas.postedVaa(finalized);
274276

275-
const preparedAddress = this.preparedOrderResponseAddress(keccak256(fast.hash));
277+
const digest = vaaHash(fast);
278+
const preparedAddress = this.pdas.preparedOrderResponse(digest);
276279

277280
try {
278281
// Check if its already been prepared
@@ -341,15 +344,16 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
341344
}
342345
}
343346

344-
const digest = keccak256(fast.hash);
345-
const preparedOrderResponse = this.preparedOrderResponseAddress(digest);
346-
const auction = this.auctionAddress(digest);
347347
const fastVaa = this.pdas.postedVaa(fast);
348348

349+
const digest = vaaHash(fast);
350+
const preparedOrderResponse = this.pdas.preparedOrderResponse(digest);
351+
const auction = this.pdas.auction(digest);
352+
349353
const settleIx = await (async () => {
350354
if (finalized && !cctp) {
351355
if (fast.payload.targetChain === "Solana") {
352-
const reservedSequence = this.reservedFastFillSequenceAddress(digest);
356+
const reservedSequence = this.pdas.reservedFastFillSequence(digest);
353357
return await this.settleAuctionNoneLocalIx({
354358
payer,
355359
reservedSequence,

solana/ts/tests/01__matchingEngine.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
} from "@wormhole-foundation/example-liquidity-layer-definitions";
1919
import { Chain, ChainId, encoding, toChain, toChainId } from "@wormhole-foundation/sdk-base";
2020
import { CircleBridge, VAA, create, toUniversal } from "@wormhole-foundation/sdk-definitions";
21-
import { SolanaAddress } from "@wormhole-foundation/sdk-solana";
2221
import { deserializePostMessage } from "@wormhole-foundation/sdk-solana-core";
2322
import { expect } from "chai";
2423
import { CctpTokenBurnMessage } from "../src/cctp";
@@ -2450,12 +2449,7 @@ describe("Matching Engine", function () {
24502449
fastMarketOrder: baseFastOrder,
24512450
},
24522451
);
2453-
const {
2454-
fastVaa,
2455-
fastVaaAccount,
2456-
auction,
2457-
auctionDataBefore: initialData,
2458-
} = result!;
2452+
const { fastVaaAccount, auction, auctionDataBefore: initialData } = result!;
24592453

24602454
const tmpOwner = Keypair.generate();
24612455
const transferLamportsToTmpOwnerIx = SystemProgram.transfer({
@@ -2581,12 +2575,7 @@ describe("Matching Engine", function () {
25812575
fastMarketOrder: baseFastOrder,
25822576
},
25832577
);
2584-
const {
2585-
fastVaa,
2586-
auction,
2587-
fastVaaAccount,
2588-
auctionDataBefore: initialData,
2589-
} = result!;
2578+
const { auction, fastVaaAccount, auctionDataBefore: initialData } = result!;
25902579

25912580
const tmpOwner = Keypair.generate();
25922581
const transferLamportsToTmpOwnerIx = SystemProgram.transfer({
@@ -2721,12 +2710,7 @@ describe("Matching Engine", function () {
27212710
fastMarketOrder: baseFastOrder,
27222711
},
27232712
);
2724-
const {
2725-
fastVaa,
2726-
fastVaaAccount,
2727-
auction,
2728-
auctionDataBefore: initialData,
2729-
} = result!;
2713+
const { fastVaaAccount, auction, auctionDataBefore: initialData } = result!;
27302714

27312715
const improveBy = Number(
27322716
await engine.computeMinOfferDelta(

0 commit comments

Comments
 (0)