Skip to content

Commit

Permalink
⚡️ server: batch activity log querying
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Oct 18, 2024
1 parent fc6969b commit 976411a
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions server/api/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,38 @@ export default app.get(
.filter(<T>(value: T | undefined): value is T => value !== undefined);
}

const repays = ignore("repay")
? []
: await publicClient.getLogs({
event: marketAbi.find((item) => item.type === "event" && item.name === "RepayAtMaturity"),
address: [...marketsByAddress.keys()],
args: { caller: exaPluginAddress, borrower: account },
toBlock: "latest",
fromBlock: 0n,
});

const withdraws = ignore("withdraw")
? []
: await publicClient
.getLogs({
event: marketAbi.find((item) => item.type === "event" && item.name === "Withdraw"),
const [repays, withdraws] = await Promise.all([
ignore("repay")
? []
: await publicClient.getLogs({
event: marketAbi.find((item) => item.type === "event" && item.name === "RepayAtMaturity"),
address: [...marketsByAddress.keys()],
args: { caller: account, owner: account },
args: { caller: exaPluginAddress, borrower: account },
toBlock: "latest",
fromBlock: 0n,
})
.then((logs) =>
logs.filter(
({ topics, data }) =>
decodeEventLog({ abi: marketAbi, eventName: "Withdraw", topics, data }).args.receiver.toLowerCase() !==
collector,
}),
ignore("withdraw")
? []
: await publicClient
.getLogs({
event: marketAbi.find((item) => item.type === "event" && item.name === "Withdraw"),
address: [...marketsByAddress.keys()],
args: { caller: account, owner: account },
toBlock: "latest",
fromBlock: 0n,
})
.then((logs) =>
logs.filter(
({ topics, data }) =>
decodeEventLog({
abi: marketAbi,
eventName: "Withdraw",
topics,
data,
}).args.receiver.toLowerCase() !== collector,
),
),
);
]);

const blocks = await Promise.all(
[...new Set([...repays, ...withdraws].map(({ blockNumber }) => blockNumber))].map((blockNumber) =>
Expand Down

0 comments on commit 976411a

Please sign in to comment.