Skip to content

Commit 2e481c2

Browse files
committed
Add prepare order ix to settle order
1 parent 4c0dfe2 commit 2e481c2

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

solana/ts/src/matchingEngine/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,7 @@ export class MatchingEngineProgram {
842842
const { ownerOrAssistant, custodian } = accounts;
843843
return this.program.methods
844844
.setPause(paused)
845-
.accounts({
846-
admin: this.adminMutComposite(ownerOrAssistant, custodian),
847-
})
845+
.accounts({ admin: this.adminMutComposite(ownerOrAssistant, custodian) })
848846
.instruction();
849847
}
850848

solana/ts/src/protocol/matchingEngine.ts

+26-18
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,13 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
108108
) {
109109
const ownerOrAssistant = new SolanaAddress(sender).unwrap();
110110
const mintRecipient = tokenAccount
111-
? new SolanaAddress(tokenAccount).toUniversalAddress().toUint8Array()
111+
? Array.from(new SolanaAddress(tokenAccount).toUniversalAddress().toUint8Array())
112112
: null;
113+
const address = Array.from(router.toUniversalAddress().toUint8Array());
114+
113115
const ix = await this.addCctpRouterEndpointIx(
114116
{ ownerOrAssistant },
115-
{
116-
chain: toChainId(chain),
117-
cctpDomain: cctpDomain,
118-
address: Array.from(router.toUniversalAddress().toUint8Array()),
119-
mintRecipient: mintRecipient ? Array.from(mintRecipient) : null,
120-
},
117+
{ chain: toChainId(chain), cctpDomain, address, mintRecipient },
121118
);
122119

123120
const transaction = await this.createTx(ownerOrAssistant, [ix]);
@@ -133,17 +130,12 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
133130
) {
134131
const owner = new SolanaAddress(sender).unwrap();
135132
const mintRecipient = tokenAccount
136-
? new SolanaAddress(tokenAccount).toUniversalAddress().toUint8Array()
133+
? Array.from(new SolanaAddress(tokenAccount).toUniversalAddress().toUint8Array())
137134
: null;
138-
135+
const address = Array.from(router.toUniversalAddress().toUint8Array());
139136
const ix = await this.updateCctpRouterEndpointIx(
140137
{ owner },
141-
{
142-
chain: toChainId(chain),
143-
cctpDomain: cctpDomain,
144-
address: Array.from(router.toUniversalAddress().toUint8Array()),
145-
mintRecipient: mintRecipient ? Array.from(mintRecipient) : null,
146-
},
138+
{ chain: toChainId(chain), cctpDomain, address, mintRecipient },
147139
);
148140

149141
const transaction = await this.createTx(owner, [ix]);
@@ -152,6 +144,7 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
152144

153145
async *disableRouter<RC extends Chain>(sender: AnySolanaAddress, chain: RC) {
154146
const owner = new SolanaAddress(sender).unwrap();
147+
155148
const ix = await this.disableRouterEndpointIx({ owner }, toChainId(chain));
156149

157150
const transaction = await this.createTx(owner, [ix]);
@@ -329,8 +322,20 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
329322
// If the finalized VAA and CCTP message/attestation are passed
330323
// we may try to prepare the order response
331324
// this yields its own transaction
332-
if (finalized && cctp)
333-
yield* this.prepareOrderResponse(sender, fast, finalized, cctp, lookupTables);
325+
const ixs = [];
326+
if (finalized && cctp) {
327+
// TODO: how do we decide?
328+
const combine = true;
329+
// try to include the prepare order instruction in the same transaction
330+
if (combine) {
331+
const ix = await this._prepareOrderResponseIx(sender, fast, finalized, cctp);
332+
if (ix !== undefined) {
333+
ixs.push(ix, ComputeBudgetProgram.setComputeUnitLimit({ units: 300_000 }));
334+
}
335+
} else {
336+
yield* this.prepareOrderResponse(sender, fast, finalized, cctp, lookupTables);
337+
}
338+
}
334339

335340
const digest = keccak256(fast.hash);
336341
const preparedOrderResponse = this.preparedOrderResponseAddress(digest);
@@ -364,11 +369,14 @@ export class SolanaMatchingEngine<N extends Network, C extends SolanaChains>
364369
return await this.settleAuctionCompleteIx({
365370
executor: payer,
366371
preparedOrderResponse,
372+
auction,
367373
});
368374
}
369375
})();
370376

371-
const transaction = await this.createTx(payer, [settleIx], undefined, lookupTables);
377+
ixs.push(settleIx);
378+
379+
const transaction = await this.createTx(payer, ixs, undefined, lookupTables);
372380

373381
yield this.createUnsignedTx({ transaction }, "MatchingEngine.settleAuctionComplete");
374382
}

0 commit comments

Comments
 (0)