Skip to content

Commit

Permalink
Include types for withdrawal seederwhere query
Browse files Browse the repository at this point in the history
  • Loading branch information
uditdc committed May 18, 2024
1 parent 28b4ee7 commit f21fb2d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
20 changes: 11 additions & 9 deletions packages/api/src/routes/withdrawals/withdrawalController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Request, Response } from 'express'
import { Prisma } from '@prisma/client'
import prisma from '../../utils/prismaClient'
import { handleAndReturnErrorResponse } from '../../schema/errors'
import { WithdrawalListQuerySchema } from '../../schema/zod/schemas/withdrawal'
Expand All @@ -24,26 +25,26 @@ export async function getAllWithdrawals(req: Request, res: Response) {
result.data

try {
const filterQuery = {}
const filterQuery: Prisma.WithdrawalWhereInput = {}

if (stakerAddress) {
filterQuery['stakerAddress'] = stakerAddress.toLowerCase()
filterQuery.stakerAddress = stakerAddress.toLowerCase()
}

if (delegatedTo) {
filterQuery['delegatedTo'] = delegatedTo.toLowerCase()
filterQuery.delegatedTo = delegatedTo.toLowerCase()
}

if (strategyAddress) {
filterQuery['strategies'] = { has: strategyAddress.toLowerCase() }
filterQuery.strategies = { has: strategyAddress.toLowerCase() }
}

if (status) {
switch (status) {
case 'queued':
filterQuery['isCompleted'] = false
filterQuery.isCompleted = false
break
case 'queued_withdrawable':
case 'queued_withdrawable': {
const viemClient = getViemClient()
const minDelayBlocks = await prisma.settings.findUnique({
where: { key: 'withdrawMinDelayBlocks' }
Expand All @@ -52,11 +53,12 @@ export async function getAllWithdrawals(req: Request, res: Response) {
(await viemClient.getBlockNumber()) -
BigInt((minDelayBlocks?.value as string) || 0)

filterQuery['isCompleted'] = false
filterQuery['startBlock'] = { lte: minDelayBlock }
filterQuery.isCompleted = false
filterQuery.startBlock = { lte: minDelayBlock }
break
}
case 'completed':
filterQuery['isCompleted'] = true
filterQuery.isCompleted = true
break
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/seeder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ async function seedEigenDataLoop() {
await seedOperatorShares(targetBlock)
await seedQueuedWithdrawals(targetBlock)
await seedCompletedWithdrawals(targetBlock)

} catch (error) {
console.log('Failed to seed AVS and Opeartors at:', Date.now())
}
Expand Down
25 changes: 14 additions & 11 deletions packages/seeder/src/seedWithdrawalsCompleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const blockSyncKey = 'lastSyncedBlock_completedWithdrawals'
* @param fromBlock
* @param toBlock
*/
export async function seedCompletedWithdrawals(toBlock?: bigint, fromBlock?: bigint) {
export async function seedCompletedWithdrawals(
toBlock?: bigint,
fromBlock?: bigint
) {
console.log('Seeding Completed Withdrawals ...')

const viemClient = getViemClient()
Expand Down Expand Up @@ -56,16 +59,16 @@ export async function seedCompletedWithdrawals(toBlock?: bigint, fromBlock?: big
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const dbTransactions: any[] = []

if (completedWithdrawalList.length > 0) {
dbTransactions.push(
prismaClient.withdrawal.updateMany({
where: { withdrawalRoot: { in: completedWithdrawalList } },
data: {
isCompleted: true
}
})
)
}
if (completedWithdrawalList.length > 0) {
dbTransactions.push(
prismaClient.withdrawal.updateMany({
where: { withdrawalRoot: { in: completedWithdrawalList } },
data: {
isCompleted: true
}
})
)
}

await bulkUpdateDbTransactions(dbTransactions)

Expand Down
21 changes: 12 additions & 9 deletions packages/seeder/src/seedWithdrawalsQueued.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ interface Withdrawal {
* @param fromBlock
* @param toBlock
*/
export async function seedQueuedWithdrawals(toBlock?: bigint, fromBlock?: bigint) {
export async function seedQueuedWithdrawals(
toBlock?: bigint,
fromBlock?: bigint
) {
console.log('Seeding Queued Withdrawals ...')

const viemClient = getViemClient()
Expand All @@ -48,12 +51,10 @@ export async function seedQueuedWithdrawals(toBlock?: bigint, fromBlock?: bigint
await loopThroughBlocks(firstBlock, lastBlock, async (fromBlock, toBlock) => {
const logs = await viemClient.getLogs({
address: getEigenContracts().DelegationManager,
event: parseAbiItem(
[
'event WithdrawalQueued(bytes32 withdrawalRoot, Withdrawal withdrawal)',
'struct Withdrawal { address staker; address delegatedTo; address withdrawer; uint256 nonce; uint32 startBlock; address[] strategies; uint256[] shares; }'
]
),
event: parseAbiItem([
'event WithdrawalQueued(bytes32 withdrawalRoot, Withdrawal withdrawal)',
'struct Withdrawal { address staker; address delegatedTo; address withdrawer; uint256 nonce; uint32 startBlock; address[] strategies; uint256[] shares; }'
]),
fromBlock,
toBlock
})
Expand All @@ -76,8 +77,10 @@ export async function seedQueuedWithdrawals(toBlock?: bigint, fromBlock?: bigint
stakerAddress,
delegatedTo,
withdrawerAddress,
strategies: withdrawal.strategies.map(s => s.toLowerCase()) as string[],
shares: withdrawal.shares.map(s => BigInt(s).toString()),
strategies: withdrawal.strategies.map((s) =>
s.toLowerCase()
) as string[],
shares: withdrawal.shares.map((s) => BigInt(s).toString()),
startBlock: withdrawal.startBlock,

createdAtBlock: Number(log.blockNumber),
Expand Down

0 comments on commit f21fb2d

Please sign in to comment.