From 2ee609d79b81ca25c11b8b4b1a7bb6ef1a5e049b Mon Sep 17 00:00:00 2001 From: tate Date: Mon, 3 Jul 2023 13:53:17 +1000 Subject: [PATCH] checkpoint --- .vscode/settings.json | 3 +- package.json | 2 +- packages/ensjs/package.json | 6 +- .../ensjs/src/clients/decorators/public.ts | 394 ++++++++++ .../ensjs/src/clients/decorators/subgraph.ts | 194 +++++ .../ensjs/src/clients/decorators/wallet.ts | 708 ++++++++++++++++++ packages/ensjs/src/clients/public.ts | 81 ++ packages/ensjs/src/clients/subgraph.ts | 72 ++ packages/ensjs/src/clients/wallet.ts | 90 +++ .../ensjs/src/contracts/addEnsContracts.ts | 42 ++ .../contracts/{addContracts.ts => consts.ts} | 86 +-- .../src/contracts/getChainContractAddress.ts | 2 +- packages/ensjs/src/contracts/index.ts | 2 +- packages/ensjs/src/errors/contracts.ts | 34 + .../ensjs/src/functions/dns/importDnsName.ts | 2 +- .../src/functions/dns/prepareDnsImport.ts | 7 +- packages/ensjs/src/functions/read/_getAbi.ts | 2 +- packages/ensjs/src/functions/read/_getAddr.ts | 4 +- .../src/functions/read/_getContentHash.ts | 2 +- packages/ensjs/src/functions/read/_getText.ts | 2 +- .../ensjs/src/functions/read/batch.test.ts | 9 +- packages/ensjs/src/functions/read/batch.ts | 37 +- .../ensjs/src/functions/read/ccip.test.ts | 9 +- .../ensjs/src/functions/read/getAbiRecord.ts | 7 +- .../functions/read/getAddressRecord.test.ts | 9 +- .../src/functions/read/getAddressRecord.ts | 7 +- .../ensjs/src/functions/read/getAvailable.ts | 7 +- .../functions/read/getContentHashRecord.ts | 7 +- .../ensjs/src/functions/read/getExpiry.ts | 7 +- packages/ensjs/src/functions/read/getName.ts | 7 +- packages/ensjs/src/functions/read/getOwner.ts | 7 +- packages/ensjs/src/functions/read/getPrice.ts | 7 +- .../ensjs/src/functions/read/getRecords.ts | 7 +- .../ensjs/src/functions/read/getResolver.ts | 7 +- .../functions/read/getSupportedInterfaces.ts | 2 +- .../ensjs/src/functions/read/getTextRecord.ts | 7 +- .../src/functions/read/getWrapperData.ts | 7 +- .../src/functions/read/getWrapperName.ts | 7 +- .../src/functions/read/multicallWrapper.ts | 2 +- .../src/functions/read/universalWrapper.ts | 2 +- .../ensjs/src/functions/subgraph/client.ts | 2 +- .../src/functions/subgraph/getDecodedName.ts | 7 +- .../src/functions/subgraph/getNameHistory.ts | 7 +- .../functions/subgraph/getNamesForAddress.ts | 7 +- .../functions/subgraph/getSubgraphRecords.ts | 7 +- .../subgraph/getSubgraphRegistrant.ts | 7 +- .../src/functions/subgraph/getSubnames.ts | 7 +- .../ensjs/src/functions/write/commitName.ts | 13 +- .../src/functions/write/createSubname.ts | 13 +- .../src/functions/write/deleteSubname.ts | 11 +- .../ensjs/src/functions/write/registerName.ts | 6 +- .../ensjs/src/functions/write/renewNames.ts | 6 +- .../ensjs/src/functions/write/setAbiRecord.ts | 13 +- .../src/functions/write/setAddressRecord.ts | 13 +- .../src/functions/write/setChildFuses.ts | 13 +- .../functions/write/setContentHashRecord.ts | 13 +- .../ensjs/src/functions/write/setFuses.ts | 13 +- .../src/functions/write/setPrimaryName.ts | 13 +- .../ensjs/src/functions/write/setRecords.ts | 13 +- .../ensjs/src/functions/write/setResolver.ts | 13 +- .../src/functions/write/setTextRecord.ts | 13 +- .../ensjs/src/functions/write/transferName.ts | 13 +- .../ensjs/src/functions/write/unwrapName.ts | 13 +- .../ensjs/src/functions/write/wrapName.ts | 13 +- packages/ensjs/src/types.ts | 22 +- .../ensjs/src/utils/ownerFromContract.test.ts | 16 +- packages/ensjs/src/utils/ownerFromContract.ts | 2 +- pnpm-lock.yaml | 43 +- 68 files changed, 1869 insertions(+), 359 deletions(-) create mode 100644 packages/ensjs/src/clients/decorators/public.ts create mode 100644 packages/ensjs/src/clients/decorators/subgraph.ts create mode 100644 packages/ensjs/src/clients/decorators/wallet.ts create mode 100644 packages/ensjs/src/clients/public.ts create mode 100644 packages/ensjs/src/clients/subgraph.ts create mode 100644 packages/ensjs/src/clients/wallet.ts create mode 100644 packages/ensjs/src/contracts/addEnsContracts.ts rename packages/ensjs/src/contracts/{addContracts.ts => consts.ts} (70%) create mode 100644 packages/ensjs/src/errors/contracts.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 46b1ef28..b1cb2fdf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,8 +3,7 @@ "**/.yarn": true, "**/.pnp.*": true }, - "eslint.nodePath": ".yarn/sdks", - "prettier.prettierPath": ".yarn/sdks/prettier/index.js", + "prettier.prettierPath": "node_modules/prettier/index.js", "typescript.tsdk": "node_modules/typescript/lib", "typescript.enablePromptUseWorkspaceTsdk": true } diff --git a/package.json b/package.json index 0f239cf5..3fc12306 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.0.0", - "prettier": "^2.6.0", + "prettier": "^2.8.8", "ts-node": "^10.7.0", "typescript": "^5.0.4" }, diff --git a/packages/ensjs/package.json b/packages/ensjs/package.json index 0ae70df2..89d65656 100644 --- a/packages/ensjs/package.json +++ b/packages/ensjs/package.json @@ -108,13 +108,13 @@ "jest-environment-node": "^29.5.0", "jest-localstorage-mock": "^2.4.21", "solc": "^0.8.13", - "ts-jest": "^29.1.0", + "ts-jest": "^29.1.1", "ts-node": "^10.7.0", "typescript": "^5.0.4", "wait-on": "^6.0.1", - "viem": "^0.3.24" + "viem": "^1.2.9" }, "peerDependencies": { - "viem": "^0.3.24" + "viem": "^1.2.9" } } diff --git a/packages/ensjs/src/clients/decorators/public.ts b/packages/ensjs/src/clients/decorators/public.ts new file mode 100644 index 00000000..858a5565 --- /dev/null +++ b/packages/ensjs/src/clients/decorators/public.ts @@ -0,0 +1,394 @@ +import { type Account, type Client, type Transport } from 'viem' +import type { ChainWithEns } from '../../contracts/consts' +import batch, { + type BatchParameters, + type BatchReturnType, +} from '../../functions/read/batch' +import getAbiRecord, { + type GetAbiRecordParameters, + type GetAbiRecordReturnType, +} from '../../functions/read/getAbiRecord' +import getAddressRecord, { + type GetAddressRecordParameters, + type GetAddressRecordReturnType, +} from '../../functions/read/getAddressRecord' +import getAvailable, { + type GetAvailableParameters, + type GetAvailableReturnType, +} from '../../functions/read/getAvailable' +import getContentHashRecord, { + type GetContentHashRecordParameters, + type GetContentHashRecordReturnType, +} from '../../functions/read/getContentHashRecord' +import getExpiry, { + type GetExpiryParameters, + type GetExpiryReturnType, +} from '../../functions/read/getExpiry' +import getName, { + type GetNameParameters, + type GetNameReturnType, +} from '../../functions/read/getName' +import getOwner, { + type GetOwnerParameters, + type GetOwnerReturnType, +} from '../../functions/read/getOwner' +import getPrice, { + type GetPriceParameters, + type GetPriceReturnType, +} from '../../functions/read/getPrice' +import getRecords, { + type GetRecordsParameters, + type GetRecordsReturnType, +} from '../../functions/read/getRecords' +import getResolver, { + type GetResolverParameters, + type GetResolverReturnType, +} from '../../functions/read/getResolver' +import getTextRecord, { + type GetTextRecordParameters, + type GetTextRecordReturnType, +} from '../../functions/read/getTextRecord' +import getWrapperData, { + type GetWrapperDataParameters, + type GetWrapperDataReturnType, +} from '../../functions/read/getWrapperData' +import getWrapperName, { + type GetWrapperNameParameters, + type GetWrapperNameReturnType, +} from '../../functions/read/getWrapperName' + +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: ( + ...parameters: TBatchFunctions + ) => Promise> + /** + * Gets the ABI record for a name + * @param parameters - {@link GetAbiRecordParameters} + * @returns ABI record for the name, or `null` if not found. {@link GetAbiRecordReturnType} + * + * @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.getAbiRecord({ name: 'ens.eth' }) + * // TODO: real example + */ + getAbiRecord: ({ + name, + }: GetAbiRecordParameters) => Promise + /** + * Gets an address record for a name and specified coin + * @param parameters - {@link GetAddressRecordParameters} + * @returns Coin value object, or `null` if not found. {@link GetAddressRecordReturnType} + * + * @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.getAddressRecord({ name: 'ens.eth', coin: 'ETH' }) + * // { id: 60, name: 'ETH , value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' } + */ + getAddressRecord: ({ + name, + coin, + bypassFormat, + }: GetAddressRecordParameters) => Promise + /** + * Gets the availability of a name to register + * @param parameters - {@link GetAvailableParameters} + * @returns Availability as boolean. {@link GetAvailableReturnType} + * + * @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.getAvailable({ name: 'ens.eth' }) + * // false + */ + getAvailable: ({ + name, + }: GetAvailableParameters) => Promise + /** + * Gets the content hash record for a name + * @param parameters - {@link GetContentHashRecordParameters} + * @returns Content hash object, or `null` if not found. {@link GetContentHashRecordReturnType} + * + * @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.getContentHashRecord({ name: 'ens.eth' }) + * // { protocolType: 'ipfs', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } + */ + getContentHashRecord: ({ + name, + }: GetContentHashRecordParameters) => Promise + /** + * Gets the expiry for a name + * @param parameters - {@link GetExpiryParameters} + * @returns Expiry object, or `null` if no expiry. {@link GetExpiryReturnType} + * + * @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.getExpiry({ name: 'ens.eth' }) + * // { expiry: { date: Date, value: 1913933217n }, gracePeriod: 7776000, status: 'active' } + */ + getExpiry: ({ + name, + contract, + }: GetExpiryParameters) => Promise + /** + * Gets the primary name for an address + * @param parameters - {@link GetNameParameters} + * @returns Name data object, or `null` if no primary name is set. {@link GetNameReturnType} + * + * @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.getName({ address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5' }) + * // { name: 'nick.eth', match: true, reverseResolverAddress: '0xa2c122be93b0074270ebee7f6b7292c7deb45047', resolverAddress: '0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41' } + */ + getName: ({ address }: GetNameParameters) => Promise + /** + * Gets the owner(s) of a name. + * @param parameters - {@link GetOwnerParameters} + * @returns Owner data object, or `null` if no owners exist. {@link GetOwnerReturnType} + * + * @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.getOwner({ name: 'ens.eth' }) + * // { owner: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9', registrant: '0xb6E040C9ECAaE172a89bD561c5F73e1C48d28cd9', ownershipLevel: 'registrar } + */ + getOwner: ({ + name, + contract, + }: GetOwnerParameters) => Promise + /** + * Gets the price of a name, or array of names, for a given duration. + * @param parameters - {@link GetPriceParameters} + * @returns Price data object. {@link GetPriceReturnType} + * + * @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.getPrice({ nameOrNames: 'ens.eth' }) + * // { base: 352828971668930335n, premium: 0n } + */ + getPrice: ({ + nameOrNames, + duration, + }: GetPriceParameters) => Promise + /** + * Gets arbitrary records for a name + * @param parameters - {@link GetRecordsParameters} + * @returns Records data object. {@link GetRecordsReturnType} + * + * @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.getRecords({ + * name: 'ens.eth', + * records: { + * texts: ['com.twitter', 'com.github'], + * coins: ['ETH'], + * contentHash: true, + * }, + * }) + * // { texts: [{ key: 'com.twitter', value: 'ensdomains' }, { key: 'com.github', value: 'ensdomains' }], coins: [{ id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }], contentHash: { protocolType: 'ipns', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } } + */ + getRecords: ({ + name, + records, + resolver, + }: GetRecordsParameters) => Promise + /** + * Gets the resolver address for a name. + * @param parameters - {@link GetResolverParameters} + * @returns Resolver address, or null if none is found. {@link GetResolverReturnType} + * + * @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.getResolver({ name: 'ens.eth' }) + * // 0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41 + */ + getResolver: ({ + name, + }: GetResolverParameters) => Promise + /** + * Gets a text record for a name. + * @param parameters - {@link GetTextRecordParameters} + * @returns Text record string, or null if none is found. {@link GetTextRecordReturnType} + * + * @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.getTextRecord({ name: 'ens.eth', key: 'com.twitter' }) + * // ensdomains + */ + getTextRecord: ({ + name, + key, + }: GetTextRecordParameters) => Promise + /** + * Gets the wrapper data for a name. + * @param parameters - {@link GetWrapperDataParameters} + * @returns Wrapper data object, or null if name is not wrapped. {@link GetWrapperDataReturnType} + * + * @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.getWrapperData({ name: 'ilikelasagna.eth' }) + */ + getWrapperData: ({ + name, + }: GetWrapperDataParameters) => Promise + /** + * Gets the full name for a name with unknown labels from the NameWrapper. + * @param parameters - {@link GetWrapperNameParameters} + * @returns Full name, or null if name was not found. {@link GetWrapperNameReturnType} + * + * @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.getWrapperName({ name: '[4ca938ec1b323ca71c4fb47a712abb68cce1cabf39ea4d6789e42fbc1f95459b].eth' }) + * // wrapped.eth + */ + getWrapperName: ({ + name, + }: GetWrapperNameParameters) => Promise +} + +/** + * Extends the viem client with ENS public actions + * @param client - The viem {@link Client} object to add the ENS public actions to + * + * @example + * import { createPublicClient, http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensPublicActions } from '@ensdomains/ensjs' + * + * const clientWithEns = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensPublicActions) + */ +export const ensPublicActions = < + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, + TAccount extends Account | undefined = Account | undefined, +>( + client: Client, +): 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), + getExpiry: (parameters) => getExpiry(client, parameters), + getName: (parameters) => getName(client, parameters), + getOwner: (parameters) => getOwner(client, parameters), + getPrice: (parameters) => getPrice(client, parameters), + getRecords: (parameters) => getRecords(client, parameters), + getResolver: (parameters) => getResolver(client, parameters), + getTextRecord: (parameters) => getTextRecord(client, parameters), + getWrapperData: (parameters) => getWrapperData(client, parameters), + getWrapperName: (parameters) => getWrapperName(client, parameters), +}) diff --git a/packages/ensjs/src/clients/decorators/subgraph.ts b/packages/ensjs/src/clients/decorators/subgraph.ts new file mode 100644 index 00000000..c6c92cc6 --- /dev/null +++ b/packages/ensjs/src/clients/decorators/subgraph.ts @@ -0,0 +1,194 @@ +import { type Account, type Client, type Transport } from 'viem' +import { type ChainWithEns } from '../../contracts/consts' +import getDecodedName, { + type GetDecodedNameParameters, + type GetDecodedNameReturnType, +} from '../../functions/subgraph/getDecodedName' +import getNameHistory, { + type GetNameHistoryParameters, + type GetNameHistoryReturnType, +} from '../../functions/subgraph/getNameHistory' +import getNamesForAddress, { + type GetNamesForAddressParameters, + type GetNamesForAddressReturnType, +} from '../../functions/subgraph/getNamesForAddress' +import getSubgraphRecords, { + type GetSubgraphRecordsParameters, + type GetSubgraphRecordsReturnType, +} from '../../functions/subgraph/getSubgraphRecords' +import getSubgraphRegistrant, { + type GetSubgraphRegistrantParameters, + type GetSubgraphRegistrantReturnType, +} from '../../functions/subgraph/getSubgraphRegistrant' +import getSubnames, { + type GetSubnamesParameters, + type GetSubnamesReturnType, +} from '../../functions/subgraph/getSubnames' + +export type EnsSubgraphActions = { + /** + * 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * const result = await client.getDecodedName({ name: '[5cee339e13375638553bdf5a6e36ba80fb9f6a4f0783680884d92b558aa471da].eth' }) + * // ens.eth + */ + 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * const result = await client.getNameHistory({ name: 'ens.eth' }) + */ + 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * const result = await client.getSubgraphRecords({ name: 'ens.eth' }) + * // { + * // isMigrated: true, + * // createdAt: { date: 2019-08-26T05:09:01.000Z, value: 1566796141000 }, + * // texts: [ 'snapshot', 'url', 'avatar', 'com.twitter', 'com.github' ], + * // coins: [ '60' ] + * // } + */ + 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * const result = await client.getSubgraphRegistrant({ name: 'ens.eth' }) + * // 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 { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const client = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + * const result = await client.getSubnames({ name: 'ens.eth' }) + */ + getSubnames: ({ + name, + searchString, + allowExpired, + orderBy, + orderDirection, + pageSize, + previousPage, + }: GetSubnamesParameters) => Promise +} + +/** + * Extends the viem client with ENS subgraph actions + * @param client - The viem {@link Client} object to add the ENS subgraph actions to + * + * @example + * import { createPublicClient, http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensSubgraphActions } from '@ensdomains/ensjs' + * + * const clientWithEns = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }).extend(ensSubgraphActions) + */ +export const ensSubgraphActions = < + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, + TAccount extends Account | undefined = Account | undefined, +>( + client: Client, +): EnsSubgraphActions => ({ + 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), +}) diff --git a/packages/ensjs/src/clients/decorators/wallet.ts b/packages/ensjs/src/clients/decorators/wallet.ts new file mode 100644 index 00000000..50f2cd19 --- /dev/null +++ b/packages/ensjs/src/clients/decorators/wallet.ts @@ -0,0 +1,708 @@ +import { type Account, type Transport, type WalletClient } from 'viem' +import { type ChainWithEns } from '../../contracts/consts' +import commitName, { + type CommitNameParameters, + type CommitNameReturnType, +} from '../../functions/write/commitName' +import createSubname, { + type CreateSubnameParameters, + type CreateSubnameReturnType, +} from '../../functions/write/createSubname' +import deleteSubname, { + type DeleteSubnameParameters, + type DeleteSubnameReturnType, +} from '../../functions/write/deleteSubname' +import registerName, { + type RegisterNameParameters, + type RegisterNameReturnType, +} from '../../functions/write/registerName' +import renewNames, { + type RenewNamesParameters, + type RenewNamesReturnType, +} from '../../functions/write/renewNames' +import setAbiRecord, { + type SetAbiRecordParameters, + type SetAbiRecordReturnType, +} from '../../functions/write/setAbiRecord' +import setAddressRecord, { + type SetAddressRecordParameters, + type SetAddressRecordReturnType, +} from '../../functions/write/setAddressRecord' +import setChildFuses, { + type SetChildFusesParameters, + type SetChildFusesReturnType, +} from '../../functions/write/setChildFuses' +import setContentHashRecord, { + type SetContentHashRecordParameters, + type SetContentHashRecordReturnType, +} from '../../functions/write/setContentHashRecord' +import setFuses, { + type SetFusesParameters, + type SetFusesReturnType, +} from '../../functions/write/setFuses' +import setPrimaryName, { + type SetPrimaryNameParameters, + type SetPrimaryNameReturnType, +} from '../../functions/write/setPrimaryName' +import setRecords, { + type SetRecordsParameters, + type SetRecordsReturnType, +} from '../../functions/write/setRecords' +import setResolver, { + type SetResolverParameters, + type SetResolverReturnType, +} from '../../functions/write/setResolver' +import setTextRecord, { + type SetTextRecordParameters, + type SetTextRecordReturnType, +} from '../../functions/write/setTextRecord' +import transferName, { + type TransferNameParameters, + type TransferNameReturnType, +} from '../../functions/write/transferName' +import unwrapName, { + type UnwrapNameParameters, + type UnwrapNameReturnType, +} from '../../functions/write/unwrapName' +import wrapName, { + type WrapNameParameters, + type WrapNameReturnType, +} from '../../functions/write/wrapName' + +export type EnsWalletActions< + TChain extends ChainWithEns, + TAccount extends Account | undefined, +> = { + /** + * Commits a name to be registered + * @param parameters - {@link CommitNameParameters} + * @returns Transaction hash. {@link CommitNameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions, randomSecret } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const secret = randomSecret() + * const hash = await wallet.commitName({ + * name: 'example.eth', + * owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * duration: 31536000, // 1 year + * secret, + * }) + * // 0x... + */ + commitName: ({ + name, + owner, + duration, + secret, + resolverAddress, + records, + reverseRecord, + fuses, + ...txArgs + }: CommitNameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Creates a subname + * @param parameters - {@link CreateSubnameParameters} + * @returns Transaction hash. {@link CreateSubnameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.createSubname({ + * name: 'sub.ens.eth', + * owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * contract: 'registry', + * }) + * // 0x... + */ + createSubname: ({ + name, + contract, + owner, + resolverAddress, + expiry, + fuses, + ...txArgs + }: CreateSubnameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Deletes a subname + * @param parameters - {@link DeleteSubnameParameters} + * @returns Transaction hash. {@link DeleteSubnameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.deleteSubname({ + * name: 'sub.ens.eth', + * contract: 'registry', + * }) + * // 0x... + */ + deleteSubname: ({ + name, + contract, + asOwner, + ...txArgs + }: DeleteSubnameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Registers a name on ENS + * @param parameters - {@link RegisterNameParameters} + * @returns Transaction hash. {@link RegisterNameReturnType} + * + * @example + * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensPublicActions, ensWalletActions, randomSecret } from '@ensdomains/ensjs' + * + * const mainnetWithEns = addEnsContracts(mainnet) + * const client = createPublicClient({ + * chain: mainnetWithEns, + * transport: http(), + * }).extend(ensPublicActions) + * const wallet = createWalletClient({ + * chain: mainnetWithEns, + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const secret = randomSecret() + * const params = { + * name: 'example.eth', + * owner: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * duration: 31536000, // 1 year + * secret, + * } + * + * const commitmentHash = await wallet.commitName(params) + * await client.waitForTransactionReceipt({ hash: commitmentHash }) // wait for commitment to finalise + * await new Promise((resolve) => setTimeout(resolve, 60 * 1_000)) // wait for commitment to be valid + * + * const { base, premium } = await client.getPrice({ nameOrNames: params.name, duration: params.duration }) + * const value = (base + premium) * 110n / 100n // add 10% to the price for buffer + * const hash = await wallet.registerName({ ...params, value }) + * // 0x... + */ + registerName: ({ + name, + owner, + duration, + secret, + resolverAddress, + records, + reverseRecord, + fuses, + value, + ...txArgs + }: RegisterNameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Renews a name or names for a specified duration. + * @param parameters - {@link RenewNamesParameters} + * @returns Transaction hash. {@link RenewNamesReturnType} + * + * @example + * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensPublicActions, ensWalletActions } from '@ensdomains/ensjs' + * + * const mainnetWithEns = addEnsContracts(mainnet) + * const client = createPublicClient({ + * chain: mainnetWithEns, + * transport: http(), + * }).extend(ensPublicActions) + * const wallet = createWalletClient({ + * chain: mainnetWithEns, + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * + * const duration = 31536000 // 1 year + * const { base, premium } = await client.getPrice({ + * nameOrNames: 'example.eth', + * duration, + * }) + * const value = (base + premium) * 110n / 100n // add 10% to the price for buffer + * const hash = await wallet.renewNames({ + * nameOrNames: 'example.eth', + * duration, + * value, + * }) + * // 0x... + */ + renewNames: ({ + nameOrNames, + duration, + value, + ...txArgs + }: RenewNamesParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets the ABI for a name on a resolver. + * @param parameters - {@link SetAbiRecordParameters} + * @returns Transaction hash. {@link SetAbiRecordReturnType} + * + * @example + * import abi from './abi.json' + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions, encodeAbi } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * + * const encodedAbi = await encodeAbi({ encodeAs: 'json', abi }) + * const hash = await wallet.setAbiRecord({ + * name: 'ens.eth', + * encodedAbi, + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setAbiRecord: ({ + name, + encodedAbi, + resolverAddress, + ...txArgs + }: SetAbiRecordParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets an address record for a name on a resolver. + * @param parameters - {@link SetAddressRecordParameters} + * @returns Transaction hash. {@link SetAddressRecordReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setAddressRecord({ + * name: 'ens.eth', + * coin: 'ETH', + * value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setAddressRecord: ({ + name, + coin, + value, + resolverAddress, + ...txArgs + }: SetAddressRecordParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets the fuses for a name as the parent. + * @param parameters - {@link SetChildFusesParameters} + * @returns Transaction hash. {@link SetChildFusesReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setChildFuses({ + * name: 'sub.ens.eth', + * fuses: { + * parent: { + * named: ['PARENT_CANNOT_CONTROl'], + * }, + * }, + * }) + * // 0x... + */ + setChildFuses: ({ + name, + fuses, + expiry, + ...txArgs + }: SetChildFusesParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets the content hash record for a name on a resolver. + * @param parameters - {@link SetContentHashRecordParameters} + * @returns Transaction hash. {@link SetContentHashRecordReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setContentHashRecord({ + * name: 'ens.eth', + * value: 'ipns://k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw', + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setContentHashRecord: ({ + name, + contentHash, + resolverAddress, + ...txArgs + }: SetContentHashRecordParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets the fuses for a name. + * @param parameters - {@link SetFusesParameters} + * @returns Transaction hash. {@link SetFusesReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setFuses({ + * name: 'sub.ens.eth', + * fuses: { + * named: ['CANNOT_TRANSFER'], + * }, + * }) + * // 0x... + */ + setFuses: ({ + name, + fuses, + ...txArgs + }: SetFusesParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets a primary name for an address. + * @param parameters - {@link SetPrimaryNameParameters} + * @returns Transaction hash. {@link SetPrimaryNameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setPrimaryName({ + * name: 'ens.eth', + * }) + * // 0x... + */ + setPrimaryName: ({ + name, + address, + resolverAddress, + ...txArgs + }: SetPrimaryNameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets multiple records for a name on a resolver. + * @param parameters - {@link SetRecordsParameters} + * @returns Transaction hash. {@link SetRecordsReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setRecords({ + * name: 'ens.eth', + * coins: [ + * { + * coin: 'ETH', + * value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * }, + * ], + * texts: [{ key: 'foo', value: 'bar' }], + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setRecords: ({ + name, + resolverAddress, + clearRecords, + contentHash, + texts, + coins, + abi, + ...txArgs + }: SetRecordsParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets a resolver for a name. + * @param parameters - {@link SetResolverParameters} + * @returns Transaction hash. {@link SetResolverReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setResolver({ + * name: 'ens.eth', + * contract: 'registry', + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setResolver: ({ + name, + contract, + resolverAddress, + ...txArgs + }: SetResolverParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Sets a text record for a name on a resolver. + * @param parameters - {@link SetTextRecordParameters} + * @returns Transaction hash. {@link SetTextRecordReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.setTextRecord({ + * name: 'ens.eth', + * key: 'foo', + * value: 'bar', + * resolverAddress: '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41', + * }) + * // 0x... + */ + setTextRecord: ({ + name, + key, + value, + resolverAddress, + ...txArgs + }: SetTextRecordParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Transfers a name to a new owner. + * @param parameters - {@link TransferNameParameters} + * @returns Transaction hash. {@link TransferNameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.transferName({ + * name: 'ens.eth', + * newOwnerAddress: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * contract: 'registry', + * }) + * // 0x... + */ + transferName: ({ + name, + newOwnerAddress, + contract, + reclaim, + asParent, + ...txArgs + }: TransferNameParameters< + TChain, + TAccount, + TChain + >) => Promise + /** + * Unwraps a name. + * @param parameters - {@link UnwrapNameParameters} + * @returns Transaction hash. {@link UnwrapNameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.unwrapName({ + * name: 'example.eth', + * newOwnerAddress: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * newRegistrantAddress: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * }) + * // 0x... + */ + unwrapName: ({ + name, + newOwnerAddress, + newRegistrantAddress, + ...txArgs + }: UnwrapNameParameters< + TName, + TChain, + TAccount, + TChain + >) => Promise + /** + * Wraps a name. + * @param parameters - {@link WrapNameParameters} + * @returns Transaction hash. {@link WrapNameReturnType} + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const wallet = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + * const hash = await wallet.wrapName({ + * name: 'ens.eth', + * newOwnerAddress: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7', + * }) + * // 0x... + */ + wrapName: ({ + name, + newOwnerAddress, + fuses, + resolverAddress, + ...txArgs + }: WrapNameParameters< + TName, + TChain, + TAccount, + TChain + >) => Promise +} + +/** + * Extends the viem client with ENS wallet actions + * @param client - The viem {@link WalletClient} object to add the ENS wallet actions to + * + * @example + * import { createWalletClient, custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts, ensWalletActions } from '@ensdomains/ensjs' + * + * const clientWithEns = createWalletClient({ + * chain: addEnsContracts(mainnet), + * transport: custom(window.ethereum), + * }).extend(ensWalletActions) + */ +export const ensWalletActions = < + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, + TAccount extends Account | undefined = Account | undefined, +>( + client: WalletClient, +): EnsWalletActions => ({ + commitName: (parameters) => commitName(client, parameters), + createSubname: (parameters) => createSubname(client, parameters), + deleteSubname: (parameters) => deleteSubname(client, parameters), + registerName: (parameters) => registerName(client, parameters), + renewNames: (parameters) => renewNames(client, parameters), + setAbiRecord: (parameters) => setAbiRecord(client, parameters), + setAddressRecord: (parameters) => setAddressRecord(client, parameters), + setChildFuses: (parameters) => setChildFuses(client, parameters), + setContentHashRecord: (parameters) => + setContentHashRecord(client, parameters), + setFuses: (parameters) => setFuses(client, parameters), + setPrimaryName: (parameters) => setPrimaryName(client, parameters), + setRecords: (parameters) => setRecords(client, parameters), + setResolver: (parameters) => setResolver(client, parameters), + setTextRecord: (parameters) => setTextRecord(client, parameters), + transferName: (parameters) => transferName(client, parameters), + unwrapName: (parameters) => unwrapName(client, parameters), + wrapName: (parameters) => wrapName(client, parameters), +}) diff --git a/packages/ensjs/src/clients/public.ts b/packages/ensjs/src/clients/public.ts new file mode 100644 index 00000000..39177006 --- /dev/null +++ b/packages/ensjs/src/clients/public.ts @@ -0,0 +1,81 @@ +import { + createClient, + type Chain, + type Client, + type ClientConfig, + type Transport, +} from 'viem' +import { addEnsContracts } from '../contracts/addEnsContracts' +import { type ChainWithEns } from '../contracts/consts' +import { type Prettify } from '../types' +import { ensPublicActions, type EnsPublicActions } from './decorators/public' +import { + ensSubgraphActions, + type EnsSubgraphActions, +} from './decorators/subgraph' + +export type EnsPublicClientConfig< + TTransport extends Transport = Transport, + TChain extends Chain = Chain, +> = Pick< + ClientConfig, + 'batch' | 'key' | 'name' | 'pollingInterval' | 'transport' +> & { + chain: Exclude['chain'], undefined> +} + +export type EnsPublicClient< + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, +> = Prettify< + Client< + TTransport, + TChain, + undefined, + undefined, + EnsPublicActions & EnsSubgraphActions + > +> + +/** + * Creates a ENS Public Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html). + * + * @param config - {@link EnsPublicClientConfig} + * @returns An ENS Public Client. {@link EnsPublicClient} + * + * @example + * import { http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { createEnsPublicClient } from '@ensdomains/ensjs' + * + * const client = createEnsPublicClient({ + * chain: mainnet, + * transport: http(), + * }) + */ +export const createEnsPublicClient = < + TTransport extends Transport, + TChain extends Chain, +>({ + batch, + chain, + key = 'ensPublic', + name = 'ENS Public Client', + transport, + pollingInterval, +}: EnsPublicClientConfig): EnsPublicClient< + TTransport, + ChainWithEns +> => { + return createClient({ + batch, + chain: addEnsContracts(chain), + key, + name, + pollingInterval, + transport, + type: 'ensPublicClient', + }) + .extend(ensPublicActions) + .extend(ensSubgraphActions) +} diff --git a/packages/ensjs/src/clients/subgraph.ts b/packages/ensjs/src/clients/subgraph.ts new file mode 100644 index 00000000..3200c3e3 --- /dev/null +++ b/packages/ensjs/src/clients/subgraph.ts @@ -0,0 +1,72 @@ +import { + createClient, + type Chain, + type Client, + type ClientConfig, + type Transport, +} from 'viem' +import { addEnsContracts } from '../contracts/addEnsContracts' +import { type ChainWithEns } from '../contracts/consts' +import { type Prettify } from '../types' +import { + ensSubgraphActions, + type EnsSubgraphActions, +} from './decorators/subgraph' + +export type EnsSubgraphClientConfig< + TTransport extends Transport = Transport, + TChain extends Chain = Chain, +> = Pick< + ClientConfig, + 'batch' | 'key' | 'name' | 'pollingInterval' | 'transport' +> & { + chain: Exclude['chain'], undefined> +} + +export type EnsSubgraphClient< + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, +> = Prettify< + Client +> + +/** + * Creates a ENS Subgraph Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html). + * + * @param config - {@link EnsSubgraphClientConfig} + * @returns An ENS Subgraph Client. {@link EnsSubgraphClient} + * + * @example + * import { http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { createEnsSubgraphClient } from '@ensdomains/ensjs' + * + * const client = createEnsSubgraphClient({ + * chain: mainnet, + * transport: http(), + * }) + */ +export const createEnsSubgraphClient = < + TTransport extends Transport, + TChain extends Chain, +>({ + batch, + chain, + key = 'ensSubgraph', + name = 'ENS Subgraph Client', + transport, + pollingInterval, +}: EnsSubgraphClientConfig): EnsSubgraphClient< + TTransport, + ChainWithEns +> => { + return createClient({ + batch, + chain: addEnsContracts(chain), + key, + name, + pollingInterval, + transport, + type: 'ensSubgraphClient', + }).extend(ensSubgraphActions) +} diff --git a/packages/ensjs/src/clients/wallet.ts b/packages/ensjs/src/clients/wallet.ts new file mode 100644 index 00000000..3f23bf1b --- /dev/null +++ b/packages/ensjs/src/clients/wallet.ts @@ -0,0 +1,90 @@ +import { + Account, + Address, + ParseAccount, + WalletActions, + WalletRpcSchema, + createWalletClient, + type Chain, + type Client, + type ClientConfig, + type Transport, +} from 'viem' +import { addEnsContracts } from '../contracts/addEnsContracts' +import { type ChainWithEns } from '../contracts/consts' +import { type Prettify } from '../types' +import { ensWalletActions, type EnsWalletActions } from './decorators/wallet' + +export type EnsWalletClientConfig< + TTransport extends Transport, + TChain extends Chain, + TAccountOrAddress extends Account | Address | undefined = + | Account + | Address + | undefined, +> = Pick< + ClientConfig, + 'account' | 'chain' | 'key' | 'name' | 'pollingInterval' | 'transport' +> & { + chain: Exclude['chain'], undefined> +} + +export type EnsWalletClient< + TTransport extends Transport = Transport, + TChain extends ChainWithEns = ChainWithEns, + TAccount extends Account | undefined = Account | undefined, +> = Prettify< + Client< + TTransport, + TChain, + TAccount, + WalletRpcSchema, + WalletActions & EnsWalletActions + > +> + +/** + * Creates an ENS Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html). + * + * @param config - {@link EnsWalletClientConfig} + * @returns An ENS Wallet Client. {@link EnsWalletClient} + * + * @example + * import { custom } from 'viem' + * import { mainnet } from 'viem/chains' + * import { createEnsWalletClient } from '@ensdomains/ensjs' + * + * const client = createEnsWalletClient({ + * chain: mainnet, + * transport: custom(window.ethereum), + * }) + */ +export const createEnsWalletClient = < + TTransport extends Transport, + TChain extends Chain, + TAccountOrAddress extends Account | Address | undefined = undefined, +>({ + account, + chain, + key = 'ensWallet', + name = 'ENS Wallet Client', + transport, + pollingInterval, +}: EnsWalletClientConfig< + TTransport, + TChain, + TAccountOrAddress +>): EnsWalletClient< + TTransport, + ChainWithEns, + ParseAccount +> => { + return createWalletClient({ + account, + chain: addEnsContracts(chain), + key, + name, + pollingInterval, + transport, + }).extend(ensWalletActions) +} diff --git a/packages/ensjs/src/contracts/addEnsContracts.ts b/packages/ensjs/src/contracts/addEnsContracts.ts new file mode 100644 index 00000000..5d0ee2c4 --- /dev/null +++ b/packages/ensjs/src/contracts/addEnsContracts.ts @@ -0,0 +1,42 @@ +import { Chain } from 'viem' +import { NoChainError, UnsupportedNetworkError } from '../errors/contracts' +import { + ChainWithEns, + SupportedChain, + addresses, + subgraphs, + supportedChains, +} from './consts' + +/** + * Adds ENS contract addresses to the viem chain + * @param chain - The viem {@link Chain} object to add the ENS contracts to + * + * @example + * import { createPublicClient, http } from 'viem' + * import { mainnet } from 'viem/chains' + * import { addEnsContracts } from '@ensdomains/ensjs' + * + * const clientWithEns = createPublicClient({ + * chain: addEnsContracts(mainnet), + * transport: http(), + * }) + */ +export const addEnsContracts = (chain: TChain) => { + if (!chain) throw new NoChainError() + if (!supportedChains.includes(chain.network as SupportedChain)) + throw new UnsupportedNetworkError({ + network: chain.network, + supportedNetworks: supportedChains, + }) + return { + ...chain, + contracts: { + ...chain.contracts, + ...addresses[chain.network as SupportedChain], + }, + subgraphs: { + ...subgraphs[chain.network as SupportedChain], + }, + } as ChainWithEns +} diff --git a/packages/ensjs/src/contracts/addContracts.ts b/packages/ensjs/src/contracts/consts.ts similarity index 70% rename from packages/ensjs/src/contracts/addContracts.ts rename to packages/ensjs/src/contracts/consts.ts index 25a0469a..b6ba022e 100644 --- a/packages/ensjs/src/contracts/addContracts.ts +++ b/packages/ensjs/src/contracts/consts.ts @@ -1,15 +1,22 @@ -import type { - Account, - Chain, - PublicClient, - Transport, - WalletClient, -} from 'viem' +import { Account, Chain, Client, Transport, WalletClient } from 'viem' import type { ChainContract } from 'viem/src/types/chain' -const supportedChains = ['homestead', 'goerli'] +export const supportedChains = ['homestead', 'goerli'] as const +export const supportedContracts = [ + 'ensBaseRegistrarImplementation', + 'ensDnsRegistrar', + 'ensEthRegistrarController', + 'ensNameWrapper', + 'ensPublicResolver', + 'ensReverseRegistrar', + 'ensBulkRenewal', + 'ensDnssecImpl', +] as const -const addresses = { +export type SupportedChain = (typeof supportedChains)[number] +export type SupportedContract = (typeof supportedContracts)[number] + +export const addresses = { homestead: { ensBaseRegistrarImplementation: { address: '0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85', @@ -64,7 +71,19 @@ const addresses = { }, } as const -const subgraphs = { +// add when this is resolved: https://github.com/kulshekhar/ts-jest/issues/4100 +// } as const satisfies Record< +// SupportedChain, +// Record +// > + +type Subgraphs = { + ens: { + url: string + } +} + +export const subgraphs = { homestead: { ens: { url: 'https://api.thegraph.com/subgraphs/name/ensdomains/ens', @@ -77,11 +96,8 @@ const subgraphs = { }, } as const -type Subgraphs = { - ens: { - url: string - } -} +// add when this is resolved: https://github.com/kulshekhar/ts-jest/issues/4100 +// } as const satisfies Record type EnsChainContracts = { ensBaseRegistrarImplementation: ChainContract @@ -105,43 +121,21 @@ export type ChainWithEns = TChain & { subgraphs: Subgraphs } +export type CheckedChainWithEns = + TChain['network'] extends SupportedChain + ? TChain & { + contracts: (typeof addresses)[TChain['network']] + subgraphs: (typeof subgraphs)[TChain['network']] + } + : never + export type ClientWithEns< TTransport extends Transport = Transport, TChain extends ChainWithEns = ChainWithEns, -> = PublicClient +> = Client export type WalletWithEns< TTransport extends Transport = Transport, TChain extends ChainWithEns = ChainWithEns, TAccount extends Account | undefined = Account | undefined, > = WalletClient - -/** - * Adds the ENS contracts to a viem chain object - * @param chains - The {@link Chain} objects to add the ENS contracts to - * @returns A {@link Chain} array with ENS contracts added - * - * @example - * import { mainnet } from 'viem/chains' - * import { addContracts } from '@ensdomains/ensjs' - * - * const [mainnetWithEns] = addContracts([mainnet]) - */ -export const addContracts = ( - chains: TChain[], -): ChainWithEns[] => - chains - .filter((chain) => supportedChains.includes(chain.network)) - .map( - (chain) => - ({ - ...chain, - contracts: { - ...chain.contracts, - ...addresses[chain.network as keyof typeof addresses], - }, - subgraphs: { - ...subgraphs[chain.network as keyof typeof subgraphs], - }, - } as ChainWithEns), - ) diff --git a/packages/ensjs/src/contracts/getChainContractAddress.ts b/packages/ensjs/src/contracts/getChainContractAddress.ts index b16ff5e6..b4ce6ad2 100644 --- a/packages/ensjs/src/contracts/getChainContractAddress.ts +++ b/packages/ensjs/src/contracts/getChainContractAddress.ts @@ -1,5 +1,5 @@ import { getChainContractAddress as _getChainContractAddress } from 'viem/utils' -import { ChainWithEns } from './addContracts' +import { ChainWithEns } from './consts' type ChainClient = { chain: TChain diff --git a/packages/ensjs/src/contracts/index.ts b/packages/ensjs/src/contracts/index.ts index bbdbcaa3..07fd8aff 100644 --- a/packages/ensjs/src/contracts/index.ts +++ b/packages/ensjs/src/contracts/index.ts @@ -1,2 +1,2 @@ -export { addContracts } from './addContracts' +export { addEnsContracts } from './addEnsContracts' export { getChainContractAddress } from './getChainContractAddress' diff --git a/packages/ensjs/src/errors/contracts.ts b/packages/ensjs/src/errors/contracts.ts new file mode 100644 index 00000000..fc020371 --- /dev/null +++ b/packages/ensjs/src/errors/contracts.ts @@ -0,0 +1,34 @@ +import { BaseError } from './base' + +export class UnsupportedNetworkError extends BaseError { + network: string + + supportedNetworks: readonly string[] + + override name = 'UnsupportedNetworkError' + + constructor({ + network, + supportedNetworks, + details, + }: { + network: string + supportedNetworks: readonly string[] + details?: string + }) { + super(`Unsupported network: ${network}`, { + metaMessages: [`- Supported networks: ${supportedNetworks.join(', ')}`], + details, + }) + this.network = network + this.supportedNetworks = supportedNetworks + } +} + +export class NoChainError extends BaseError { + override name = 'NoChainError' + + constructor() { + super('No chain provided') + } +} diff --git a/packages/ensjs/src/functions/dns/importDnsName.ts b/packages/ensjs/src/functions/dns/importDnsName.ts index db66f612..e47bef85 100644 --- a/packages/ensjs/src/functions/dns/importDnsName.ts +++ b/packages/ensjs/src/functions/dns/importDnsName.ts @@ -8,7 +8,7 @@ import { encodeFunctionData, toHex, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { proveAndClaimSnippet, proveAndClaimWithResolverSnippet, diff --git a/packages/ensjs/src/functions/dns/prepareDnsImport.ts b/packages/ensjs/src/functions/dns/prepareDnsImport.ts index eceaf6b7..cd9ab7d6 100644 --- a/packages/ensjs/src/functions/dns/prepareDnsImport.ts +++ b/packages/ensjs/src/functions/dns/prepareDnsImport.ts @@ -2,7 +2,8 @@ import { DNSProver, ProvableAnswer, SignedSet } from '@ensdomains/dnsprovejs' import type * as packet from 'dns-packet' import { toType } from 'dns-packet/types' import { keccak256, toBytes, toHex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { readContract } from 'viem/actions' +import { ClientWithEns } from '../../contracts/consts' import { anchorsSnippet, rrDataSnippet } from '../../contracts/dnssecImpl' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { DnsNewerRecordTypeAvailableError } from '../../errors/dns' @@ -85,7 +86,7 @@ const prepareDnsImport = async ( const hexEncodedName = toHex(packetToBytes(proof.signature.name)) const type = toType(proof.signature.data.typeCovered) // eslint-disable-next-line no-await-in-loop - const [inception, expiration, hash] = await client.readContract({ + const [inception, expiration, hash] = await readContract(client, { abi: rrDataSnippet, address: ensDnssecImplAddress, functionName: 'rrdata', @@ -115,7 +116,7 @@ const prepareDnsImport = async ( return { rrsets: encodeProofs(allProofs), proof: toBytes( - await client.readContract({ + await readContract(client, { abi: anchorsSnippet, address: ensDnssecImplAddress, functionName: 'anchors', diff --git a/packages/ensjs/src/functions/read/_getAbi.ts b/packages/ensjs/src/functions/read/_getAbi.ts index 9d2ba4c8..69846ebc 100644 --- a/packages/ensjs/src/functions/read/_getAbi.ts +++ b/packages/ensjs/src/functions/read/_getAbi.ts @@ -5,7 +5,7 @@ import { hexToBytes, hexToString, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { abiSnippet } from '../../contracts/publicResolver' import { DecodedAbi, Prettify, SimpleTransactionRequest } from '../../types' import { EMPTY_ADDRESS } from '../../utils/consts' diff --git a/packages/ensjs/src/functions/read/_getAddr.ts b/packages/ensjs/src/functions/read/_getAddr.ts index f1e517d8..c19acd04 100644 --- a/packages/ensjs/src/functions/read/_getAddr.ts +++ b/packages/ensjs/src/functions/read/_getAddr.ts @@ -2,7 +2,7 @@ import { formatsByCoinType, formatsByName } from '@ensdomains/address-encoder' import { Hex, decodeFunctionResult, encodeFunctionData, trim } from 'viem' import { namehash } from '../../utils/normalise' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { multiAddrSnippet, singleAddrSnippet, @@ -98,7 +98,7 @@ const decode = async ( if (!response) return null const trimmed = trim(response) - if (trimmed === '0x' || trimmed === '0x0') { + if (trimmed === '0x' || trimmed === '0x0' || trimmed === '0x00') { return null } diff --git a/packages/ensjs/src/functions/read/_getContentHash.ts b/packages/ensjs/src/functions/read/_getContentHash.ts index c246bce7..33b0840c 100644 --- a/packages/ensjs/src/functions/read/_getContentHash.ts +++ b/packages/ensjs/src/functions/read/_getContentHash.ts @@ -1,5 +1,5 @@ import { Hex, decodeFunctionResult, encodeFunctionData } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { contenthashSnippet } from '../../contracts/publicResolver' import { Prettify, SimpleTransactionRequest } from '../../types' import { EMPTY_ADDRESS } from '../../utils/consts' diff --git a/packages/ensjs/src/functions/read/_getText.ts b/packages/ensjs/src/functions/read/_getText.ts index 6cd95682..d0e01e5b 100644 --- a/packages/ensjs/src/functions/read/_getText.ts +++ b/packages/ensjs/src/functions/read/_getText.ts @@ -1,5 +1,5 @@ import { Hex, decodeFunctionResult, encodeFunctionData } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { textSnippet } from '../../contracts/publicResolver' import { SimpleTransactionRequest } from '../../types' import { EMPTY_ADDRESS } from '../../utils/consts' diff --git a/packages/ensjs/src/functions/read/batch.test.ts b/packages/ensjs/src/functions/read/batch.test.ts index 9f108701..7c9a856c 100644 --- a/packages/ensjs/src/functions/read/batch.test.ts +++ b/packages/ensjs/src/functions/read/batch.test.ts @@ -1,18 +1,15 @@ import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' -import { addContracts } from '../../contracts/addContracts' +import { addEnsContracts } from '../../contracts' import { publicClient } from '../../tests/addTestContracts' import batch from './batch' import getAddressRecord from './getAddressRecord' import getName from './getName' import getText from './getTextRecord' -const [mainnetWithEns] = addContracts([mainnet]) -const transport = http('https://web3.ens.domains/v1/mainnet') - const mainnetPublicClient = createPublicClient({ - chain: mainnetWithEns, - transport, + chain: addEnsContracts(mainnet), + transport: http('https://web3.ens.domains/v1/mainnet'), }) describe('batch', () => { diff --git a/packages/ensjs/src/functions/read/batch.ts b/packages/ensjs/src/functions/read/batch.ts index 38770f58..bcd3a41b 100644 --- a/packages/ensjs/src/functions/read/batch.ts +++ b/packages/ensjs/src/functions/read/batch.ts @@ -1,5 +1,5 @@ import type { Hex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { FunctionNotBatchableError } from '../../errors/read' import { SimpleTransactionRequest, @@ -12,6 +12,18 @@ import { } from '../../utils/generateFunction' import multicallWrapper from './multicallWrapper' +type ExtractResult = TFunction extends { + decode: (...args: any[]) => Promise +} + ? U + : never + +export type BatchParameters = BatchFunctionResult[] + +export type BatchReturnType = { + [TFunctionName in keyof TFunctions]: ExtractResult +} + const encode = ( client: ClientWithEns, ...items: BatchFunctionResult[] @@ -28,24 +40,14 @@ const encode = ( return { ...response, passthrough: rawDataArr } } -type ExtractResult = TFunction extends { - decode: (...args: any[]) => Promise -} - ? U - : never - -type BatchReturnType = { - [TFunctionName in keyof TFunctions]: ExtractResult -} - const decode = async ( client: ClientWithEns, data: Hex, passthrough: TransactionRequestWithPassthrough[], ...items: I -): Promise | undefined> => { +): Promise> => { const response = await multicallWrapper.decode(client, data, passthrough) - if (!response) return + if (!response) throw new Error('No response from multicall') return Promise.all( response.map((ret, i: number) => { @@ -73,16 +75,15 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, batch, getText, getAddressRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, batch, getTextRecord, getAddressRecord } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await batch( * client, - * getText.batch({ name: 'ens.eth', key: 'com.twitter' }), + * getTextRecord.batch({ name: 'ens.eth', key: 'com.twitter' }), * getAddressRecord.batch({ name: 'ens.eth', coin: 'ETH' }), * ) * // ['ensdomains', { id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7 }] @@ -93,7 +94,7 @@ const batch = generateFunction({ }) as (( client: ClientWithEns, ...args: I -) => Promise | undefined>) & +) => Promise>) & BatchableFunctionObject export default batch diff --git a/packages/ensjs/src/functions/read/ccip.test.ts b/packages/ensjs/src/functions/read/ccip.test.ts index c10cbbbb..7c377e96 100644 --- a/packages/ensjs/src/functions/read/ccip.test.ts +++ b/packages/ensjs/src/functions/read/ccip.test.ts @@ -1,17 +1,14 @@ import { createPublicClient, http } from 'viem' import { goerli } from 'viem/chains' -import { addContracts } from '../../contracts/addContracts' +import { addEnsContracts } from '../../contracts' import batch from './batch' import getAddressRecord from './getAddressRecord' import getRecords from './getRecords' import getText from './getTextRecord' -const [goerliWithEns] = addContracts([goerli]) -const transport = http('https://web3.ens.domains/v1/goerli') - const goerliPublicClient = createPublicClient({ - chain: goerliWithEns, - transport, + chain: addEnsContracts(goerli), + transport: http('https://web3.ens.domains/v1/goerli'), }) jest.setTimeout(30000) diff --git a/packages/ensjs/src/functions/read/getAbiRecord.ts b/packages/ensjs/src/functions/read/getAbiRecord.ts index 67bb07b8..670dbd43 100644 --- a/packages/ensjs/src/functions/read/getAbiRecord.ts +++ b/packages/ensjs/src/functions/read/getAbiRecord.ts @@ -1,5 +1,5 @@ import { Hex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest } from '../../types' import { GeneratedFunction, @@ -43,11 +43,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getAbiRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, getAbiRecord } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getAbiRecord(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getAddressRecord.test.ts b/packages/ensjs/src/functions/read/getAddressRecord.test.ts index 88b9a5bf..e955f745 100644 --- a/packages/ensjs/src/functions/read/getAddressRecord.test.ts +++ b/packages/ensjs/src/functions/read/getAddressRecord.test.ts @@ -1,15 +1,12 @@ import { createPublicClient, http } from 'viem' import { mainnet } from 'viem/chains' -import { addContracts } from '../../contracts/addContracts' +import { addEnsContracts } from '../../contracts' import { publicClient } from '../../tests/addTestContracts' import getAddressRecord from './getAddressRecord' -const [mainnetWithEns] = addContracts([mainnet]) -const transport = http('https://web3.ens.domains/v1/mainnet') - const mainnetPublicClient = createPublicClient({ - chain: mainnetWithEns, - transport, + chain: addEnsContracts(mainnet), + transport: http('https://web3.ens.domains/v1/mainnet'), }) describe('getAddressRecord()', () => { diff --git a/packages/ensjs/src/functions/read/getAddressRecord.ts b/packages/ensjs/src/functions/read/getAddressRecord.ts index 0f720c9b..38c24462 100644 --- a/packages/ensjs/src/functions/read/getAddressRecord.ts +++ b/packages/ensjs/src/functions/read/getAddressRecord.ts @@ -1,5 +1,5 @@ import { Hex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest } from '../../types' import { GeneratedFunction, @@ -44,11 +44,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getAddressRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, getAddressRecord } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getAddressRecord(client, { name: 'ens.eth', coin: 'ETH' }) diff --git a/packages/ensjs/src/functions/read/getAvailable.ts b/packages/ensjs/src/functions/read/getAvailable.ts index 4ba968fb..ff9cd70f 100644 --- a/packages/ensjs/src/functions/read/getAvailable.ts +++ b/packages/ensjs/src/functions/read/getAvailable.ts @@ -1,6 +1,6 @@ import { Hex, decodeFunctionResult, encodeFunctionData, labelhash } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' import { availableSnippet } from '../../contracts/baseRegistrar' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { UnsupportedNameTypeError } from '../../errors/general' import { SimpleTransactionRequest } from '../../types' @@ -66,11 +66,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getAvailable } from '@ensdomains/ensjs' + * import { addEnsContracts, getAvailable } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getAvailable(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getContentHashRecord.ts b/packages/ensjs/src/functions/read/getContentHashRecord.ts index 4edf69af..11a7934a 100644 --- a/packages/ensjs/src/functions/read/getContentHashRecord.ts +++ b/packages/ensjs/src/functions/read/getContentHashRecord.ts @@ -1,5 +1,5 @@ import { Hex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest } from '../../types' import { GeneratedFunction, @@ -45,11 +45,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getContentHashRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, getContentHashRecord } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getContentHashRecord(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getExpiry.ts b/packages/ensjs/src/functions/read/getExpiry.ts index 549e2fd9..e0524939 100644 --- a/packages/ensjs/src/functions/read/getExpiry.ts +++ b/packages/ensjs/src/functions/read/getExpiry.ts @@ -1,9 +1,9 @@ import { Hex, decodeFunctionResult, encodeFunctionData, labelhash } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' import { gracePeriodSnippet, nameExpiresSnippet, } from '../../contracts/baseRegistrar' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { getCurrentBlockTimestampSnippet } from '../../contracts/multicall' import { getDataSnippet } from '../../contracts/nameWrapper' @@ -170,11 +170,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getExpiry } from '@ensdomains/ensjs' + * import { addEnsContracts, getExpiry } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getExpiry(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getName.ts b/packages/ensjs/src/functions/read/getName.ts index 55a6ce59..0e045a19 100644 --- a/packages/ensjs/src/functions/read/getName.ts +++ b/packages/ensjs/src/functions/read/getName.ts @@ -5,7 +5,7 @@ import { encodeFunctionData, toHex, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { reverseSnippet } from '../../contracts/universalResolver' import { SimpleTransactionRequest } from '../../types' @@ -76,11 +76,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getName } from '@ensdomains/ensjs' + * import { addEnsContracts, getName } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getName(client, { address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5' }) diff --git a/packages/ensjs/src/functions/read/getOwner.ts b/packages/ensjs/src/functions/read/getOwner.ts index 28a74ce2..6d9f4bc3 100644 --- a/packages/ensjs/src/functions/read/getOwner.ts +++ b/packages/ensjs/src/functions/read/getOwner.ts @@ -1,5 +1,5 @@ import { Address, Hex, decodeAbiParameters } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { SimpleTransactionRequest } from '../../types' import { EMPTY_ADDRESS } from '../../utils/consts' @@ -228,11 +228,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getOwner } from '@ensdomains/ensjs' + * import { addEnsContracts, getOwner } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getOwner(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getPrice.ts b/packages/ensjs/src/functions/read/getPrice.ts index ce80436d..32116ee8 100644 --- a/packages/ensjs/src/functions/read/getPrice.ts +++ b/packages/ensjs/src/functions/read/getPrice.ts @@ -1,6 +1,6 @@ import { Hex, decodeFunctionResult, encodeFunctionData } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' import { rentPriceSnippet as bulkRentPriceSnippet } from '../../contracts/bulkRenewal' +import { ClientWithEns } from '../../contracts/consts' import { rentPriceSnippet as controllerRentPriceSnippet } from '../../contracts/ethRegistrarController' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { UnsupportedNameTypeError } from '../../errors/general' @@ -123,11 +123,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getPrice } from '@ensdomains/ensjs' + * import { addEnsContracts, getPrice } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getPrice(client, { nameOrNames: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getRecords.ts b/packages/ensjs/src/functions/read/getRecords.ts index af3987dd..ddf16b64 100644 --- a/packages/ensjs/src/functions/read/getRecords.ts +++ b/packages/ensjs/src/functions/read/getRecords.ts @@ -8,7 +8,7 @@ import { stringToBytes, toHex, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { resolveArraySnippet } from '../../contracts/universalResolver' import { @@ -321,11 +321,10 @@ type BatchableFunctionObject = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getRecords } from '@ensdomains/ensjs' + * import { addEnsContracts, getRecords } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getRecords(client, { diff --git a/packages/ensjs/src/functions/read/getResolver.ts b/packages/ensjs/src/functions/read/getResolver.ts index 5b4d16d8..ee663386 100644 --- a/packages/ensjs/src/functions/read/getResolver.ts +++ b/packages/ensjs/src/functions/read/getResolver.ts @@ -5,7 +5,7 @@ import { encodeFunctionData, toHex, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { findResolverSnippet } from '../../contracts/universalResolver' import { SimpleTransactionRequest } from '../../types' @@ -63,11 +63,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getResolver } from '@ensdomains/ensjs' + * import { addEnsContracts, getResolver } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getResolver(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/read/getSupportedInterfaces.ts b/packages/ensjs/src/functions/read/getSupportedInterfaces.ts index 8ac3ffa3..ae3bcd5e 100644 --- a/packages/ensjs/src/functions/read/getSupportedInterfaces.ts +++ b/packages/ensjs/src/functions/read/getSupportedInterfaces.ts @@ -1,5 +1,5 @@ import { Address, Hex, encodeFunctionData } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { supportsInterfaceSnippet } from '../../contracts/erc165' import { SimpleTransactionRequest, diff --git a/packages/ensjs/src/functions/read/getTextRecord.ts b/packages/ensjs/src/functions/read/getTextRecord.ts index 853014dd..9c26c830 100644 --- a/packages/ensjs/src/functions/read/getTextRecord.ts +++ b/packages/ensjs/src/functions/read/getTextRecord.ts @@ -1,5 +1,5 @@ import { Hex } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest } from '../../types' import { GeneratedFunction, @@ -43,11 +43,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getTextRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, getTextRecord } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getTextRecord(client, { name: 'ens.eth', key: 'com.twitter' }) diff --git a/packages/ensjs/src/functions/read/getWrapperData.ts b/packages/ensjs/src/functions/read/getWrapperData.ts index 4ad3c084..99269f26 100644 --- a/packages/ensjs/src/functions/read/getWrapperData.ts +++ b/packages/ensjs/src/functions/read/getWrapperData.ts @@ -1,5 +1,5 @@ import { Address, Hex, decodeFunctionResult, encodeFunctionData } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { getDataSnippet } from '../../contracts/nameWrapper' import { DateWithValue, Prettify, SimpleTransactionRequest } from '../../types' @@ -85,11 +85,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getWrapperData } from '@ensdomains/ensjs' + * import { addEnsContracts, getWrapperData } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getWrapperData(client, { name: 'ilikelasagna.eth' }) diff --git a/packages/ensjs/src/functions/read/getWrapperName.ts b/packages/ensjs/src/functions/read/getWrapperName.ts index 87b7fada..deb876cc 100644 --- a/packages/ensjs/src/functions/read/getWrapperName.ts +++ b/packages/ensjs/src/functions/read/getWrapperName.ts @@ -1,5 +1,5 @@ import { Hex, decodeFunctionResult, encodeFunctionData, hexToBytes } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { namesSnippet } from '../../contracts/nameWrapper' import { SimpleTransactionRequest } from '../../types' @@ -55,11 +55,10 @@ type BatchableFunctionObject = GeneratedFunction * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getWrapperName } from '@ensdomains/ensjs' + * import { addEnsContracts, getWrapperName } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getWrapperName(client, { name: '[4ca938ec1b323ca71c4fb47a712abb68cce1cabf39ea4d6789e42fbc1f95459b].eth' }) diff --git a/packages/ensjs/src/functions/read/multicallWrapper.ts b/packages/ensjs/src/functions/read/multicallWrapper.ts index 20d75e98..47cb9d18 100644 --- a/packages/ensjs/src/functions/read/multicallWrapper.ts +++ b/packages/ensjs/src/functions/read/multicallWrapper.ts @@ -4,7 +4,7 @@ import { encodeFunctionData, offchainLookup, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { tryAggregateSnippet } from '../../contracts/multicall' import { diff --git a/packages/ensjs/src/functions/read/universalWrapper.ts b/packages/ensjs/src/functions/read/universalWrapper.ts index d93ed020..34c6afb0 100644 --- a/packages/ensjs/src/functions/read/universalWrapper.ts +++ b/packages/ensjs/src/functions/read/universalWrapper.ts @@ -7,7 +7,7 @@ import { toBytes, toHex, } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { resolveSnippet } from '../../contracts/universalResolver' import { SimpleTransactionRequest } from '../../types' diff --git a/packages/ensjs/src/functions/subgraph/client.ts b/packages/ensjs/src/functions/subgraph/client.ts index 2e65add2..cef7f245 100644 --- a/packages/ensjs/src/functions/subgraph/client.ts +++ b/packages/ensjs/src/functions/subgraph/client.ts @@ -3,7 +3,7 @@ import { GraphQLClient } from 'graphql-request' import { RequestMiddleware, Response } from 'graphql-request/dist/types' import { parse, print, visit } from 'graphql/language/index' import traverse from 'traverse' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { namehash } from '../../utils/normalise' const generateSelection = (selection: string): SelectionNode => ({ diff --git a/packages/ensjs/src/functions/subgraph/getDecodedName.ts b/packages/ensjs/src/functions/subgraph/getDecodedName.ts index d3d1bf35..4c6ebd16 100644 --- a/packages/ensjs/src/functions/subgraph/getDecodedName.ts +++ b/packages/ensjs/src/functions/subgraph/getDecodedName.ts @@ -1,5 +1,5 @@ import { gql } from 'graphql-request' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { checkIsDecrypted, decodeLabelhash, @@ -32,11 +32,10 @@ type SubgraphResult = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getDecodedName } from '@ensdomains/ensjs' + * import { addEnsContracts, getDecodedName } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getDecodedName(client, { name: '[5cee339e13375638553bdf5a6e36ba80fb9f6a4f0783680884d92b558aa471da].eth' }) diff --git a/packages/ensjs/src/functions/subgraph/getNameHistory.ts b/packages/ensjs/src/functions/subgraph/getNameHistory.ts index ab6602c9..ddd76b53 100644 --- a/packages/ensjs/src/functions/subgraph/getNameHistory.ts +++ b/packages/ensjs/src/functions/subgraph/getNameHistory.ts @@ -1,6 +1,6 @@ import { formatsByCoinType } from '@ensdomains/address-encoder' import { gql } from 'graphql-request' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { decodeContenthash } from '../../utils/contentHash' import { namehash } from '../../utils/normalise' import { createSubgraphClient } from './client' @@ -71,11 +71,10 @@ export type GetNameHistoryReturnType = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getNameHistory } from '@ensdomains/ensjs' + * import { addEnsContracts, getNameHistory } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getNameHistory(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts b/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts index ab7c8c91..7d1c8144 100644 --- a/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts +++ b/packages/ensjs/src/functions/subgraph/getNamesForAddress.ts @@ -1,6 +1,6 @@ import { gql } from 'graphql-request' import { Address } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { FilterKeyRequiredError, InvalidFilterKeyError, @@ -74,11 +74,10 @@ type SubgraphResult = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getNamesForAddress } from '@ensdomains/ensjs' + * import { addEnsContracts, getNamesForAddress } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getNamesForAddress(client, { address: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }) diff --git a/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts b/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts index 79d596bd..bcf0c2c7 100644 --- a/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts +++ b/packages/ensjs/src/functions/subgraph/getSubgraphRecords.ts @@ -1,6 +1,6 @@ import { gql } from 'graphql-request' import type { Address } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { DateWithValue } from '../../types' import { namehash } from '../../utils/normalise' import { createSubgraphClient } from './client' @@ -82,11 +82,10 @@ type CustomResolverSubgraphResult = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getSubgraphRecords } from '@ensdomains/ensjs' + * import { addEnsContracts, getSubgraphRecords } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getSubgraphRecords(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts b/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts index 1ab70df5..5e79875b 100644 --- a/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts +++ b/packages/ensjs/src/functions/subgraph/getSubgraphRegistrant.ts @@ -1,6 +1,6 @@ import { gql } from 'graphql-request' import { Address, getAddress, labelhash } from 'viem' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { UnsupportedNameTypeError } from '../../errors/general' import { getNameType } from '../../utils/getNameType' import { createSubgraphClient } from './client' @@ -39,11 +39,10 @@ type SubgraphResult = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getSubgraphRegistrant } from '@ensdomains/ensjs' + * import { addEnsContracts, getSubgraphRegistrant } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getSubgraphRegistrant(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/subgraph/getSubnames.ts b/packages/ensjs/src/functions/subgraph/getSubnames.ts index 0116e0d1..62ef61a1 100644 --- a/packages/ensjs/src/functions/subgraph/getSubnames.ts +++ b/packages/ensjs/src/functions/subgraph/getSubnames.ts @@ -1,5 +1,5 @@ import { gql } from 'graphql-request' -import { ClientWithEns } from '../../contracts/addContracts' +import { ClientWithEns } from '../../contracts/consts' import { InvalidOrderByError } from '../../errors/subgraph' import { GRACE_PERIOD_SECONDS } from '../../utils/consts' import { namehash } from '../../utils/normalise' @@ -48,11 +48,10 @@ type SubgraphResult = { * @example * import { createPublicClient, http } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, getSubnames } from '@ensdomains/ensjs' + * import { addEnsContracts, getSubnames } from '@ensdomains/ensjs' * - * const mainnetWithEns = addContracts([mainnet]) * const client = createPublicClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: http(), * }) * const result = await getSubnames(client, { name: 'ens.eth' }) diff --git a/packages/ensjs/src/functions/write/commitName.ts b/packages/ensjs/src/functions/write/commitName.ts index 3bbde9c7..00c10d8c 100644 --- a/packages/ensjs/src/functions/write/commitName.ts +++ b/packages/ensjs/src/functions/write/commitName.ts @@ -5,7 +5,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { commitSnippet } from '../../contracts/ethRegistrarController' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { UnsupportedNameTypeError } from '../../errors/general' @@ -72,17 +72,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link CommitNameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, commitName, randomSecret } from '@ensdomains/ensjs' + * import { addEnsContracts, commitName, randomSecret } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const secret = randomSecret() diff --git a/packages/ensjs/src/functions/write/createSubname.ts b/packages/ensjs/src/functions/write/createSubname.ts index 42c9f479..9c1ac15b 100644 --- a/packages/ensjs/src/functions/write/createSubname.ts +++ b/packages/ensjs/src/functions/write/createSubname.ts @@ -6,7 +6,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setSubnodeRecordSnippet as nameWrapperSetSubnodeRecordSnippet } from '../../contracts/nameWrapper' import { setSubnodeRecordSnippet as registrySetSubnodeRecordSnippet } from '../../contracts/registry' @@ -156,17 +156,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link CreateSubnameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, createSubname } from '@ensdomains/ensjs' + * import { addEnsContracts, createSubname } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await createSubname(wallet, { diff --git a/packages/ensjs/src/functions/write/deleteSubname.ts b/packages/ensjs/src/functions/write/deleteSubname.ts index f9981917..7c824eb7 100644 --- a/packages/ensjs/src/functions/write/deleteSubname.ts +++ b/packages/ensjs/src/functions/write/deleteSubname.ts @@ -5,7 +5,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setSubnodeRecordSnippet as nameWrapperSetSubnodeRecordSnippet, @@ -146,15 +146,10 @@ export const makeFunctionData = < * @returns Transaction hash. {@link DeleteSubnameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, deleteSubname } from '@ensdomains/ensjs' + * import { addEnsContracts, deleteSubname } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ * chain: mainnetWithEns, * transport: custom(window.ethereum), diff --git a/packages/ensjs/src/functions/write/registerName.ts b/packages/ensjs/src/functions/write/registerName.ts index d2a6d8f9..15206d64 100644 --- a/packages/ensjs/src/functions/write/registerName.ts +++ b/packages/ensjs/src/functions/write/registerName.ts @@ -5,7 +5,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { registerSnippet } from '../../contracts/ethRegistrarController' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { UnsupportedNameTypeError } from '../../errors/general' @@ -82,9 +82,9 @@ export const makeFunctionData = < * @example * import { createPublicClient, createWalletClient, http, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, commitName, randomSecret, getPrice, registerName } from '@ensdomains/ensjs' + * import { addEnsContracts, commitName, randomSecret, getPrice, registerName } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) + * const mainnetWithEns = addEnsContracts(mainnet) * const client = createPublicClient({ * chain: mainnetWithEns, * transport: http(), diff --git a/packages/ensjs/src/functions/write/renewNames.ts b/packages/ensjs/src/functions/write/renewNames.ts index 0b2a95c5..0eb3ff8a 100644 --- a/packages/ensjs/src/functions/write/renewNames.ts +++ b/packages/ensjs/src/functions/write/renewNames.ts @@ -5,8 +5,8 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' import { renewAllSnippet } from '../../contracts/bulkRenewal' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { renewSnippet } from '../../contracts/ethRegistrarController' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { UnsupportedNameTypeError } from '../../errors/general' @@ -99,9 +99,9 @@ export const makeFunctionData = < * @example * import { createPublicClient, createWalletClient, http, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, renewNames, getPrice } from '@ensdomains/ensjs' + * import { addEnsContracts, renewNames, getPrice } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) + * const mainnetWithEns = addEnsContracts(mainnet) * const client = createPublicClient({ * chain: mainnetWithEns, * transport: http(), diff --git a/packages/ensjs/src/functions/write/setAbiRecord.ts b/packages/ensjs/src/functions/write/setAbiRecord.ts index 40c21815..3d446598 100644 --- a/packages/ensjs/src/functions/write/setAbiRecord.ts +++ b/packages/ensjs/src/functions/write/setAbiRecord.ts @@ -5,7 +5,7 @@ import { SendTransactionParameters, Transport, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest, @@ -65,17 +65,12 @@ export const makeFunctionData = < * * @example * import abi from './abi.json' - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, encodeAbi, setAbiRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, encodeAbi, setAbiRecord } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * diff --git a/packages/ensjs/src/functions/write/setAddressRecord.ts b/packages/ensjs/src/functions/write/setAddressRecord.ts index 801515cb..1e602ba4 100644 --- a/packages/ensjs/src/functions/write/setAddressRecord.ts +++ b/packages/ensjs/src/functions/write/setAddressRecord.ts @@ -5,7 +5,7 @@ import { SendTransactionParameters, Transport, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest, @@ -58,17 +58,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetAddressRecordReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setAddressRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, setAddressRecord } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setAddressRecord(wallet, { diff --git a/packages/ensjs/src/functions/write/setChildFuses.ts b/packages/ensjs/src/functions/write/setChildFuses.ts index 2e6f6edc..75c3f962 100644 --- a/packages/ensjs/src/functions/write/setChildFuses.ts +++ b/packages/ensjs/src/functions/write/setChildFuses.ts @@ -6,7 +6,7 @@ import { encodeFunctionData, labelhash, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setChildFusesSnippet } from '../../contracts/nameWrapper' import { @@ -67,17 +67,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetChildFusesReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setChildFuses } from '@ensdomains/ensjs' + * import { addEnsContracts, setChildFuses } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setChildFuses(wallet, { diff --git a/packages/ensjs/src/functions/write/setContentHashRecord.ts b/packages/ensjs/src/functions/write/setContentHashRecord.ts index d68c534e..8cee1933 100644 --- a/packages/ensjs/src/functions/write/setContentHashRecord.ts +++ b/packages/ensjs/src/functions/write/setContentHashRecord.ts @@ -5,7 +5,7 @@ import { SendTransactionParameters, Transport, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest, @@ -56,17 +56,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetContentHashRecordReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setContentHashRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, setContentHashRecord } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setContentHashRecord(wallet, { diff --git a/packages/ensjs/src/functions/write/setFuses.ts b/packages/ensjs/src/functions/write/setFuses.ts index 92bca4d4..ab3133ac 100644 --- a/packages/ensjs/src/functions/write/setFuses.ts +++ b/packages/ensjs/src/functions/write/setFuses.ts @@ -5,7 +5,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setFusesSnippet } from '../../contracts/nameWrapper' import { @@ -61,17 +61,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetFusesReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setFuses } from '@ensdomains/ensjs' + * import { addEnsContracts, setFuses } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setFuses(wallet, { diff --git a/packages/ensjs/src/functions/write/setPrimaryName.ts b/packages/ensjs/src/functions/write/setPrimaryName.ts index ed0103a6..1a8009b6 100644 --- a/packages/ensjs/src/functions/write/setPrimaryName.ts +++ b/packages/ensjs/src/functions/write/setPrimaryName.ts @@ -7,7 +7,7 @@ import { encodeFunctionData, } from 'viem' import { parseAccount } from 'viem/utils' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setNameForAddrSnippet, @@ -109,17 +109,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetPrimaryNameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setPrimaryName } from '@ensdomains/ensjs' + * import { addEnsContracts, setPrimaryName } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setPrimaryName(wallet, { diff --git a/packages/ensjs/src/functions/write/setRecords.ts b/packages/ensjs/src/functions/write/setRecords.ts index f4b08f41..f941a266 100644 --- a/packages/ensjs/src/functions/write/setRecords.ts +++ b/packages/ensjs/src/functions/write/setRecords.ts @@ -6,7 +6,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { multicallSnippet } from '../../contracts/publicResolver' import { NoRecordsSpecifiedError } from '../../errors/read' import { @@ -74,17 +74,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetRecordsReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setRecords } from '@ensdomains/ensjs' + * import { addEnsContracts, setRecords } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setRecords(wallet, { diff --git a/packages/ensjs/src/functions/write/setResolver.ts b/packages/ensjs/src/functions/write/setResolver.ts index 139a458a..d07fff11 100644 --- a/packages/ensjs/src/functions/write/setResolver.ts +++ b/packages/ensjs/src/functions/write/setResolver.ts @@ -6,7 +6,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { setResolverSnippet } from '../../contracts/registry' import { @@ -68,17 +68,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetResolverReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setResolver } from '@ensdomains/ensjs' + * import { addEnsContracts, setResolver } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setResolver(wallet, { diff --git a/packages/ensjs/src/functions/write/setTextRecord.ts b/packages/ensjs/src/functions/write/setTextRecord.ts index fd6041a6..c5ef55ff 100644 --- a/packages/ensjs/src/functions/write/setTextRecord.ts +++ b/packages/ensjs/src/functions/write/setTextRecord.ts @@ -5,7 +5,7 @@ import { SendTransactionParameters, Transport, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { Prettify, SimpleTransactionRequest, @@ -58,17 +58,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link SetTextRecordReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, setTextRecord } from '@ensdomains/ensjs' + * import { addEnsContracts, setTextRecord } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await setTextRecord(wallet, { diff --git a/packages/ensjs/src/functions/write/transferName.ts b/packages/ensjs/src/functions/write/transferName.ts index 8c91d221..e418735d 100644 --- a/packages/ensjs/src/functions/write/transferName.ts +++ b/packages/ensjs/src/functions/write/transferName.ts @@ -8,8 +8,8 @@ import { labelhash, } from 'viem' import { parseAccount } from 'viem/utils' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' import { reclaimSnippet } from '../../contracts/baseRegistrar' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { safeTransferFromSnippet as erc1155SafeTransferFromSnippet } from '../../contracts/erc1155' import { safeTransferFromSnippet as erc721SafeTransferFromSnippet } from '../../contracts/erc721' import { getChainContractAddress } from '../../contracts/getChainContractAddress' @@ -203,17 +203,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link TransferNameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, transferName } from '@ensdomains/ensjs' + * import { addEnsContracts, transferName } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await transferName(wallet, { diff --git a/packages/ensjs/src/functions/write/unwrapName.ts b/packages/ensjs/src/functions/write/unwrapName.ts index fe929951..7e0ef9e1 100644 --- a/packages/ensjs/src/functions/write/unwrapName.ts +++ b/packages/ensjs/src/functions/write/unwrapName.ts @@ -6,7 +6,7 @@ import { Transport, encodeFunctionData, } from 'viem' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { unwrapEth2ldSnippet, unwrapSnippet } from '../../contracts/nameWrapper' import { @@ -122,17 +122,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link UnwrapNameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, unwrapName } from '@ensdomains/ensjs' + * import { addEnsContracts, unwrapName } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await unwrapName(wallet, { diff --git a/packages/ensjs/src/functions/write/wrapName.ts b/packages/ensjs/src/functions/write/wrapName.ts index aad5ade7..316bb213 100644 --- a/packages/ensjs/src/functions/write/wrapName.ts +++ b/packages/ensjs/src/functions/write/wrapName.ts @@ -10,7 +10,7 @@ import { toHex, } from 'viem' import { parseAccount } from 'viem/utils' -import { ChainWithEns, WalletWithEns } from '../../contracts/addContracts' +import { ChainWithEns, WalletWithEns } from '../../contracts/consts' import { safeTransferFromWithDataSnippet } from '../../contracts/erc721' import { getChainContractAddress } from '../../contracts/getChainContractAddress' import { wrapSnippet } from '../../contracts/nameWrapper' @@ -134,17 +134,12 @@ export const makeFunctionData = < * @returns Transaction hash. {@link WrapNameReturnType} * * @example - * import { createPublicClient, createWalletClient, http, custom } from 'viem' + * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' - * import { addContracts, wrapName } from '@ensdomains/ensjs' + * import { addEnsContracts, wrapName } from '@ensdomains/ensjs' * - * const [mainnetWithEns] = addContracts([mainnet]) - * const client = createPublicClient({ - * chain: mainnetWithEns, - * transport: http(), - * }) * const wallet = createWalletClient({ - * chain: mainnetWithEns, + * chain: addEnsContracts(mainnet), * transport: custom(window.ethereum), * }) * const hash = await wrapName(wallet, { diff --git a/packages/ensjs/src/types.ts b/packages/ensjs/src/types.ts index 714411ec..d0bc0ff7 100644 --- a/packages/ensjs/src/types.ts +++ b/packages/ensjs/src/types.ts @@ -1,9 +1,10 @@ import type { Account, + Client, SendTransactionParameters, TransactionRequest, } from 'viem' -import { ChainWithEns } from './contracts/addContracts' +import { ChainWithEns } from './contracts/consts' export type Prettify = { [K in keyof T]: T[K] @@ -17,18 +18,25 @@ export type TransactionRequestWithPassthrough = SimpleTransactionRequest & { passthrough?: any } -export type WriteTransactionParameters< - TChain extends ChainWithEns, - TAccount extends Account | undefined, - TChainOverride extends ChainWithEns | undefined = ChainWithEns, -> = Pick< - SendTransactionParameters, +export type Extended = { [K in keyof Client]?: undefined } & { + [key: string]: unknown +} + +type AllowedWriteParameters = | 'gas' | 'gasPrice' | 'maxFeePerGas' | 'maxPriorityFeePerGas' | 'nonce' | 'account' + +export type WriteTransactionParameters< + TChain extends ChainWithEns, + TAccount extends Account | undefined, + TChainOverride extends ChainWithEns | undefined = ChainWithEns, +> = Pick< + SendTransactionParameters, + AllowedWriteParameters > export type DateWithValue = { diff --git a/packages/ensjs/src/utils/ownerFromContract.test.ts b/packages/ensjs/src/utils/ownerFromContract.test.ts index 8c6dcc09..125a4570 100644 --- a/packages/ensjs/src/utils/ownerFromContract.test.ts +++ b/packages/ensjs/src/utils/ownerFromContract.test.ts @@ -1,4 +1,3 @@ -import { getChainContractAddress } from '../contracts' import { publicClient } from '../tests/addTestContracts' import { namehash } from './normalise' import { ownerFromContract } from './ownerFromContract' @@ -13,10 +12,7 @@ it('uses nameWrapper contract when contract is nameWrapper', () => { .toMatchInlineSnapshot(` { "data": "0x6352211eeb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1", - "to": "${getChainContractAddress({ - client: publicClient, - contract: 'ensNameWrapper', - })}", + "to": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E", } `) }) @@ -25,10 +21,7 @@ it('uses registry contract when contract is registry', () => { .toMatchInlineSnapshot(` { "data": "0x02571be3eb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1", - "to": "${getChainContractAddress({ - client: publicClient, - contract: 'ensRegistry', - })}", + "to": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", } `) }) @@ -42,10 +35,7 @@ it('uses registrar contract when contract is registrar', () => { ).toMatchInlineSnapshot(` { "data": "0x6352211e9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658", - "to": "${getChainContractAddress({ - client: publicClient, - contract: 'ensBaseRegistrarImplementation', - })}", + "to": "0x4A679253410272dd5232B3Ff7cF5dbB88f295319", } `) }) diff --git a/packages/ensjs/src/utils/ownerFromContract.ts b/packages/ensjs/src/utils/ownerFromContract.ts index b071522d..f0207002 100644 --- a/packages/ensjs/src/utils/ownerFromContract.ts +++ b/packages/ensjs/src/utils/ownerFromContract.ts @@ -1,5 +1,5 @@ import { Hex, encodeFunctionData, labelhash } from 'viem' -import { ClientWithEns } from '../contracts/addContracts' +import { ClientWithEns } from '../contracts/consts' import { ownerOfSnippet } from '../contracts/erc721' import { getChainContractAddress } from '../contracts/getChainContractAddress' import { ownerSnippet } from '../contracts/registry' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d045c244..59124079 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,7 +16,7 @@ importers: eslint-config-prettier: ^8.5.0 eslint-plugin-import: ^2.26.0 eslint-plugin-prettier: ^4.0.0 - prettier: ^2.6.0 + prettier: ^2.8.8 ts-node: ^10.7.0 typescript: ^5.0.4 devDependencies: @@ -28,8 +28,8 @@ importers: eslint-config-airbnb-typescript: 16.2.0_2p33354vws2q7hfbt5tyy4qhyy eslint-config-prettier: 8.5.0_eslint@8.21.0 eslint-plugin-import: 2.26.0_qfqnhzzittf54udqwes54xx65q - eslint-plugin-prettier: 4.2.1_h62lvancfh4b7r6zn2dgodrh5e - prettier: 2.7.1 + eslint-plugin-prettier: 4.2.1_wd2zc6i5zgwlkgicsslt4azlqi + prettier: 2.8.8 ts-node: 10.9.1_typescript@5.0.4 typescript: 5.0.4 dependenciesMeta: @@ -113,7 +113,7 @@ importers: ts-jest: ^29.1.0 ts-node: ^10.7.0 typescript: ^5.0.4 - viem: ^0.3.24 + viem: ^1.2.9 wait-on: ^6.0.1 dependencies: '@adraffy/ens-normalize': 1.9.0 @@ -155,7 +155,7 @@ importers: ts-jest: 29.1.0_k4loywzeyoudxba33oezutz7em ts-node: 10.9.1_k7iguhqbtoao35i6waebqvypgi typescript: 5.0.4 - viem: 0.3.24_typescript@5.0.4 + viem: 1.2.9_typescript@5.0.4 wait-on: 6.0.1 packages: @@ -2417,10 +2417,10 @@ packages: resolution: {integrity: sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==} dev: true - /@wagmi/chains/0.2.16_typescript@5.0.4: - resolution: {integrity: sha512-rkWaI2PxCnbD8G07ZZff5QXftnSkYL0h5f4DkHCG3fGYYr/ZDvmCL4bMae7j7A9sAif1csPPBmbCzHp3R5ogCQ==} + /@wagmi/chains/1.2.0_typescript@5.0.4: + resolution: {integrity: sha512-dmDRipsE54JfyudOBkuhEexqQWcrZqxn/qiujG8SBzMh/az/AH5xlJSA+j1CPWTx9+QofSMF3B7A4gb6XRmSaQ==} peerDependencies: - typescript: '>=4.9.4' + typescript: '>=5.0.4' peerDependenciesMeta: typescript: optional: true @@ -2446,8 +2446,8 @@ packages: typescript: 5.0.4 dev: false - /abitype/0.8.2_typescript@5.0.4: - resolution: {integrity: sha512-B1ViNMGpfx/qjVQi0RTc2HEFHuR9uoCoTEkwELT5Y7pBPtBbctYijz9BK6+Kd0hQ3S70FhYTO2dWWk0QNUEXMA==} + /abitype/0.8.11_typescript@5.0.4: + resolution: {integrity: sha512-bM4v2dKvX08sZ9IU38IN5BKmN+ZkOSd2oI4a9f0ejHYZQYV6cDr7j+d95ga0z2XHG36Y4jzoG5Z7qDqxp7fi/A==} peerDependencies: typescript: '>=5.0.4' zod: ^3 >=3.19.1 @@ -4461,7 +4461,7 @@ packages: - typescript dev: true - /eslint-plugin-prettier/4.2.1_h62lvancfh4b7r6zn2dgodrh5e: + /eslint-plugin-prettier/4.2.1_wd2zc6i5zgwlkgicsslt4azlqi: resolution: {integrity: sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==} engines: {node: '>=12.0.0'} peerDependencies: @@ -4474,7 +4474,7 @@ packages: dependencies: eslint: 8.21.0 eslint-config-prettier: 8.5.0_eslint@8.21.0 - prettier: 2.7.1 + prettier: 2.8.8 prettier-linter-helpers: 1.0.0 dev: true @@ -7921,8 +7921,8 @@ packages: fast-diff: 1.2.0 dev: true - /prettier/2.7.1: - resolution: {integrity: sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==} + /prettier/2.8.8: + resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} hasBin: true dev: true @@ -9355,21 +9355,26 @@ packages: extsprintf: 1.3.0 dev: true - /viem/0.3.24_typescript@5.0.4: - resolution: {integrity: sha512-Oa2FgJ4mswl1I6nPPnyBnt+9+8w4/xcw4XjB1q115g9JJOqX8Ic9nq4Z31lDAonjtCca+K7u1M30t1lFXafqFg==} + /viem/1.2.9_typescript@5.0.4: + resolution: {integrity: sha512-EnEbTuAAHv43unUgMISdQXbD9mrhZLvOdmf6eRGbDFl+XwP/PEzZAT79RaWAuDPnLXGMP1gBCJF++NFjSMukUw==} + peerDependencies: + typescript: '>=5.0.4' + peerDependenciesMeta: + typescript: + optional: true dependencies: '@adraffy/ens-normalize': 1.9.0 '@noble/curves': 1.0.0 '@noble/hashes': 1.3.0 '@scure/bip32': 1.3.0 '@scure/bip39': 1.2.0 - '@wagmi/chains': 0.2.16_typescript@5.0.4 - abitype: 0.8.2_typescript@5.0.4 + '@wagmi/chains': 1.2.0_typescript@5.0.4 + abitype: 0.8.11_typescript@5.0.4 isomorphic-ws: 5.0.0_ws@8.12.0 + typescript: 5.0.4 ws: 8.12.0 transitivePeerDependencies: - bufferutil - - typescript - utf-8-validate - zod dev: true