Skip to content

Commit

Permalink
feat: viem v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Feb 12, 2024
1 parent 8d0f501 commit 554f118
Show file tree
Hide file tree
Showing 32 changed files with 280 additions and 247 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.8.8",
"ts-node": "^10.7.0",
"typescript": "^5.1.6"
"typescript": "^5.3.2"
},
"resolutions": {
"@nomiclabs/hardhat-ethers": "npm:[email protected]"
Expand Down
5 changes: 5 additions & 0 deletions packages/ensjs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"leadingUnderscore": "allowSingleOrDouble",
"trailingUnderscore": "allowSingleOrDouble"
},
{
"selector": "objectLiteralProperty",
"filter": { "regex": "\\d+", "match": true },
"format": null
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"],
Expand Down
12 changes: 6 additions & 6 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@
"@ensdomains/address-encoder": "1.0.0",
"@ensdomains/content-hash": "3.1.0-rc.1",
"@ensdomains/dnsprovejs": "^0.5.1",
"abitype": "^0.8.0",
"abitype": "^1.0.0",
"dns-packet": "^5.3.1",
"graphql": "^16.3.0",
"graphql-request": "6.1.0",
"pako": "^2.1.0",
"traverse": "^0.6.6"
"traverse": "^0.6.8"
},
"devDependencies": {
"@ensdomains/buffer": "^0.0.13",
Expand All @@ -123,7 +123,7 @@
"@types/jest": "^27.4.1",
"@types/node": "^20.3.3",
"@types/pako": "^2.0.0",
"@types/traverse": "^0.6.32",
"@types/traverse": "^0.6.36",
"cbor": "^8.1.0",
"dotenv": "^16.0.0",
"esbuild": "^0.15.6",
Expand All @@ -143,11 +143,11 @@
"ts-node": "^10.9.2",
"typedoc": "^0.24.8",
"typedoc-plugin-markdown": "^4.0.0-next.16",
"typescript": "^5.1.6",
"viem": "^1.16.4",
"typescript": "5.3.2",
"viem": "^2.5.0",
"wait-on": "^6.0.1"
},
"peerDependencies": {
"viem": "^1.16.4"
"viem": "^2.5.0"
}
}
1 change: 1 addition & 0 deletions packages/ensjs/src/clients/decorators/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export type EnsPublicActions = {
name,
gatewayUrls,
strict,
supportedContentTypes,
}: GetAbiRecordParameters) => Promise<GetAbiRecordReturnType>
/**
* Gets an address record for a name and specified coin
Expand Down
14 changes: 7 additions & 7 deletions packages/ensjs/src/contracts/addEnsContracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Chain } from 'viem'
import { NoChainError, UnsupportedNetworkError } from '../errors/contracts.js'
import { NoChainError, UnsupportedChainError } from '../errors/contracts.js'
import {
addresses,
subgraphs,
Expand All @@ -24,19 +24,19 @@ import {
*/
export const addEnsContracts = <const TChain extends Chain>(chain: TChain) => {
if (!chain) throw new NoChainError()
if (!supportedChains.includes(chain.network as SupportedChain))
throw new UnsupportedNetworkError({
network: chain.network,
supportedNetworks: supportedChains,
if (!supportedChains.includes(chain.id as SupportedChain))
throw new UnsupportedChainError({
chainId: chain.id,
supportedChains,
})
return {
...chain,
contracts: {
...chain.contracts,
...addresses[chain.network as SupportedChain],
...addresses[chain.id as SupportedChain],
},
subgraphs: {
...subgraphs[chain.network as SupportedChain],
...subgraphs[chain.id as SupportedChain],
},
} as unknown as CheckedChainWithEns<TChain>
}
65 changes: 30 additions & 35 deletions packages/ensjs/src/contracts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ type ChainContract = {
blockCreated?: number
}

export const supportedChains = [
'homestead',
'goerli',
'sepolia',
'holesky',
] as const
export const supportedChains = [1, 5, 17000, 11155111] as const
export const supportedContracts = [
'ensBaseRegistrarImplementation',
'ensBulkRenewal',
Expand All @@ -36,7 +31,7 @@ export type SupportedChain = (typeof supportedChains)[number]
export type SupportedContract = (typeof supportedContracts)[number]

export const addresses = {
homestead: {
1: {
ensBaseRegistrarImplementation: {
address: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
},
Expand Down Expand Up @@ -68,7 +63,7 @@ export const addresses = {
address: '0x8cab227b1162f03b8338331adaad7aadc83b895e',
},
},
goerli: {
5: {
ensBaseRegistrarImplementation: {
address: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
},
Expand Down Expand Up @@ -100,68 +95,68 @@ export const addresses = {
address: '0xfc4AC75C46C914aF5892d6d3eFFcebD7917293F1',
},
},
sepolia: {
17000: {
ensBaseRegistrarImplementation: {
address: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
},
ensBulkRenewal: {
address: '0x4EF77b90762Eddb33C8Eba5B5a19558DaE53D7a1',
address: '0xbc4cfB363F948E64Cd73Da6438F64CB37E2e33d1',
},
ensDnsRegistrar: {
address: '0x5a07C75Ae469Bf3ee2657B588e8E6ABAC6741b4f',
address: '0x458d278AEd4cE82BAeC384170f39198b01B8351c',
},
ensDnssecImpl: {
address: '0xe62E4b6cE018Ad6e916fcC24545e20a33b9d8653',
address: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5',
},
ensEthRegistrarController: {
address: '0xFED6a969AaA60E4961FCD3EBF1A2e8913ac65B72',
address: '0x179Be112b24Ad4cFC392eF8924DfA08C20Ad8583',
},
ensNameWrapper: {
address: '0x0635513f179D50A207757E05759CbD106d7dFcE8',
address: '0xab50971078225D365994dc1Edcb9b7FD72Bb4862',
},
ensPublicResolver: {
address: '0x8FADE66B79cC9f707aB26799354482EB93a5B7dD',
address: '0x9010A27463717360cAD99CEA8bD39b8705CCA238',
},
ensRegistry: {
address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
},
ensReverseRegistrar: {
address: '0xA0a1AbcDAe1a2a4A2EF8e9113Ff0e02DD81DC0C6',
address: '0x132AC0B116a73add4225029D1951A9A707Ef673f',
},
ensUniversalResolver: {
address: '0xBaBC7678D7A63104f1658c11D6AE9A21cdA09725',
address: '0x2548a7E09deE955c4d97688dcB6C5b24085725f5',
},
},
holesky: {
11155111: {
ensBaseRegistrarImplementation: {
address: '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85',
},
ensBulkRenewal: {
address: '0xbc4cfB363F948E64Cd73Da6438F64CB37E2e33d1',
address: '0x4EF77b90762Eddb33C8Eba5B5a19558DaE53D7a1',
},
ensDnsRegistrar: {
address: '0x458d278AEd4cE82BAeC384170f39198b01B8351c',
address: '0x5a07C75Ae469Bf3ee2657B588e8E6ABAC6741b4f',
},
ensDnssecImpl: {
address: '0x283af0b28c62c092c9727f1ee09c02ca627eb7f5',
address: '0xe62E4b6cE018Ad6e916fcC24545e20a33b9d8653',
},
ensEthRegistrarController: {
address: '0x179Be112b24Ad4cFC392eF8924DfA08C20Ad8583',
address: '0xFED6a969AaA60E4961FCD3EBF1A2e8913ac65B72',
},
ensNameWrapper: {
address: '0xab50971078225D365994dc1Edcb9b7FD72Bb4862',
address: '0x0635513f179D50A207757E05759CbD106d7dFcE8',
},
ensPublicResolver: {
address: '0x9010A27463717360cAD99CEA8bD39b8705CCA238',
address: '0x8FADE66B79cC9f707aB26799354482EB93a5B7dD',
},
ensRegistry: {
address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
},
ensReverseRegistrar: {
address: '0x132AC0B116a73add4225029D1951A9A707Ef673f',
address: '0xA0a1AbcDAe1a2a4A2EF8e9113Ff0e02DD81DC0C6',
},
ensUniversalResolver: {
address: '0x2548a7E09deE955c4d97688dcB6C5b24085725f5',
address: '0xBaBC7678D7A63104f1658c11D6AE9A21cdA09725',
},
},
} as const satisfies Record<
Expand All @@ -176,24 +171,24 @@ type Subgraphs = {
}

export const subgraphs = {
homestead: {
1: {
ens: {
url: 'https://api.thegraph.com/subgraphs/name/ensdomains/ens',
},
},
goerli: {
5: {
ens: {
url: 'https://api.thegraph.com/subgraphs/name/ensdomains/ensgoerli',
},
},
sepolia: {
17000: {
ens: {
url: 'https://api.studio.thegraph.com/query/49574/enssepolia/version/latest',
url: 'https://api.studio.thegraph.com/query/49574/ensholesky/version/latest',
},
},
holesky: {
11155111: {
ens: {
url: 'https://api.studio.thegraph.com/query/49574/ensholesky/version/latest',
url: 'https://api.studio.thegraph.com/query/49574/enssepolia/version/latest',
},
},
} as const satisfies Record<SupportedChain, Subgraphs>
Expand Down Expand Up @@ -231,11 +226,11 @@ export type ChainWithBaseContracts = Assign<
>

export type CheckedChainWithEns<TChain extends Chain> =
TChain['network'] extends SupportedChain
TChain['id'] extends SupportedChain
? TChain['contracts'] extends BaseChainContracts
? TChain & {
contracts: Prettify<(typeof addresses)[TChain['network']]>
subgraphs: (typeof subgraphs)[TChain['network']]
contracts: Prettify<(typeof addresses)[TChain['id']]>
subgraphs: (typeof subgraphs)[TChain['id']]
}
: never
: never
Expand Down
12 changes: 12 additions & 0 deletions packages/ensjs/src/contracts/universalResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ const universalResolverReverse = {
export const universalResolverReverseSnippet = [
...universalResolverErrors,
universalResolverReverse,
] as const

export const universalResolverReverseWithGatewaysSnippet = [
...universalResolverErrors,
{
...universalResolverReverse,
inputs: [
Expand Down Expand Up @@ -108,6 +112,10 @@ const universalResolverResolve = {
export const universalResolverResolveSnippet = [
...universalResolverErrors,
universalResolverResolve,
] as const

export const universalResolverResolveWithGatewaysSnippet = [
...universalResolverErrors,
{
...universalResolverResolve,
inputs: [
Expand Down Expand Up @@ -159,6 +167,10 @@ const universalResolverResolveArray = {
export const universalResolverResolveArraySnippet = [
...universalResolverErrors,
universalResolverResolveArray,
] as const

export const universalResolverResolveArrayWithGatewaysSnippet = [
...universalResolverErrors,
{
...universalResolverResolveArray,
inputs: [
Expand Down
24 changes: 12 additions & 12 deletions packages/ensjs/src/errors/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { BaseError } from './base.js'

export class UnsupportedNetworkError extends BaseError {
network: string
export class UnsupportedChainError extends BaseError {
chainId: number

supportedNetworks: readonly string[]
supportedChains: readonly number[]

override name = 'UnsupportedNetworkError'
override name = 'UnsupportedChainError'

constructor({
network,
supportedNetworks,
chainId,
supportedChains,
details,
}: {
network: string
supportedNetworks: readonly string[]
chainId: number
supportedChains: readonly number[]
details?: string
}) {
super(`Unsupported network: ${network}`, {
metaMessages: [`- Supported networks: ${supportedNetworks.join(', ')}`],
super(`Unsupported chain: ${chainId}`, {
metaMessages: [`- Supported chains: ${supportedChains.join(', ')}`],
details,
})
this.network = network
this.supportedNetworks = supportedNetworks
this.chainId = chainId
this.supportedChains = supportedChains
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getAbi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ it('propagates error when strict is true', async () => {
Params: (uint256, bytes)
Data: 0x1234 (2 bytes)
Version: viem@1.16.3"
Version: viem@2.5.0"
`)
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getAddr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ it('propagates error when strict is true', async () => {
Params: (address)
Data: 0x1234 (2 bytes)
Version: viem@1.16.3"
Version: viem@2.5.0"
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ it('propagates error when strict is true', async () => {
Params: (bytes)
Data: 0x1234 (2 bytes)
Version: viem@1.16.3"
Version: viem@2.5.0"
`)
})
2 changes: 1 addition & 1 deletion packages/ensjs/src/functions/public/_getText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ it('propagates error when strict is true', async () => {
Params: (string)
Data: 0x1234 (2 bytes)
Version: viem@1.16.3"
Version: viem@2.5.0"
`)
})
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/public/getAbiRecord.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RawContractError } from 'viem'
import type { ClientWithEns } from '../../contracts/consts.js'
import { publicClient } from '../../test/addTestContracts.js'
import getAbiRecord from './getAbiRecord.js'
import { generateSupportedContentTypes } from '../../utils/generateSupportedContentTypes.js'
import getAbiRecord from './getAbiRecord.js'

const dummyABI = [
{
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('getAbiRecord()', () => {
function: resolve(bytes name, bytes data)
args: (0x, 0x)
Version: viem@1.16.3"
Version: viem@2.5.0"
`)
})
})
Loading

0 comments on commit 554f118

Please sign in to comment.