getEvents.ts 1.03 KB
Newer Older
Will Cory's avatar
Will Cory committed
1
import { ethers } from 'ethers'
2
import type { Address } from '@wagmi/core'
Will Cory's avatar
Will Cory committed
3 4 5 6

import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddress'
import { abi } from '../lib/abi'
import { AttestationCreatedEvent } from '../types/AttestationCreatedEvent'
7
import { encodeRawKey } from './createKey'
Will Cory's avatar
Will Cory committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

export const getEvents = async ({
  creator = null,
  about = null,
  key = null,
  value = null,
  provider,
  fromBlockOrBlockhash,
  toBlock,
}: {
  creator?: Address | null
  about?: Address | null
  key?: string | null
  value?: string | null
  provider: ethers.providers.JsonRpcProvider
  fromBlockOrBlockhash?: ethers.providers.BlockTag | undefined
  toBlock?: ethers.providers.BlockTag | undefined
}) => {
  const contract = new ethers.Contract(
    ATTESTATION_STATION_ADDRESS,
    abi,
    provider
  )
  return contract.queryFilter(
    contract.filters.AttestationCreated(
      creator,
      about,
      key && encodeRawKey(key),
      value
    ),
    fromBlockOrBlockhash,
    toBlock
  ) as Promise<AttestationCreatedEvent[]>
}