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

Commit 0b9c764

Browse files
committed
replace sdk signer with subclass && provide unwrap to get keypair, update prep order response
1 parent 6c2d364 commit 0b9c764

File tree

5 files changed

+180
-135
lines changed

5 files changed

+180
-135
lines changed

solana/ts/src/matchingEngine/pdas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ReservedFastFillSequence,
1515
RouterEndpoint,
1616
} from "./state";
17+
import { VAA } from "@wormhole-foundation/sdk-definitions";
1718

1819
export function programDerivedAddresses(ID: PublicKey, mint: PublicKey) {
1920
return {

solana/ts/src/protocol/matchingEngine.ts

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AddressLookupTableAccount,
23
ComputeBudgetProgram,
34
Connection,
45
PublicKey,
@@ -10,11 +11,12 @@ import {
1011
FastTransfer,
1112
MatchingEngine,
1213
} from "@wormhole-foundation/example-liquidity-layer-definitions";
13-
import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core";
1414
import { Chain, Network, Platform, toChainId } from "@wormhole-foundation/sdk-base";
1515
import {
1616
AccountAddress,
1717
ChainsConfig,
18+
CircleAttestation,
19+
CircleBridge,
1820
Contracts,
1921
UnsignedTransaction,
2022
VAA,
@@ -28,12 +30,8 @@ import {
2830
SolanaTransaction,
2931
SolanaUnsignedTransaction,
3032
} from "@wormhole-foundation/sdk-solana";
31-
import {
32-
AuctionInfo,
33-
AuctionParameters,
34-
MatchingEngineProgram,
35-
ProgramId,
36-
} from "../matchingEngine";
33+
import { utils as coreUtils } from "@wormhole-foundation/sdk-solana-core";
34+
import { AuctionParameters, MatchingEngineProgram, ProgramId } from "../matchingEngine";
3735

3836
export interface SolanaMatchingEngineContracts {
3937
matchingEngine: string;
@@ -249,11 +247,97 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
249247
});
250248

251249
const transaction = await this.createTx(payer, [ix, computeIx]);
252-
yield this.createUnsignedTx({ transaction }, "MatchingEngine.improveOffer");
250+
yield this.createUnsignedTx({ transaction }, "MatchingEngine.executeFastOrder");
251+
}
252+
253+
async *prepareOrderResponse(
254+
sender: AnySolanaAddress,
255+
fast: VAA<"FastTransfer:FastMarketOrder">,
256+
finalized: VAA<"FastTransfer:CctpDeposit">,
257+
cctp: {
258+
message: CircleBridge.Message;
259+
attestation: CircleAttestation;
260+
},
261+
lookupTables?: AddressLookupTableAccount[],
262+
) {
263+
const payer = new SolanaAddress(sender).unwrap();
264+
265+
const fastVaa = coreUtils.derivePostedVaaKey(
266+
this.coreBridgeProgramId(),
267+
Buffer.from(fast.hash),
268+
);
269+
270+
const finalizedVaa = coreUtils.derivePostedVaaKey(
271+
this.coreBridgeProgramId(),
272+
Buffer.from(finalized.hash),
273+
);
274+
275+
const ix = await this.prepareOrderResponseCctpIx(
276+
{ payer, fastVaa, finalizedVaa },
277+
{
278+
encodedCctpMessage: Buffer.from(CircleBridge.serialize(cctp.message)),
279+
cctpAttestation: Buffer.from(cctp.attestation, "hex"),
280+
},
281+
);
282+
283+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
284+
units: 300_000,
285+
});
286+
287+
const transaction = await this.createTx(payer, [ix, computeIx], undefined, lookupTables);
288+
yield this.createUnsignedTx({ transaction }, "MatchingEngine.prepareOrderResponse");
253289
}
254290

