indexer.ts 896 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
export * from './generated'

type PaginationOptions = {
  limit?: number
  cursor?: string
}

type Options = {
  baseUrl?: string
  address: `0x${string}`
} & PaginationOptions

const createQueryString = ({ cursor, limit }: PaginationOptions): string => {
  if (cursor === undefined && limit === undefined) {
    return ''
  }
  const queries: string[] = []
  if (cursor) {
    queries.push(`cursor=${cursor}`)
  }
  if (limit) {
    queries.push(`limit=${limit}`)
  }
  return `?${queries.join('&')}`
}

export const depositEndpoint = ({ baseUrl = '', address, cursor, limit }: Options): string => {
28
  return [baseUrl, 'deposits', `${address}${createQueryString({ cursor, limit })}`].join('/')
29 30 31
}

export const withdrawalEndoint = ({ baseUrl = '', address, cursor, limit }: Options): string => {
32
  return [baseUrl, 'withdrawals', `${address}${createQueryString({ cursor, limit })}`].join('/')
33 34
}