Skip to content

Commit

Permalink
fix: add timestamp and validity to state
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Nov 8, 2023
1 parent 93eb672 commit acd5a83
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/hooks/loadables/useLoadRecovery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SENTINEL_ADDRESS } from '@safe-global/safe-core-sdk/dist/src/utils/constants'
import { BigNumber } from 'ethers'
import type { Delay } from '@gnosis.pm/zodiac'

import { getDelayModifiers } from '@/services/recovery/delay-modifier'
Expand All @@ -16,21 +17,44 @@ const REFRESH_DELAY = 5 * 60 * 1_000 // 5 minutes
const getRecoveryState = async (delayModifier: Delay): Promise<RecoveryState[number]> => {
const transactionAddedFilter = delayModifier.filters.TransactionAdded()

const [[modules], txCooldown, txNonce, queueNonce, transactionsAdded] = await Promise.all([
const [[modules], txExpiration, txCooldown, txNonce, queueNonce, transactionsAdded] = await Promise.all([
delayModifier.getModulesPaginated(SENTINEL_ADDRESS, MAX_PAGE_SIZE),
delayModifier.txExpiration(),
delayModifier.txCooldown(),
delayModifier.txNonce(),
delayModifier.queueNonce(),
delayModifier.queryFilter(transactionAddedFilter),
])

const queue = await Promise.all(
transactionsAdded
// Only queued transactions with queueNonce >= current txNonce
.filter(({ args }) => args.queueNonce.gte(txNonce))
.map(async (event) => {
const txBlock = await event.getBlock()

const validFrom = BigNumber.from(txBlock.timestamp).add(txCooldown)
const expiresAt = txExpiration.isZero()
? null // Never expires
: validFrom.add(txExpiration).toString()

return {
...event,
timestamp: txBlock.timestamp,
validFrom: validFrom.toString(),
expiresAt,
}
}),
)

return {
address: delayModifier.address,
modules,
txExpiration: txExpiration.toString(),
txCooldown: txCooldown.toString(),
txNonce: txNonce.toString(),
queueNonce: queueNonce.toString(),
transactionsAdded: transactionsAdded.filter(({ args }) => args.queueNonce.gte(txNonce)),
queue,
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/store/recoverySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import type { TransactionAddedEvent } from '@gnosis.pm/zodiac/dist/cjs/types/Del

import { makeLoadableSlice } from './common'

type QueuedTransactionAdded = TransactionAddedEvent & {
timestamp: number
validFrom: string
expiresAt: string | null
}

export type RecoveryState = Array<{
address: string
modules: Array<string>
txExpiration: string
txCooldown: string
txNonce: string
queueNonce: string
transactionsAdded: Array<TransactionAddedEvent>
queue: Array<QueuedTransactionAdded>
}>

const initialState: RecoveryState = []
Expand Down

0 comments on commit acd5a83

Please sign in to comment.