Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter tokenAddress on withdrawing balance #109

Merged
merged 1 commit into from
Sep 22, 2024
Merged
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
50 changes: 30 additions & 20 deletions src/repositories/redistributeBalance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ export class RedistributeBalanceRepository extends BaseRepository<RedistributeBa
.leftJoinAndSelect(
"user.withdraws",
"uw",
"uw.timestamp > :withdrawCutoffDate",
"uw.timestamp > :withdrawCutoffDate AND uw.tokenAddress IN (:...tokenBuffers)",
{
withdrawCutoffDate,
tokenBuffers,
},
)
.where("user.userAddress IN (:...userAddresses)", {
Expand All @@ -107,25 +108,34 @@ export class RedistributeBalanceRepository extends BaseRepository<RedistributeBa
.getMany();

// Step 3: Organize data into the desired structure
const result = users.map((user) => ({
userAddress: user.userAddress,
userHolding: user.holdings.map((holding) => ({
...holding,
userAddress: holding.userAddress,
tokenAddress: holding.tokenAddress,
})),
userStaked: user.stakes.map((stake) => ({
...stake,
userAddress: stake.userAddress,
tokenAddress: stake.tokenAddress,
poolAddress: stake.poolAddress,
})),
userWithdraw: user.withdraws.map((withdraw) => ({
...withdraw,
userAddress: withdraw.userAddress,
tokenAddress: withdraw.tokenAddress,
})),
}));
const result = users
.map((user) => ({
userAddress: user.userAddress,
userHolding: user.holdings.map((holding) => ({
...holding,
userAddress: holding.userAddress,
tokenAddress: holding.tokenAddress,
})),
userStaked: user.stakes.map((stake) => ({
...stake,
userAddress: stake.userAddress,
tokenAddress: stake.tokenAddress,
poolAddress: stake.poolAddress,
})),
userWithdraw: user.withdraws.map((withdraw) => ({
...withdraw,
userAddress: withdraw.userAddress,
tokenAddress: withdraw.tokenAddress,
})),
}))
.filter(
(item) =>
![
"0xdd6105865380984716C6B2a1591F9643e6ED1C48".toLowerCase(), // aqua vault
"0x4AC97E2727B0e92AE32F5796b97b7f98dc47F059".toLowerCase(), // lbank vault
"0xc48F99afe872c2541f530C6c87E3A6427e0C40d5".toLowerCase(), // agx vault
].includes(item.userAddress),
);

return result;
}
Expand Down