viem 1.2.14 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/cjs/actions/ens/getEnsAddress.js +4 -7
  2. package/dist/cjs/actions/ens/getEnsAddress.js.map +1 -1
  3. package/dist/cjs/actions/ens/getEnsName.js +6 -20
  4. package/dist/cjs/actions/ens/getEnsName.js.map +1 -1
  5. package/dist/cjs/actions/ens/getEnsText.js +31 -23
  6. package/dist/cjs/actions/ens/getEnsText.js.map +1 -1
  7. package/dist/cjs/chains/index.js +5 -2
  8. package/dist/cjs/chains/index.js.map +1 -1
  9. package/dist/cjs/constants/abis.js +30 -2
  10. package/dist/cjs/constants/abis.js.map +1 -1
  11. package/dist/cjs/errors/version.js +1 -1
  12. package/dist/cjs/utils/ens/errors.js +24 -0
  13. package/dist/cjs/utils/ens/errors.js.map +1 -0
  14. package/dist/esm/actions/ens/getEnsAddress.js +5 -8
  15. package/dist/esm/actions/ens/getEnsAddress.js.map +1 -1
  16. package/dist/esm/actions/ens/getEnsName.js +6 -21
  17. package/dist/esm/actions/ens/getEnsName.js.map +1 -1
  18. package/dist/esm/actions/ens/getEnsText.js +32 -24
  19. package/dist/esm/actions/ens/getEnsText.js.map +1 -1
  20. package/dist/esm/chains/index.js +3 -0
  21. package/dist/esm/chains/index.js.map +1 -1
  22. package/dist/esm/constants/abis.js +29 -1
  23. package/dist/esm/constants/abis.js.map +1 -1
  24. package/dist/esm/errors/version.js +1 -1
  25. package/dist/esm/utils/ens/errors.js +25 -0
  26. package/dist/esm/utils/ens/errors.js.map +1 -0
  27. package/dist/types/actions/ens/getEnsAddress.d.ts.map +1 -1
  28. package/dist/types/actions/ens/getEnsName.d.ts.map +1 -1
  29. package/dist/types/actions/ens/getEnsText.d.ts.map +1 -1
  30. package/dist/types/chains/index.d.ts +160 -37
  31. package/dist/types/chains/index.d.ts.map +1 -1
  32. package/dist/types/constants/abis.d.ts +39 -1
  33. package/dist/types/constants/abis.d.ts.map +1 -1
  34. package/dist/types/errors/version.d.ts +1 -1
  35. package/dist/types/utils/ens/errors.d.ts +2 -0
  36. package/dist/types/utils/ens/errors.d.ts.map +1 -0
  37. package/package.json +2 -2
  38. package/src/actions/ens/getEnsAddress.ts +4 -13
  39. package/src/actions/ens/getEnsName.ts +6 -27
  40. package/src/actions/ens/getEnsText.ts +32 -23
  41. package/src/chains/index.ts +3 -0
  42. package/src/constants/abis.ts +31 -1
  43. package/src/errors/version.ts +1 -1
  44. package/src/utils/ens/errors.ts +27 -0
@@ -2,15 +2,12 @@ import type { Address } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
- import { panicReasons } from '../../constants/solidity.js'
6
- import {
7
- ContractFunctionExecutionError,
8
- type ContractFunctionRevertedError,
9
- } from '../../errors/contract.js'
5
+ import { universalResolverReverseAbi } from '../../constants/abis.js'
10
6
  import type { Chain } from '../../types/chain.js'
11
7
  import type { Prettify } from '../../types/utils.js'
12
8
  import { getChainContractAddress } from '../../utils/chain.js'
13
9
  import { toHex } from '../../utils/encoding/toHex.js'
10
+ import { isNullUniversalResolverError } from '../../utils/ens/errors.js'
14
11
  import { packetToBytes } from '../../utils/ens/packetToBytes.js'
