import { gql } from 'graphql-request' import { type Address } from 'viem' import type { ClientWithPns } from '../../contracts/consts.js' import { createSubgraphClient } from './client.js' export type GetReferralBlacklistsParameters = {} export type GetReferralBlacklistsReturnType = { id: Address }[] const query = gql` query getReferralBlacklists { blacklists( where: { banned: true } ) { id } } ` type SubgraphResult = { blacklists?: { id: Address }[] } /** * Gets referral blacklists from the subgraph. * @param client - {@link ClientWithPns} * @param parameters - {@link GetReferralBlacklistsParameters} * @returns List of referral blacklists or empty array. {@link GetReferralBlacklistsReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts } from '@pnsdomains/pnsjs' * import { getReferralBlacklists } from '@pnsdomains/pnsjs/subgraph' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }) * const result = await getReferralBlacklists(client, {}) * // [{ id: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9'}] */ const getReferralBlacklists = async ( client: ClientWithPns, {}: GetReferralBlacklistsParameters, ): Promise => { const subgraphClient = createSubgraphClient({ client }) const result = await subgraphClient.request(query, {}) return result?.blacklists || [] } export default getReferralBlacklists