Skip to content

Commit

Permalink
Fix unlock in case one batch is split
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlotfi authored and mrlotfi committed Oct 31, 2024
1 parent 2efcd80 commit ef1ee41
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/driver/unlocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ export class Unlocker {

await this.vaaPoster.postSignedVAA(signedVaa, 'batch_unlcock');

const foundStates = orders.map((ord) =>
getSwiftStateAddrSrc(new PublicKey(SolanaProgram), Buffer.from(ord.orderHash.replace('0x', ''), 'hex')).toString(),
);

const parsedPayload = this.parseBatchUnlockVaaPayload(parseVaa(signedVaa).payload);
for (let ord of parsedPayload.orders) {
i++;
Expand All @@ -398,6 +402,10 @@ export class Unlocker {
new PublicKey(SolanaProgram),
Buffer.from(ord.orderHash.replace('0x', ''), 'hex'),
);
if (!foundStates.includes(state.toString())) {
logger.warn(`Ignoring unlock for ${ord.orderHash} as state is not found in the orders`);
continue;
}
const stateAss = getAssociatedTokenAddressSync(fromMint, state, true);
const vaaAddr = findVaaAddress(signedVaa);
const ix = await this.solanaIx.getUnlockBatchIx(driver, driverAss, state, stateAss, i, fromMint, vaaAddr);
Expand Down

0 comments on commit ef1ee41

Please sign in to comment.