15
12
  import {
16
13
  type ReadContractParameters,
@@ -81,33 +78,15 @@ export async function getEnsName<TChain extends Chain | undefined>(
81
78
  try {
82
79
  const res = await readContract(client, {
83
80
  address: universalResolverAddress,
84
- abi: [
85
- {
86
- name: 'reverse',
87
- type: 'function',
88
- stateMutability: 'view',
89
- inputs: [{ type: 'bytes', name: 'reverseName' }],
90
- outputs: [
91
- { type: 'string', name: 'resolvedName' },
92
- { type: 'address', name: 'resolvedAddress' },
93
- { type: 'address', name: 'reverseResolver' },
94
- { type: 'address', name: 'resolver' },
95
- ],
96
- },
97
- ],
81
+ abi: universalResolverReverseAbi,
98
82
  functionName: 'reverse',
99
83
  args: [toHex(packetToBytes(reverseNode))],
100
84
  blockNumber,
101
85
  blockTag,
102
86
  })
103
87
  return res[0]
104
- } catch (error) {
105
- if (
106
- error instanceof ContractFunctionExecutionError &&
107
- (error.cause as ContractFunctionRevertedError).reason === panicReasons[50]
108
- )
109
- // No primary name set for address.
110
- return null
111
- throw error
88
+ } catch (err) {
89
+ if (isNullUniversalResolverError(err, 'reverse')) return null
90
+ throw err
112
91
  }
113
92
  }
@@ -2,13 +2,17 @@ import type { Address } from 'abitype'
2
2
 
3
3
  import type { Client } from '../../clients/createClient.js'
4
4
  import type { Transport } from '../../clients/transports/createTransport.js'
5
- import { textResolverAbi, universalResolverAbi } from '../../constants/abis.js'
5
+ import {
6
+ textResolverAbi,
7
+ universalResolverResolveAbi,
8
+ } from '../../constants/abis.js'
6
9
  import type { Chain } from '../../types/chain.js'
7
10
  import type { Prettify } from '../../types/utils.js'
8
11
  import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js'
9
12
  import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js'
10
13
  import { getChainContractAddress } from '../../utils/chain.js'
11
14
  import { toHex } from '../../utils/encoding/toHex.js'
15
+ import { isNullUniversalResolverError } from '../../utils/ens/errors.js'
12
16
  import { namehash } from '../../utils/ens/namehash.js'
13
17
  import { packetToBytes } from '../../utils/ens/packetToBytes.js'
14
18
  import {
@@ -82,29 +86,34 @@ export async function getEnsText<TChain extends Chain | undefined>(
82
86
  })
83
87
  }
84
88
 
85
- const res = await readContract(client, {
86
- address: universalResolverAddress,
87
- abi: universalResolverAbi,
88
- functionName: 'resolve',
89
- args: [
90
- toHex(packetToBytes(name)),
91
- encodeFunctionData({
92
- abi: textResolverAbi,
93
- functionName: 'text',
94
- args: [namehash(name), key],
95
- }),
96
- ],
97
- blockNumber,
98
- blockTag,
99
- })
89
+ try {
90
+ const res = await readContract(client, {
91
+ address: universalResolverAddress,
92
+ abi: universalResolverResolveAbi,
93
+ functionName: 'resolve',
94
+ args: [
95
+ toHex(packetToBytes(name)),
96
+ encodeFunctionData({
97
+ abi: textResolverAbi,
98
+ functionName: 'text',
99
+ args: [namehash(name), key],
100
+ }),
101
+ ],
102
+ blockNumber,
103
+ blockTag,
104
+ })
100
105
 
101
- if (res[0] === '0x') return null
106
+ if (res[0] === '0x') return null
102
107
 
103
- const record = decodeFunctionResult({
104
- abi: textResolverAbi,
105
- functionName: 'text',
106
- data: res[0],
107
- })
108
+ const record = decodeFunctionResult({
109
+ abi: textResolverAbi,
110
+ functionName: 'text',
111
+ data: res[0],
112
+ })
108
113
 
109
- return record === '' ? null : record
114
+ return record === '' ? null : record
115
+ } catch (err) {
116
+ if (isNullUniversalResolverError(err, 'resolve')) return null
117
+ throw err
118
+ }
110
119
  }
@@ -11,6 +11,7 @@ export const aurora = /*#__PURE__*/ defineChain(chains.aurora)
11
11
  export const auroraTestnet = /*#__PURE__*/ defineChain(chains.auroraTestnet)
12
12
  export const avalanche = /*#__PURE__*/ defineChain(chains.avalanche)
