Skip to content

Commit

Permalink
Merge pull request #108 from zkLinkProtocol/fix-redistribute-withdraw…
Browse files Browse the repository at this point in the history
…-data

fix: filter out withdraw data
  • Loading branch information
zkcarter authored Sep 21, 2024
2 parents c04b09c + 6261705 commit 3a24ec8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/repositories/redistributeBalance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class RedistributeBalanceRepository extends BaseRepository<RedistributeBa
const userAddresses = combinedUserAddresses.map((row) => row.userAddress);

// Step 2: Get user data
const withdrawCutoffTimestamp = Math.floor(
(new Date().getTime() - 7 * 24 * 60 * 60 * 1000) / 1000,
);
const withdrawCutoffDate = new Date(withdrawCutoffTimestamp * 1000);
const users = await entityManager
.createQueryBuilder(User, "user")
.leftJoinAndSelect(
Expand All @@ -87,12 +91,19 @@ export class RedistributeBalanceRepository extends BaseRepository<RedistributeBa
"us.tokenAddress IN (:...tokenBuffers) AND us.poolAddress IN (:...poolBuffers)",
{ tokenBuffers, poolBuffers },
)
.leftJoinAndSelect("user.withdraws", "uw")
.leftJoinAndSelect(
"user.withdraws",
"uw",
"uw.timestamp > :withdrawCutoffDate",
{
withdrawCutoffDate,
},
)
.where("user.userAddress IN (:...userAddresses)", {
userAddresses: userAddresses.map((addr) => Buffer.from(addr, "hex")),
})
.orderBy("user.createdAt", "DESC")
.orderBy("user.userAddress", "ASC")
.addOrderBy("user.userAddress", "ASC")
.getMany();

// Step 3: Organize data into the desired structure
Expand Down

0 comments on commit 3a24ec8

Please sign in to comment.