255-
async *settleAuctionComplete() {
256-
throw "Not implemented";
291+
async *settleAuctionComplete(
292+
sender: AnySolanaAddress,
293+
fast: VAA<"FastTransfer:FastMarketOrder">,
294+
finalized: VAA<"FastTransfer:CctpDeposit">,
295+
cctp: {
296+
message: CircleBridge.Message;
297+
attestation: CircleAttestation;
298+
},
299+
lookupTables?: AddressLookupTableAccount[],
300+
) {
301+
const payer = new SolanaAddress(sender).unwrap();
302+
303+
const fastVaa = coreUtils.derivePostedVaaKey(
304+
this.coreBridgeProgramId(),
305+
Buffer.from(fast.hash),
306+
);
307+
308+
const finalizedVaa = coreUtils.derivePostedVaaKey(
309+
this.coreBridgeProgramId(),
310+
Buffer.from(finalized.hash),
311+
);
312+
313+
const prepareIx = await this.prepareOrderResponseCctpIx(
314+
{ payer, fastVaa, finalizedVaa },
315+
{
316+
encodedCctpMessage: Buffer.from(CircleBridge.serialize(cctp.message)),
317+
cctpAttestation: Buffer.from(cctp.attestation, "hex"),
318+
},
319+
);
320+
321+
const preparedAddress = this.preparedOrderResponseAddress(keccak256(fast.hash));
322+
323+
const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
324+
units: 300_000,
325+
});
326+
327+
const executor = new SolanaAddress(sender).unwrap();
328+
const settleIx = await this.settleAuctionCompleteIx({
329+
executor,
330+
preparedOrderResponse: preparedAddress,
331+
});
332+
333+
const transaction = await this.createTx(
334+
executor,
335+
[prepareIx, settleIx, computeIx],
336+
undefined,
337+
lookupTables,
338+
);
339+
340+
yield this.createUnsignedTx({ transaction }, "MatchingEngine.settleAuctionComplete");
257341
}
258342

259343
settleAuction(): AsyncGenerator<UnsignedTransaction<N, C>, any, unknown> {
@@ -277,6 +361,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
277361
payerKey: PublicKey,
278362
instructions: TransactionInstruction[],
279363
recentBlockhash?: string,
364+
lookupTables?: AddressLookupTableAccount[],
280365
): Promise<VersionedTransaction> {
281366
if (!recentBlockhash)
282367
({ blockhash: recentBlockhash } = await this._connection.getLatestBlockhash());
@@ -285,7 +370,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
285370
payerKey,
286371
recentBlockhash,
287372
instructions,
288-
}).compileToV0Message();
373+
}).compileToV0Message(lookupTables);
289374
return new VersionedTransaction(messageV0);
290375
}
291376

solana/ts/src/testing/mock.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@ import { VaaAccount } from "../wormhole";
1010
import { CORE_BRIDGE_PID, GUARDIAN_KEY, MOCK_GUARDIANS } from "./consts";
1111
import { getBlockTime, postVaa } from "./utils";
1212

13-
export type SDKSigner<N extends Network> = SolanaSendSigner<N, "Solana">;
13+
export class SDKSigner<N extends Network> extends SolanaSendSigner<N, "Solana"> {
14+
unwrap(): Keypair {
15+
// @ts-ignore
16+
return this._keypair;
17+
}
18+
}
1419

1520
export function getSdkSigner<N extends Network>(
1621
connection: Connection,
1722
key: Keypair,
1823
debug: boolean = false,
1924
): { signer: SDKSigner<N>; address: SolanaAddress } {
20-
const signer = new SolanaSendSigner(connection, "Solana", key, debug, {});
25+
const signer = new SDKSigner(connection, "Solana", key, debug, {});
2126
const address = new SolanaAddress(key.publicKey);
2227
return { signer, address };
2328
}
2429

30+
export function unwrapSigners(signers: SDKSigner<Network>[]): Keypair[] {
31+
return signers.map((signer) => signer.unwrap());
32+
}
33+
2534
export async function postLiquidityLayerVaav2(
2635
connection: Connection,
2736
payer: Keypair | SignAndSendSigner<Network, "Solana">,

0 commit comments

Comments
 (0)