13
13
  export const avalancheFuji = /*#__PURE__*/ defineChain(chains.avalancheFuji)
14
+ export const base = /*#__PURE__*/ defineChain(chains.base)
14
15
  export const baseGoerli = /*#__PURE__*/ defineChain(chains.baseGoerli)
15
16
  export const boba = /*#__PURE__*/ defineChain(chains.boba)
16
17
  export const bronos = /*#__PURE__*/ defineChain(chains.bronos)
@@ -63,6 +64,8 @@ export const localhost = /*#__PURE__*/ defineChain(chains.localhost)
63
64
  export const mainnet = /*#__PURE__*/ defineChain(chains.mainnet)
64
65
  export const metis = /*#__PURE__*/ defineChain(chains.metis)
65
66
  export const metisGoerli = /*#__PURE__*/ defineChain(chains.metisGoerli)
67
+ export const mev = /*#__PURE__*/ defineChain(chains.mev)
68
+ export const mevTestnet = /*#__PURE__*/ defineChain(chains.mevTestnet)
66
69
  export const moonbaseAlpha = /*#__PURE__*/ defineChain(chains.moonbaseAlpha)
67
70
  export const moonbeam = /*#__PURE__*/ defineChain(chains.moonbeam)
68
71
  export const moonriver = /*#__PURE__*/ defineChain(chains.moonriver)
@@ -43,7 +43,21 @@ export const multicall3Abi = [
43
43
  },
44
44
  ] as const
45
45
 
46
- export const universalResolverAbi = [
46
+ const universalResolverErrors = [
47
+ {
48
+ inputs: [],
49
+ name: 'ResolverNotFound',
50
+ type: 'error',
51
+ },
52
+ {
53
+ inputs: [],
54
+ name: 'ResolverWildcardNotSupported',
55
+ type: 'error',
56
+ },
57
+ ] as const
58
+
59
+ export const universalResolverResolveAbi = [
60
+ ...universalResolverErrors,
47
61
  {
48
62
  name: 'resolve',
49
63
  type: 'function',
@@ -59,6 +73,22 @@ export const universalResolverAbi = [
59
73
  },
60
74
  ] as const
61
75
 
76
+ export const universalResolverReverseAbi = [
77
+ ...universalResolverErrors,
78
+ {
79
+ name: 'reverse',
80
+ type: 'function',
81
+ stateMutability: 'view',
82
+ inputs: [{ type: 'bytes', name: 'reverseName' }],
83
+ outputs: [
84
+ { type: 'string', name: 'resolvedName' },
85
+ { type: 'address', name: 'resolvedAddress' },
86
+ { type: 'address', name: 'reverseResolver' },
87
+ { type: 'address', name: 'resolver' },
88
+ ],
89
+ },
90
+ ] as const
91
+
62
92
  export const textResolverAbi = [
63
93
  {
64
94
  name: 'text',
@@ -1 +1 @@
1
- export const version = '1.2.14'
1
+ export const version = '1.2.15'
@@ -0,0 +1,27 @@
1
+ import { panicReasons } from '../../constants/solidity.js'
2
+ import { BaseError } from '../../errors/base.js'
3
+ import { ContractFunctionRevertedError } from '../../errors/contract.js'
4
+
5
+ /*
6
+ * @description Checks if error is a valid null result UniversalResolver error
7
+ */
8
+ export function isNullUniversalResolverError(
9
+ err: unknown,
10
+ callType: 'resolve' | 'reverse',
11
+ ): boolean {
12
+ if (!(err instanceof BaseError)) return false
13
+ const cause = err.walk((e) => e instanceof ContractFunctionRevertedError)
14
+ if (!(cause instanceof ContractFunctionRevertedError)) return false
15
+ if (cause.data?.errorName === 'ResolverNotFound') return true
16
+ if (cause.data?.errorName === 'ResolverWildcardNotSupported') return true
17
+ // Backwards compatibility for older UniversalResolver contracts
18
+ if (
19
+ cause.reason?.includes(
20
+ 'Wildcard on non-extended resolvers is not supported',
21
+ )
22
+ )
23
+ return true
24
+ // No primary name set for address.
25
+ if (callType === 'reverse' && cause.reason === panicReasons[50]) return true
26
+ return false
27
+ }