Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/snap-points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
processNewOpen,
processNewClosed,
processNewOpenClosed,
validateLogs,
} from "./utils";
import {
IActive,
Expand Down Expand Up @@ -100,22 +101,11 @@ export const createSnapshotForNetwork = async (network: Network) => {
MAX_SIGNATURES_PER_CALL
);

const finalLogs = txLogs.flat();
const eventsObject: Record<string, IPositions> = JSON.parse(
fs.readFileSync(eventsSnapFilename, "utf-8")
);

const eventLogs: string[] = [];

finalLogs.map((log, index) => {
if (
log.startsWith("Program data:") &&
finalLogs[index + 1].startsWith(
`Program ${market.program.programId.toBase58()}`
)
)
eventLogs.push(log.split("Program data: ")[1]);
});
const eventLogs = validateLogs(txLogs, market.program.programId);

const decodedEvents = eventLogs
.map((log) => market.eventDecoder.decode(log))
Expand Down
26 changes: 26 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,29 @@ export const processNewOpenClosed = (

return updatedNewOpenClosed;
};

export const validateLogs = (logs: string[][], programId: PublicKey) => {
const rawEvents: string[] = [];
for (const txLog of logs) {
txLog.map((log, index) => {
if (
log.slice(0, -4) === `Program ${programId.toBase58()} invoke` &&
(txLog[index + 1] === "Program log: Instruction: CreatePosition" ||
txLog[index + 1] === "Program log: Instruction: RemovePosition")
) {
for (let i = index; i < txLog.length; i++) {
if (txLog[i] === `Program ${programId.toBase58()} success`) {
const associatedSlice = txLog.slice(index, i + 1);
const event = associatedSlice.find((log) =>
log.startsWith("Program data:")
);
if (event) {
rawEvents.push(event);
}
}
}
}
});
}
return rawEvents;
};