@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.
- package/dist/cjs/GqlManager.d.ts +5 -3
- package/dist/cjs/GqlManager.js +21 -13
- package/dist/cjs/contracts/index.d.ts +8 -8
- package/dist/cjs/functions/burnFuses.d.ts +31 -4
- package/dist/cjs/functions/burnFuses.js +36 -6
- package/dist/cjs/functions/getFuses.d.ts +2 -1
- package/dist/cjs/functions/getFuses.js +9 -18
- package/dist/cjs/functions/getSpecificRecord.d.ts +4 -4
- package/dist/cjs/index.d.ts +12 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/fuses.d.ts +18 -17
- package/dist/cjs/utils/fuses.js +10 -4
- package/dist/cjs/utils/wrapperExpiry.d.ts +1 -1
- package/dist/esm/GqlManager.d.ts +5 -3
- package/dist/esm/GqlManager.js +21 -13
- package/dist/esm/contracts/index.d.ts +8 -8
- package/dist/esm/functions/burnFuses.d.ts +31 -4
- package/dist/esm/functions/burnFuses.js +36 -3
- package/dist/esm/functions/getFuses.d.ts +2 -1
- package/dist/esm/functions/getFuses.js +10 -19
- package/dist/esm/functions/getSpecificRecord.d.ts +4 -4
- package/dist/esm/index.d.ts +12 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/fuses.d.ts +18 -17
- package/dist/esm/utils/fuses.js +9 -3
- package/dist/esm/utils/wrapperExpiry.d.ts +1 -1
- package/package.json +1 -1
- package/src/GqlManager.test.ts +5 -4
- package/src/GqlManager.ts +54 -36
- package/src/functions/burnFuses.test.ts +123 -15
- package/src/functions/burnFuses.ts +101 -10
- package/src/functions/getFuses.test.ts +33 -15
- package/src/functions/getFuses.ts +13 -25
- package/src/index.ts +2 -0
- package/src/utils/fuses.ts +12 -4
|
@@ -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
|
|
45
|
+
it('should return default data for an unwrapped name', async () => {
|
|
30
46
|
const result = await ENSInstance.getFuses('with-profile.eth')
|
|
31
|
-
expect(result).
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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 {
|
|
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('
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
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(
|
|
40
|
-
|
|
41
|
-
|
|
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
|
package/src/utils/fuses.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
21
|
-
...
|
|
26
|
+
const fullFuseEnum = {
|
|
27
|
+
...fuseEnum,
|
|
22
28
|
CAN_DO_EVERYTHING,
|
|
23
29
|
}
|
|
30
|
+
|
|
31
|
+
export default fullFuseEnum
|