import type { Account, Client, Transport } from 'viem' import type { ChainWithPns } from '../../contracts/consts.js' import getDecodedName, { type GetDecodedNameParameters, type GetDecodedNameReturnType, } from '../../functions/subgraph/getDecodedName.js' import getNameHistory, { type GetNameHistoryParameters, type GetNameHistoryReturnType, } from '../../functions/subgraph/getNameHistory.js' import getNamesForAddress, { type GetNamesForAddressParameters, type GetNamesForAddressReturnType, } from '../../functions/subgraph/getNamesForAddress.js' import getSubgraphRecords, { type GetSubgraphRecordsParameters, type GetSubgraphRecordsReturnType, } from '../../functions/subgraph/getSubgraphRecords.js' import getSubgraphRegistrant, { type GetSubgraphRegistrantParameters, type GetSubgraphRegistrantReturnType, } from '../../functions/subgraph/getSubgraphRegistrant.js' import getSubnames, { type GetSubnamesParameters, type GetSubnamesReturnType, } from '../../functions/subgraph/getSubnames.js' import getReferralBlacklists, { type GetReferralBlacklistsParameters, type GetReferralBlacklistsReturnType, } from '../../functions/subgraph/getReferralBlacklists.js' import getReferralStats, { type GetReferralStatsParameters, type GetReferralStatsReturnType, } from '../../functions/subgraph/getReferralStats.js' import getGracePeriodNames, { type GetGracePeriodNamesParameters, type GetGracePeriodNamesReturnType, } from '../../functions/subgraph/getGracePeriodNames.js' export type PnsSubgraphActions = { /** * Gets the full name for a name with unknown labels from the subgraph. * @param parameters - {@link GetDecodedNameParameters} * @returns Full name, or null if name was could not be filled. {@link GetDecodedNameReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getDecodedName({ name: '[5cee339e13375638553bdf5a6e36ba80fb9f6a4f0783680884d92b558aa471da].pls' }) * // pns.pls */ getDecodedName: ({ name, allowIncomplete, }: GetDecodedNameParameters) => Promise /** * Gets the history of a name from the subgraph. * @param parameters - {@link GetNameHistoryParameters} * @returns History object, or null if name could not be found. {@link GetNameHistoryReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getNameHistory({ name: 'pns.pls' }) */ getNameHistory: ({ name, }: GetNameHistoryParameters) => Promise /** * Gets the names for an address from the subgraph. * @param parameters - {@link GetNamesForAddressParameters} * @returns Name array. {@link GetNamesForAddressReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getNamesForAddress({ address: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }) */ getNamesForAddress: ({ address, filter, orderBy, orderDirection, pageSize, previousPage, }: GetNamesForAddressParameters) => Promise /** * Gets the records for a name from the subgraph * @param parameters - {@link GetSubgraphRecordsParameters} * @returns Record object, or null if name was not found. {@link GetSubgraphRecordsReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getSubgraphRecords({ name: 'pns.pls' }) * // { * // isMigrated: true, * // createdAt: { date: 2019-08-26T05:09:01.000Z, value: 1566796141000 }, * // texts: [ 'snapshot', 'url', 'avatar', 'com.twitter', 'com.github' ], * // coins: [ '1028' ] * // } */ getSubgraphRecords: ({ name, resolverAddress, }: GetSubgraphRecordsParameters) => Promise /** * Gets the name registrant from the subgraph. * @param parameters - {@link GetSubgraphRegistrantParameters} * @returns Registrant address, or null if name was not found. {@link GetSubgraphRegistrantReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getSubgraphRegistrant({ name: 'pns.pls' }) * // 0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9 */ getSubgraphRegistrant: ({ name, }: GetSubgraphRegistrantParameters) => Promise /** * Gets the subnames for a name from the subgraph. * @param parameters - {@link GetSubnamesParameters} * @returns Subname array. {@link GetSubnamesReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getSubnames({ name: 'pns.pls' }) */ getSubnames: ({ name, searchString, allowExpired, allowDeleted, orderBy, orderDirection, pageSize, previousPage, }: GetSubnamesParameters) => Promise /** * 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' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getReferralBlacklists({}) * // [{ id: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9'}] */ getReferralBlacklists: ({}: GetReferralBlacklistsParameters) => Promise /** * Gets referral statistics of an address from the subgraph. * @param client - {@link ClientWithPns} * @param parameters - {@link GetReferralStatsParameters} * @returns Referral statistics detail. {@link GetReferralStatsReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) * const result = await client.getReferralStats({ address: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9' }) * // { id: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9', commission: '0', count: 0} */ getReferralStats: ({ address, }: GetReferralStatsParameters) => Promise /** * Gets all grace period names from the subgraph. * @param client - {@link ClientWithPns} * @param parameters - {@link GetGracePeriodNamesParameters} * @returns List of referral blacklists or empty array. {@link GetGracePeriodNamesReturnType} * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts } from '@pnsdomains/pnsjs' * * const client = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }) * const result = await client.getGracePeriodNames({}) * // { * // isMigrated: true, * // createdAt: { date: 2019-08-26T05:09:01.000Z, value: 1566796141000 }, * // texts: [ 'snapshot', 'url', 'avatar', 'com.twitter', 'com.github' ], * // coins: [ '1028' ] * // } */ getGracePeriodNames: ({}: GetGracePeriodNamesParameters) => Promise } /** * Extends the viem client with PNS subgraph actions * @param client - The viem {@link Client} object to add the PNS subgraph actions to * * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' * import { addPnsContracts, pnsSubgraphActions } from '@pnsdomains/pnsjs' * * const clientWithPns = createPublicClient({ * chain: addPnsContracts(mainnet), * transport: http(), * }).extend(pnsSubgraphActions) */ export const pnsSubgraphActions = < TTransport extends Transport = Transport, TChain extends ChainWithPns = ChainWithPns, TAccount extends Account | undefined = Account | undefined, >( client: Client, ): PnsSubgraphActions => ({ getDecodedName: (parameters) => getDecodedName(client, parameters), getNameHistory: (parameters) => getNameHistory(client, parameters), getNamesForAddress: (parameters) => getNamesForAddress(client, parameters), getSubgraphRecords: (parameters) => getSubgraphRecords(client, parameters), getSubgraphRegistrant: (parameters) => getSubgraphRegistrant(client, parameters), getSubnames: (parameters) => getSubnames(client, parameters), getReferralBlacklists: (parameters) => getReferralBlacklists(client, parameters), getReferralStats: (parameters) => getReferralStats(client, parameters), getGracePeriodNames: (parameters) => getGracePeriodNames(client, parameters), })