Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.8.8",
"ts-node": "^10.7.0",
"typescript": "^5.3.2"
"typescript": "5.6.2"
},
"resolutions": {
"@nomiclabs/hardhat-ethers": "npm:[email protected]"
Expand Down
5 changes: 5 additions & 0 deletions packages/ensjs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
{
"selector": "typeLike",
"format": ["PascalCase"]
},
{
"selector": "typeParameter",
"format": ["camelCase"]
}
],
"@typescript-eslint/no-redeclare": "off",
"no-useless-return": ["off"],
"radix": ["error", "as-needed"],
"no-bitwise": ["off"],
Expand Down
10 changes: 7 additions & 3 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
"!src/**/*.test.ts",
"!src/test"
],
"repository": "[email protected]:ensdomains/ensjs.git",
"repository": {
"type": "git",
"url": "git+https://github.com/ensdomains/ensjs.git",
"directory": "packages/ensjs"
},
"author": "TateB <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -136,8 +140,8 @@
"ts-node": "^10.9.2",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^4.0.0-next.16",
"typescript": "5.3.2",
"viem": "^2.9.2",
"typescript": "5.6.2",
"viem": "2.21.15",
"vitest": "^1.3.1",
"wait-on": "^6.0.1"
},
Expand Down
116 changes: 65 additions & 51 deletions packages/ensjs/src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
import type { Account, Client, Transport } from 'viem'
import type { ChainWithEns } from '../../contracts/consts.js'
import batch, {
type BatchParameters,
type BatchReturnType,
} from '../../functions/public/batch.js'
import getAbiRecord, {
import {
getAbiRecord,
type GetAbiRecordParameters,
type GetAbiRecordReturnType,
} from '../../functions/public/getAbiRecord.js'
import getAddressRecord, {
import {
getAddressRecord,
type GetAddressRecordParameters,
type GetAddressRecordReturnType,
} from '../../functions/public/getAddressRecord.js'
import getAvailable, {
import {
getAvailable,
type GetAvailableParameters,
type GetAvailableReturnType,
} from '../../functions/public/getAvailable.js'
import getContentHashRecord, {
import {
getContentHashRecord,
type GetContentHashRecordParameters,
type GetContentHashRecordReturnType,
} from '../../functions/public/getContentHashRecord.js'
import getExpiry, {
import {
getCredentials,
type GetCredentialsParameters,
type GetCredentialsReturnType,
} from '../../functions/public/getCredentials.js'
import {
getExpiry,
type GetExpiryParameters,
type GetExpiryReturnType,
} from '../../functions/public/getExpiry.js'
import getName, {
import {
getName,
type GetNameParameters,
type GetNameReturnType,
} from '../../functions/public/getName.js'
import getOwner, {
import {
getOwner,
type GetOwnerParameters,
type GetOwnerReturnType,
} from '../../functions/public/getOwner.js'
import getPrice, {
import {
getPrice,
type GetPriceParameters,
type GetPriceReturnType,
} from '../../functions/public/getPrice.js'
import getRecords, {
import {
getRecords,
type GetRecordsParameters,
type GetRecordsReturnType,
} from '../../functions/public/getRecords.js'
import getResolver, {
import {
getResolver,
type GetResolverParameters,
type GetResolverReturnType,
} from '../../functions/public/getResolver.js'
import getTextRecord, {
import {
getTextRecord,
type GetTextRecordParameters,
type GetTextRecordReturnType,
} from '../../functions/public/getTextRecord.js'
import getWrapperData, {
import {
getWrapperData,
type GetWrapperDataParameters,
type GetWrapperDataReturnType,
} from '../../functions/public/getWrapperData.js'
import getWrapperName, {
import {
getWrapperName,
type GetWrapperNameParameters,
type GetWrapperNameReturnType,
} from '../../functions/public/getWrapperName.js'

export type EnsPublicActions = {
/**
* Batches multiple read functions into a single call.
* @param ...parameters - Array of {@link BatchFunctionResult} objects
* @returns Array of return values from each function
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { addEnsContracts, ensPublicActions, getTextRecord, getAddressRecord } from '@ensdomains/ensjs'
*
* const client = createPublicClient({
* chain: addEnsContracts(mainnet),
* transport: http(),
* }).extend(ensPublicActions)
* const result = await client.ensBatch(
* getTextRecord.batch({ name: 'ens.eth', key: 'com.twitter' }),
* getAddressRecord.batch({ name: 'ens.eth', coin: 'ETH' }),
* )
* // ['ensdomains', { id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7 }]
*/
ensBatch: <TBatchFunctions extends BatchParameters>(
...parameters: TBatchFunctions
) => Promise<BatchReturnType<TBatchFunctions>>
/**
* Gets the ABI record for a name
* @param parameters - {@link GetAbiRecordParameters}
Expand Down Expand Up @@ -187,6 +178,28 @@ export type EnsPublicActions = {
* const result = await client.getExpiry({ name: 'ens.eth' })
* // { expiry: { date: Date, value: 1913933217n }, gracePeriod: 7776000, status: 'active' }
*/
getCredentials: ({
name,
gatewayUrls,
strict,
}: GetCredentialsParameters) => Promise<GetCredentialsReturnType>
/**
* Gets credentials for a name.
* @param parameters - {@link GetCredentialsParameters}
* @returns Credentials, or null if none are found. {@link GetCredentialsReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { addEnsContracts, ensPublicActions } from '@ensdomains/ensjs'
*
* const client = createPublicClient({
* chain: addEnsContracts(mainnet),
* transport: http(),
* }).extend(ensPublicActions)
* const result = await client.getCredentials({ name: 'ens.eth' })
* // [{ url: 'https://example.com' }]
*/
getExpiry: ({
name,
contract,
Expand All @@ -211,6 +224,7 @@ export type EnsPublicActions = {
getName: ({
address,
allowMismatch,
allowUnnormalised,
gatewayUrls,
strict,
}: GetNameParameters) => Promise<GetNameReturnType>
Expand Down Expand Up @@ -279,13 +293,13 @@ export type EnsPublicActions = {
* // { texts: [{ key: 'com.twitter', value: 'ensdomains' }, { key: 'com.github', value: 'ensdomains' }], coins: [{ id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }], contentHash: { protocolType: 'ipns', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } }
*/
getRecords: <
const TTexts extends readonly string[] = readonly string[],
const TCoins extends readonly (string | number)[] = readonly (
const texts extends readonly string[] = readonly string[],
const coins extends readonly (string | number)[] = readonly (
| string
| number
)[],
const TContentHash extends boolean = true,
const TAbi extends boolean = true,
const contentHash extends boolean = true,
const abi extends boolean = true,
>({
name,
texts,
Expand All @@ -294,8 +308,8 @@ export type EnsPublicActions = {
abi,
resolver,
gatewayUrls,
}: GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>) => Promise<
GetRecordsReturnType<TTexts, TCoins, TContentHash, TAbi>
}: GetRecordsParameters<texts, coins, contentHash, abi>) => Promise<
GetRecordsReturnType<texts, coins, contentHash, abi>
>
/**
* Gets the resolver address for a name.
Expand Down Expand Up @@ -396,18 +410,18 @@ export type EnsPublicActions = {
* }).extend(ensPublicActions)
*/
export const ensPublicActions = <
TTransport extends Transport = Transport,
TChain extends ChainWithEns = ChainWithEns,
TAccount extends Account | undefined = Account | undefined,
transport extends Transport = Transport,
chain extends ChainWithEns = ChainWithEns,
account extends Account | undefined = Account | undefined,
>(
client: Client<TTransport, TChain, TAccount>,
client: Client<transport, chain, account>,
): EnsPublicActions => ({
ensBatch: (...parameters) => batch(client, ...parameters),
getAbiRecord: (parameters) => getAbiRecord(client, parameters),
getAddressRecord: (parameters) => getAddressRecord(client, parameters),
getAvailable: (parameters) => getAvailable(client, parameters),
getContentHashRecord: (parameters) =>
getContentHashRecord(client, parameters),
getCredentials: (parameters) => getCredentials(client, parameters),
getExpiry: (parameters) => getExpiry(client, parameters),
getName: (parameters) => getName(client, parameters),
getOwner: (parameters) => getOwner(client, parameters),
Expand Down
8 changes: 4 additions & 4 deletions packages/ensjs/src/clients/decorators/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ export type EnsSubgraphActions = {
* }).extend(ensSubgraphActions)
*/
export const ensSubgraphActions = <
TTransport extends Transport = Transport,
TChain extends ChainWithEns = ChainWithEns,
TAccount extends Account | undefined = Account | undefined,
transport extends Transport = Transport,
chain extends ChainWithEns = ChainWithEns,
account extends Account | undefined = Account | undefined,
>(
client: Client<TTransport, TChain, TAccount>,
client: Client<transport, chain, account>,
): EnsSubgraphActions => ({
getDecodedName: (parameters) => getDecodedName(client, parameters),
getNameHistory: (parameters) => getNameHistory(client, parameters),
Expand Down
Loading
Loading