@ensdomains/ensjs 3.0.0-alpha.13 → 3.0.0-alpha.16

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.
@@ -1,4 +1,4 @@
1
- import { ethers } from 'ethers'
1
+ import { BigNumber, ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
3
  import setup from '../tests/setup'
4
4
 
@@ -9,6 +9,22 @@ let provider: ethers.providers.JsonRpcProvider
9
9
  let accounts: string[]
10
10
  let withWrappedSnapshot: any
11
11
 
12
+ const unwrappedNameDefault = {
13
+ expiryDate: new Date(0).toString(),
14
+ fuseObj: {
15
+ CANNOT_BURN_FUSES: false,
16
+ CANNOT_CREATE_SUBDOMAIN: false,
17
+ CANNOT_SET_RESOLVER: false,
18
+ CANNOT_SET_TTL: false,
19
+ CANNOT_TRANSFER: false,
20
+ CANNOT_UNWRAP: false,
21
+ PARENT_CANNOT_CONTROL: false,
22
+ canDoEverything: true,
23
+ },
24
+ owner: '0x0000000000000000000000000000000000000000',
25
+ rawFuses: BigNumber.from(0),
26
+ }
27
+
12
28
  beforeAll(async () => {
13
29
  ;({ ENSInstance, revert, provider, createSnapshot } = await setup())
14
30
  accounts = await provider.listAccounts()
@@ -26,9 +42,11 @@ afterAll(async () => {
26
42
  })
27
43
 
28
44
  describe('getFuses', () => {
29
- it('should return null for an unwrapped name', async () => {
45
+ it('should return default data for an unwrapped name', async () => {
30
46
  const result = await ENSInstance.getFuses('with-profile.eth')
31
- expect(result).toBeUndefined()
47
+ expect({ ...result, expiryDate: result?.expiryDate.toString() }).toEqual(
48
+ unwrappedNameDefault,
49
+ )
32
50
  })
33
51
  it('should return with canDoEverything set to true for a name with no fuses burned', async () => {
34
52
  const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
@@ -47,11 +65,11 @@ describe('getFuses', () => {
47
65
  })
48
66
  it('should return with other correct fuses', async () => {
49
67
  const tx = await ENSInstance.burnFuses('wrapped.eth', {
50
- fusesToBurn: {
51
- cannotUnwrap: true,
52
- cannotSetTtl: true,
53
- cannotCreateSubdomain: true,
54
- },
68
+ namedFusesToBurn: [
69
+ 'CANNOT_UNWRAP',
70
+ 'CANNOT_CREATE_SUBDOMAIN',
71
+ 'CANNOT_SET_TTL',
72
+ ],
55
73
  addressOrIndex: 1,
56
74
  })
57
75
  await tx.wait()
@@ -60,13 +78,13 @@ describe('getFuses', () => {
60
78
  expect(result).toBeTruthy()
61
79
  if (result) {
62
80
  expect(result.fuseObj).toMatchObject({
63
- cannotUnwrap: true,
64
- cannotBurnFuses: false,
65
- cannotTransfer: false,
66
- cannotSetResolver: false,
67
- cannotSetTtl: true,
68
- cannotCreateSubdomain: true,
69
- parentCannotControl: true,
81
+ CANNOT_UNWRAP: true,
82
+ CANNOT_BURN_FUSES: false,
83
+ CANNOT_TRANSFER: false,
84
+ CANNOT_SET_RESOLVER: false,
85
+ CANNOT_SET_TTL: true,
86
+ CANNOT_CREATE_SUBDOMAIN: true,
87
+ PARENT_CANNOT_CONTROL: true,
70
88
  canDoEverything: false,
71
89
  })
72
90
  expect(result.rawFuses.toHexString()).toBe('0x71')
@@ -1,48 +1,34 @@
1
1
  import { BigNumber } from 'ethers'
2
2
  import { ENSArgs } from '..'
3
- import { testable as fuseEnums } from '../utils/fuses'
3
+ import { fuseEnum } from '../utils/fuses'
4
4
  import { namehash } from '../utils/normalise'
5
5
 
6
- const NameSafety = [
7
- 'Safe',
8
- 'RegistrantNotWrapped',
9
- 'ControllerNotWrapped',
10
- 'SubdomainReplacementAllowed',
11
- 'Expired',
12
- ]
13
-
14
6
  const raw = async ({ contracts }: ENSArgs<'contracts'>, name: string) => {
15
7
  const nameWrapper = await contracts?.getNameWrapper()!
16
8
  return {
17
9
  to: nameWrapper.address,
18
- data: nameWrapper.interface.encodeFunctionData('getFuses', [
19
- namehash(name),
20
- ]),
10
+ data: nameWrapper.interface.encodeFunctionData('getData', [namehash(name)]),
21
11
  }
22
12
  }
23
13
 
24
14
  const decode = async (
25
15
  { contracts }: ENSArgs<'contracts'>,
26
16
  data: string,
27
- name: string,
28
17
  ) => {
29
18
  const nameWrapper = await contracts?.getNameWrapper()!
30
19
  try {
31
- const [_fuses, expiry] = nameWrapper.interface.decodeFunctionResult(
32
- 'getFuses',
33
- data,
34
- )
20
+ const {
21
+ owner,
22
+ fuses: _fuses,
23
+ expiry,
24
+ } = nameWrapper.interface.decodeFunctionResult('getData', data)
35
25
 
36
26
  const fuses = BigNumber.from(_fuses)
37
27
 
38
28
  const fuseObj = Object.fromEntries(
39
- Object.keys(fuseEnums).map((fuseEnum) => [
40
- fuseEnum
41
- .toLowerCase()
42
- .replace(/([-_][a-z])/g, (group: string) =>
43
- group.toUpperCase().replace('-', '').replace('_', ''),
44
- ),
45
- fuses.and(fuseEnums[fuseEnum as keyof typeof fuseEnums]).gt(0),
29
+ Object.keys(fuseEnum).map((fuse) => [
30
+ fuse,
31
+ fuses.and(fuseEnum[fuse as keyof typeof fuseEnum]).gt(0),
46
32
  ]),
47
33
  )
48
34
 
@@ -58,8 +44,10 @@ const decode = async (
58
44
  fuseObj,
59
45
  expiryDate,
60
46
  rawFuses: fuses,
47
+ owner,
61
48
  }
62
- } catch {
49
+ } catch (e) {
50
+ console.error('Error decoding fuses data: ', e)
63
51
  return
64
52
  }
65
53
  }
package/src/index.ts CHANGED
@@ -46,6 +46,7 @@ import type wrapName from './functions/wrapName'
46
46
  import GqlManager from './GqlManager'
47
47
  import singleCall from './utils/singleCall'
48
48
  import writeTx from './utils/writeTx'
49
+ import fuseEnum from './utils/fuses'
49
50
 
50
51
  type ENSOptions = {
51
52
  graphURI?: string | null
@@ -157,6 +158,7 @@ export class ENS {
157
158
  contracts?: ContractManager
158
159
  getContractAddress = _getContractAddress
159
160
  gqlInstance = new GqlManager()
161
+ fuses = fuseEnum
160
162
 
161
163
  constructor(options?: ENSOptions) {
162
164
  this.options = options
@@ -7,7 +7,7 @@ const CANNOT_CREATE_SUBDOMAIN = 32
7
7
  const PARENT_CANNOT_CONTROL = 64
8
8
  const CAN_DO_EVERYTHING = 0
9
9
 
10
- export const testable = {
10
+ export const fuseEnum = {
11
11
  CANNOT_UNWRAP,
12
12
  CANNOT_BURN_FUSES,
13
13
  CANNOT_TRANSFER,
@@ -15,9 +15,17 @@ export const testable = {
15
15
  CANNOT_SET_TTL,
16
16
  CANNOT_CREATE_SUBDOMAIN,
17
17
  PARENT_CANNOT_CONTROL,
18
- }
18
+ } as const
19
+
20
+ export const unnamedFuses = [
21
+ 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144,
22
+ 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864,
23
+ 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296,
24
+ ] as const
19
25
 
20
- export default {
21
- ...testable,
26
+ const fullFuseEnum = {
27
+ ...fuseEnum,
22
28
  CAN_DO_EVERYTHING,
23
29
  }
30
+
31
+ export default fullFuseEnum