@ensdomains/ensjs 3.0.0-alpha.1 → 3.0.0-alpha.10
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/README.md +2 -0
- package/dist/cjs/GqlManager.d.ts +3 -0
- package/dist/cjs/GqlManager.js +62 -2
- package/dist/cjs/functions/burnFuses.d.ts +3 -2
- package/dist/cjs/functions/burnFuses.js +4 -8
- package/dist/cjs/functions/createSubname.d.ts +1 -5
- package/dist/cjs/functions/createSubname.js +5 -8
- package/dist/cjs/functions/deleteSubname.d.ts +3 -3
- package/dist/cjs/functions/deleteSubname.js +5 -2
- package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
- package/dist/cjs/functions/getDNSOwner.js +81 -0
- package/dist/cjs/functions/getFuses.js +3 -2
- package/dist/cjs/functions/getOwner.js +7 -6
- package/dist/cjs/functions/getProfile.d.ts +4 -1
- package/dist/cjs/functions/getProfile.js +102 -24
- package/dist/cjs/functions/getRecords.d.ts +1 -0
- package/dist/cjs/functions/getSpecificRecord.js +22 -5
- package/dist/cjs/functions/getSubnames.js +6 -6
- package/dist/cjs/functions/setName.d.ts +4 -3
- package/dist/cjs/functions/setName.js +5 -10
- package/dist/cjs/functions/setRecord.d.ts +18 -0
- package/dist/cjs/functions/setRecord.js +27 -0
- package/dist/cjs/functions/setRecords.d.ts +4 -2
- package/dist/cjs/functions/setRecords.js +14 -12
- package/dist/cjs/functions/setResolver.d.ts +4 -4
- package/dist/cjs/functions/setResolver.js +6 -12
- package/dist/cjs/functions/transferName.d.ts +4 -3
- package/dist/cjs/functions/transferName.js +9 -13
- package/dist/cjs/functions/transferSubname.d.ts +4 -3
- package/dist/cjs/functions/transferSubname.js +5 -8
- package/dist/cjs/functions/unwrapName.d.ts +4 -3
- package/dist/cjs/functions/unwrapName.js +5 -9
- package/dist/cjs/functions/wrapName.d.ts +5 -3
- package/dist/cjs/functions/wrapName.js +8 -12
- package/dist/cjs/index.d.ts +48 -46
- package/dist/cjs/index.js +43 -19
- package/dist/cjs/utils/labels.js +5 -4
- package/dist/cjs/utils/makeHashIndexes.js +2 -2
- package/dist/cjs/utils/normalise.d.ts +1 -0
- package/dist/cjs/utils/normalise.js +27 -1
- package/dist/cjs/utils/recordHelpers.d.ts +3 -0
- package/dist/cjs/utils/recordHelpers.js +42 -15
- package/dist/cjs/utils/registerHelpers.js +3 -4
- package/dist/cjs/utils/writeTx.d.ts +4 -0
- package/dist/cjs/utils/writeTx.js +3 -0
- package/dist/esm/GqlManager.d.ts +3 -0
- package/dist/esm/GqlManager.js +58 -2
- package/dist/esm/functions/burnFuses.d.ts +3 -2
- package/dist/esm/functions/burnFuses.js +4 -8
- package/dist/esm/functions/createSubname.d.ts +1 -5
- package/dist/esm/functions/createSubname.js +5 -8
- package/dist/esm/functions/deleteSubname.d.ts +3 -3
- package/dist/esm/functions/deleteSubname.js +5 -2
- package/dist/esm/functions/getDNSOwner.d.ts +7 -0
- package/dist/esm/functions/getDNSOwner.js +51 -0
- package/dist/esm/functions/getFuses.js +4 -3
- package/dist/esm/functions/getOwner.js +7 -6
- package/dist/esm/functions/getProfile.d.ts +4 -1
- package/dist/esm/functions/getProfile.js +102 -24
- package/dist/esm/functions/getRecords.d.ts +1 -0
- package/dist/esm/functions/getSpecificRecord.js +22 -5
- package/dist/esm/functions/getSubnames.js +3 -3
- package/dist/esm/functions/setName.d.ts +4 -3
- package/dist/esm/functions/setName.js +5 -10
- package/dist/esm/functions/setRecord.d.ts +18 -0
- package/dist/esm/functions/setRecord.js +24 -0
- package/dist/esm/functions/setRecords.d.ts +4 -2
- package/dist/esm/functions/setRecords.js +14 -12
- package/dist/esm/functions/setResolver.d.ts +4 -4
- package/dist/esm/functions/setResolver.js +6 -12
- package/dist/esm/functions/transferName.d.ts +4 -3
- package/dist/esm/functions/transferName.js +9 -13
- package/dist/esm/functions/transferSubname.d.ts +4 -3
- package/dist/esm/functions/transferSubname.js +5 -8
- package/dist/esm/functions/unwrapName.d.ts +4 -3
- package/dist/esm/functions/unwrapName.js +5 -9
- package/dist/esm/functions/wrapName.d.ts +5 -3
- package/dist/esm/functions/wrapName.js +8 -12
- package/dist/esm/index.d.ts +48 -46
- package/dist/esm/index.js +43 -19
- package/dist/esm/utils/labels.js +5 -4
- package/dist/esm/utils/makeHashIndexes.js +2 -2
- package/dist/esm/utils/normalise.d.ts +1 -0
- package/dist/esm/utils/normalise.js +25 -0
- package/dist/esm/utils/recordHelpers.d.ts +3 -0
- package/dist/esm/utils/recordHelpers.js +40 -14
- package/dist/esm/utils/registerHelpers.js +3 -4
- package/dist/esm/utils/writeTx.d.ts +4 -0
- package/dist/esm/utils/writeTx.js +1 -0
- package/package.json +15 -7
- package/src/@types/dns-packet/index.d.ts +114 -0
- package/src/GqlManager.test.ts +170 -0
- package/src/GqlManager.ts +67 -2
- package/src/{tests → functions}/batch.test.ts +1 -1
- package/src/{tests → functions}/batchWrappers.test.ts +1 -1
- package/src/{tests → functions}/burnFuses.test.ts +12 -10
- package/src/functions/burnFuses.ts +9 -11
- package/src/{tests → functions}/createSubname.test.ts +12 -16
- package/src/functions/createSubname.ts +7 -13
- package/src/{tests → functions}/deleteSubname.test.ts +32 -32
- package/src/functions/deleteSubname.ts +9 -12
- package/src/functions/getDNSOwner.test.ts +122 -0
- package/src/functions/getDNSOwner.ts +61 -0
- package/src/{tests → functions}/getExpiry.test.ts +1 -1
- package/src/{tests → functions}/getFuses.test.ts +12 -10
- package/src/functions/getFuses.ts +4 -3
- package/src/{tests → functions}/getHistory.test.ts +1 -1
- package/src/{tests → functions}/getName.test.ts +1 -1
- package/src/{tests → functions}/getNames.test.ts +1 -1
- package/src/{tests → functions}/getOwner.test.ts +14 -2
- package/src/functions/getOwner.ts +7 -7
- package/src/{tests → functions}/getProfile.test.ts +45 -12
- package/src/functions/getProfile.ts +151 -24
- package/src/functions/getRecords.ts +1 -0
- package/src/{tests → functions}/getResolver.test.ts +1 -1
- package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
- package/src/functions/getSpecificRecord.ts +28 -8
- package/src/{tests → functions}/getSubnames.test.ts +1 -1
- package/src/functions/getSubnames.ts +68 -66
- package/src/{tests → functions}/makeCommitment.test.ts +1 -1
- package/src/functions/normalise.test.ts +22 -0
- package/src/{tests → functions}/setName.test.ts +3 -2
- package/src/functions/setName.ts +15 -17
- package/src/functions/setRecord.test.ts +100 -0
- package/src/functions/setRecord.ts +63 -0
- package/src/{tests → functions}/setRecords.test.ts +12 -10
- package/src/functions/setRecords.ts +22 -16
- package/src/{tests → functions}/setResolver.test.ts +12 -15
- package/src/functions/setResolver.ts +15 -20
- package/src/{tests → functions}/transferName.test.ts +30 -31
- package/src/functions/transferName.ts +19 -22
- package/src/{tests → functions}/transferSubname.test.ts +34 -34
- package/src/functions/transferSubname.ts +21 -13
- package/src/{tests → functions}/unwrapName.test.ts +24 -23
- package/src/functions/unwrapName.ts +20 -15
- package/src/{tests → functions}/wrapName.test.ts +19 -19
- package/src/functions/wrapName.ts +20 -22
- package/src/index.ts +115 -26
- package/src/tests/populateTransaction.test.ts +40 -0
- package/src/tests/signerInjection.test.ts +46 -0
- package/src/tests/withProvider.test.ts +1 -1
- package/src/utils/labels.ts +6 -4
- package/src/utils/makeHashIndexes.ts +4 -4
- package/src/utils/normalise.ts +29 -0
- package/src/utils/recordHelpers.ts +52 -18
- package/src/utils/registerHelpers.ts +3 -4
- package/src/utils/writeTx.ts +6 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ethers
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
-
import setup from '
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
|
+
import { namehash } from '../utils/normalise'
|
|
4
5
|
|
|
5
6
|
let ENSInstance: ENS
|
|
6
7
|
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
@@ -21,54 +22,53 @@ describe('transferSubname', () => {
|
|
|
21
22
|
await revert()
|
|
22
23
|
})
|
|
23
24
|
it('should allow transferring a subname on the registry', async () => {
|
|
24
|
-
const createSubnameTx = await ENSInstance.createSubname(
|
|
25
|
-
contract: 'registry',
|
|
26
|
-
name: 'test.parthtejpal.eth',
|
|
27
|
-
owner: accounts[0],
|
|
28
|
-
options: { addressOrIndex: 0 },
|
|
29
|
-
})
|
|
30
|
-
await createSubnameTx.wait()
|
|
31
|
-
|
|
32
|
-
const tx = await ENSInstance.transferSubname(
|
|
25
|
+
const createSubnameTx = await ENSInstance.createSubname(
|
|
33
26
|
'test.parthtejpal.eth',
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
{
|
|
28
|
+
contract: 'registry',
|
|
29
|
+
owner: accounts[0],
|
|
30
|
+
addressOrIndex: 0,
|
|
31
|
+
},
|
|
37
32
|
)
|
|
33
|
+
await createSubnameTx.wait()
|
|
34
|
+
|
|
35
|
+
const tx = await ENSInstance.transferSubname('test.parthtejpal.eth', {
|
|
36
|
+
contract: 'registry',
|
|
37
|
+
address: accounts[1],
|
|
38
|
+
addressOrIndex: 0,
|
|
39
|
+
})
|
|
38
40
|
expect(tx).toBeTruthy()
|
|
39
41
|
await tx.wait()
|
|
40
42
|
|
|
41
43
|
const registry = await ENSInstance.contracts!.getRegistry()!
|
|
42
|
-
const result = await registry.owner(
|
|
44
|
+
const result = await registry.owner(namehash('test.parthtejpal.eth'))
|
|
43
45
|
expect(result).toBe(accounts[1])
|
|
44
46
|
})
|
|
45
47
|
it('should allow transferring a subname on the nameWrapper', async () => {
|
|
46
|
-
const wrapNameTx = await ENSInstance.wrapName(
|
|
47
|
-
|
|
48
|
-
accounts[0],
|
|
49
|
-
)
|
|
50
|
-
await wrapNameTx.wait()
|
|
51
|
-
const createSubnameTx = await ENSInstance.createSubname({
|
|
52
|
-
contract: 'nameWrapper',
|
|
53
|
-
name: 'test.parthtejpal.eth',
|
|
54
|
-
owner: accounts[0],
|
|
55
|
-
options: { addressOrIndex: 0 },
|
|
48
|
+
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
49
|
+
wrappedOwner: accounts[0],
|
|
56
50
|
})
|
|
57
|
-
await
|
|
58
|
-
|
|
59
|
-
const tx = await ENSInstance.transferSubname(
|
|
51
|
+
await wrapNameTx.wait()
|
|
52
|
+
const createSubnameTx = await ENSInstance.createSubname(
|
|
60
53
|
'test.parthtejpal.eth',
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
{
|
|
55
|
+
contract: 'nameWrapper',
|
|
56
|
+
owner: accounts[0],
|
|
57
|
+
addressOrIndex: 0,
|
|
58
|
+
},
|
|
64
59
|
)
|
|
60
|
+
await createSubnameTx.wait()
|
|
61
|
+
|
|
62
|
+
const tx = await ENSInstance.transferSubname('test.parthtejpal.eth', {
|
|
63
|
+
contract: 'nameWrapper',
|
|
64
|
+
address: accounts[1],
|
|
65
|
+
addressOrIndex: 0,
|
|
66
|
+
})
|
|
65
67
|
expect(tx).toBeTruthy()
|
|
66
68
|
await tx.wait()
|
|
67
69
|
|
|
68
70
|
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
69
|
-
const result = await nameWrapper.ownerOf(
|
|
70
|
-
utils.namehash('test.parthtejpal.eth'),
|
|
71
|
-
)
|
|
71
|
+
const result = await nameWrapper.ownerOf(namehash('test.parthtejpal.eth'))
|
|
72
72
|
expect(result).toBe(accounts[1])
|
|
73
73
|
})
|
|
74
74
|
})
|
|
@@ -1,34 +1,42 @@
|
|
|
1
1
|
import { ethers } from 'ethers'
|
|
2
2
|
import { ENSArgs } from '..'
|
|
3
|
+
import { namehash } from '../utils/normalise'
|
|
3
4
|
|
|
4
5
|
export default async function (
|
|
5
|
-
{ contracts,
|
|
6
|
+
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
|
|
6
7
|
name: string,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
{
|
|
9
|
+
contract,
|
|
10
|
+
address,
|
|
11
|
+
}: {
|
|
12
|
+
contract: 'registry' | 'nameWrapper'
|
|
13
|
+
address: string
|
|
14
|
+
},
|
|
10
15
|
) {
|
|
11
|
-
const signer = provider?.getSigner(options?.addressOrIndex)
|
|
12
|
-
|
|
13
|
-
if (!signer) {
|
|
14
|
-
throw new Error('No signer found')
|
|
15
|
-
}
|
|
16
|
-
|
|
17
16
|
const labels = name.split('.')
|
|
18
17
|
const label = labels.shift() as string
|
|
19
18
|
const labelhash = ethers.utils.solidityKeccak256(['string'], [label])
|
|
20
|
-
const parentNodehash =
|
|
19
|
+
const parentNodehash = namehash(labels.join('.'))
|
|
21
20
|
|
|
22
21
|
switch (contract) {
|
|
23
22
|
case 'registry': {
|
|
24
23
|
const registry = (await contracts?.getRegistry()!).connect(signer)
|
|
25
24
|
|
|
26
|
-
return registry.setSubnodeOwner(
|
|
25
|
+
return registry.populateTransaction.setSubnodeOwner(
|
|
26
|
+
parentNodehash,
|
|
27
|
+
labelhash,
|
|
28
|
+
address,
|
|
29
|
+
)
|
|
27
30
|
}
|
|
28
31
|
case 'nameWrapper': {
|
|
29
32
|
const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
|
|
30
33
|
|
|
31
|
-
return nameWrapper.setSubnodeOwner(
|
|
34
|
+
return nameWrapper.populateTransaction.setSubnodeOwner(
|
|
35
|
+
parentNodehash,
|
|
36
|
+
label,
|
|
37
|
+
address,
|
|
38
|
+
'0',
|
|
39
|
+
)
|
|
32
40
|
}
|
|
33
41
|
default: {
|
|
34
42
|
throw new Error(`Unknown contract: ${contract}`)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ethers, utils } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
-
import setup from '
|
|
3
|
+
import setup from '../tests/setup'
|
|
4
|
+
import { namehash } from '../utils/normalise'
|
|
4
5
|
|
|
5
6
|
let ENSInstance: ENS
|
|
6
7
|
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
@@ -21,17 +22,15 @@ describe('unwrapName', () => {
|
|
|
21
22
|
await revert()
|
|
22
23
|
})
|
|
23
24
|
it('should return a .eth unwrap name transaction and succeed', async () => {
|
|
24
|
-
const wrapNameTx = await ENSInstance.wrapName(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
25
|
+
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
26
|
+
wrappedOwner: accounts[0],
|
|
27
|
+
})
|
|
28
28
|
await wrapNameTx.wait()
|
|
29
29
|
|
|
30
|
-
const tx = await ENSInstance.unwrapName(
|
|
31
|
-
|
|
32
|
-
accounts[0],
|
|
33
|
-
|
|
34
|
-
)
|
|
30
|
+
const tx = await ENSInstance.unwrapName('parthtejpal.eth', {
|
|
31
|
+
newController: accounts[0],
|
|
32
|
+
newRegistrant: accounts[0],
|
|
33
|
+
})
|
|
35
34
|
expect(tx).toBeTruthy()
|
|
36
35
|
await tx.wait()
|
|
37
36
|
|
|
@@ -42,26 +41,28 @@ describe('unwrapName', () => {
|
|
|
42
41
|
expect(result).toBe(accounts[0])
|
|
43
42
|
})
|
|
44
43
|
it('should return a regular unwrap name transaction and succeed', async () => {
|
|
45
|
-
const wrapNameTx = await ENSInstance.wrapName(
|
|
46
|
-
|
|
47
|
-
accounts[0],
|
|
48
|
-
)
|
|
49
|
-
await wrapNameTx.wait()
|
|
50
|
-
const createSubnameTx = await ENSInstance.createSubname({
|
|
51
|
-
contract: 'nameWrapper',
|
|
52
|
-
name: 'test.parthtejpal.eth',
|
|
53
|
-
owner: accounts[0],
|
|
54
|
-
shouldWrap: true,
|
|
55
|
-
options: { addressOrIndex: 0 },
|
|
44
|
+
const wrapNameTx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
45
|
+
wrappedOwner: accounts[0],
|
|
56
46
|
})
|
|
47
|
+
await wrapNameTx.wait()
|
|
48
|
+
const createSubnameTx = await ENSInstance.createSubname(
|
|
49
|
+
'test.parthtejpal.eth',
|
|
50
|
+
{
|
|
51
|
+
contract: 'nameWrapper',
|
|
52
|
+
owner: accounts[0],
|
|
53
|
+
addressOrIndex: 0,
|
|
54
|
+
},
|
|
55
|
+
)
|
|
57
56
|
await createSubnameTx.wait()
|
|
58
57
|
|
|
59
|
-
const tx = await ENSInstance.unwrapName('test.parthtejpal.eth',
|
|
58
|
+
const tx = await ENSInstance.unwrapName('test.parthtejpal.eth', {
|
|
59
|
+
newController: accounts[0],
|
|
60
|
+
})
|
|
60
61
|
expect(tx).toBeTruthy()
|
|
61
62
|
await tx.wait()
|
|
62
63
|
|
|
63
64
|
const registry = await ENSInstance.contracts!.getRegistry()!
|
|
64
|
-
const result = await registry.owner(
|
|
65
|
+
const result = await registry.owner(namehash('test.parthtejpal.eth'))
|
|
65
66
|
expect(result).toBe(accounts[0])
|
|
66
67
|
})
|
|
67
68
|
})
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { utils } from 'ethers'
|
|
2
2
|
import { ENSArgs } from '..'
|
|
3
|
+
import { namehash } from '../utils/normalise'
|
|
3
4
|
|
|
4
5
|
export default async function (
|
|
5
|
-
{ contracts,
|
|
6
|
+
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
|
|
6
7
|
name: string,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
{
|
|
9
|
+
newController,
|
|
10
|
+
newRegistrant,
|
|
11
|
+
}: {
|
|
12
|
+
newController: string
|
|
13
|
+
newRegistrant?: string
|
|
14
|
+
},
|
|
10
15
|
) {
|
|
11
|
-
const signer = provider?.getSigner(options?.addressOrIndex)
|
|
12
|
-
|
|
13
|
-
const address = await signer?.getAddress()
|
|
14
|
-
|
|
15
|
-
if (!signer || !address) {
|
|
16
|
-
throw new Error('No signer found')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
16
|
const labels = name.split('.')
|
|
20
17
|
const labelhash = utils.solidityKeccak256(['string'], [labels[0]])
|
|
21
|
-
const parentNodehash =
|
|
18
|
+
const parentNodehash = namehash(labels.slice(1).join('.'))
|
|
22
19
|
|
|
23
20
|
const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
|
|
24
21
|
|
|
@@ -27,12 +24,20 @@ export default async function (
|
|
|
27
24
|
throw new Error('newRegistrant must be specified for .eth names')
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
return nameWrapper.unwrapETH2LD(
|
|
27
|
+
return nameWrapper.populateTransaction.unwrapETH2LD(
|
|
28
|
+
labelhash,
|
|
29
|
+
newRegistrant,
|
|
30
|
+
newController,
|
|
31
|
+
)
|
|
31
32
|
} else {
|
|
32
33
|
if (newRegistrant) {
|
|
33
34
|
throw new Error('newRegistrant can only be specified for .eth names')
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
return nameWrapper.unwrap(
|
|
37
|
+
return nameWrapper.populateTransaction.unwrap(
|
|
38
|
+
parentNodehash,
|
|
39
|
+
labelhash,
|
|
40
|
+
newController,
|
|
41
|
+
)
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { BigNumber, ethers
|
|
1
|
+
import { BigNumber, ethers } from 'ethers'
|
|
2
2
|
import { ENS } from '..'
|
|
3
|
+
import setup from '../tests/setup'
|
|
3
4
|
import { hexEncodeName } from '../utils/hexEncodedName'
|
|
4
|
-
import
|
|
5
|
+
import { namehash } from '../utils/normalise'
|
|
5
6
|
|
|
6
7
|
let ENSInstance: ENS
|
|
7
8
|
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
@@ -23,37 +24,36 @@ describe('wrapName', () => {
|
|
|
23
24
|
await revert()
|
|
24
25
|
})
|
|
25
26
|
it('should return a wrap name transaction and succeed', async () => {
|
|
26
|
-
const tx = await ENSInstance.wrapName('parthtejpal.eth',
|
|
27
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
28
|
+
wrappedOwner: accounts[0],
|
|
29
|
+
})
|
|
27
30
|
expect(tx).toBeTruthy()
|
|
28
31
|
await tx.wait()
|
|
29
32
|
|
|
30
33
|
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
31
|
-
const [result] = await nameWrapper.getFuses(
|
|
32
|
-
utils.namehash('parthtejpal.eth'),
|
|
33
|
-
)
|
|
34
|
+
const [result] = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
|
|
34
35
|
expect((result as BigNumber).toHexString()).toBe('0x40')
|
|
35
36
|
})
|
|
36
37
|
it('should allow initial fuses', async () => {
|
|
37
|
-
const tx = await ENSInstance.wrapName('parthtejpal.eth',
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
39
|
+
wrappedOwner: accounts[0],
|
|
40
|
+
fuseOptions: {
|
|
41
|
+
cannotUnwrap: true,
|
|
42
|
+
cannotSetTtl: true,
|
|
43
|
+
},
|
|
40
44
|
})
|
|
41
45
|
expect(tx).toBeTruthy()
|
|
42
46
|
await tx.wait()
|
|
43
47
|
|
|
44
48
|
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
|
|
45
|
-
const [result] = await nameWrapper.getFuses(
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
expect((result as BigNumber).toHexString()).toBe('0x51')
|
|
49
|
+
const [result] = await nameWrapper.getFuses(namehash('parthtejpal.eth'))
|
|
50
|
+
expect((result as BigNumber).toHexString()).toBe('0x40')
|
|
49
51
|
})
|
|
50
52
|
it('should allow an initial resolver address', async () => {
|
|
51
|
-
const tx = await ENSInstance.wrapName(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
'0x42D63ae25990889E35F215bC95884039Ba354115',
|
|
56
|
-
)
|
|
53
|
+
const tx = await ENSInstance.wrapName('parthtejpal.eth', {
|
|
54
|
+
wrappedOwner: accounts[0],
|
|
55
|
+
resolverAddress: '0x42D63ae25990889E35F215bC95884039Ba354115',
|
|
56
|
+
})
|
|
57
57
|
expect(tx).toBeTruthy()
|
|
58
58
|
await tx.wait()
|
|
59
59
|
|
|
@@ -19,16 +19,13 @@ async function wrapETH(
|
|
|
19
19
|
const labelhash = ethers.utils.solidityKeccak256(['string'], [labels[0]])
|
|
20
20
|
|
|
21
21
|
const data = ethers.utils.defaultAbiCoder.encode(
|
|
22
|
-
['string', 'address', '
|
|
23
|
-
[labels[0], wrappedOwner, decodedFuses, resolverAddress],
|
|
22
|
+
['string', 'address', 'uint32', 'uint64', 'address'],
|
|
23
|
+
[labels[0], wrappedOwner, '0x0', decodedFuses, resolverAddress],
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
return baseRegistrar[
|
|
27
|
-
address,
|
|
28
|
-
|
|
29
|
-
labelhash,
|
|
30
|
-
data,
|
|
31
|
-
)
|
|
26
|
+
return baseRegistrar.populateTransaction[
|
|
27
|
+
'safeTransferFrom(address,address,uint256,bytes)'
|
|
28
|
+
](address, nameWrapper.address, labelhash, data)
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
async function wrapOther(
|
|
@@ -38,8 +35,9 @@ async function wrapOther(
|
|
|
38
35
|
decodedFuses: string,
|
|
39
36
|
resolverAddress: string,
|
|
40
37
|
address: string,
|
|
38
|
+
signer: ethers.Signer,
|
|
41
39
|
) {
|
|
42
|
-
const nameWrapper = await contracts?.getNameWrapper()!
|
|
40
|
+
const nameWrapper = (await contracts?.getNameWrapper()!).connect(signer)
|
|
43
41
|
const registry = await contracts?.getRegistry()!
|
|
44
42
|
|
|
45
43
|
const hasApproval = await registry.isApprovedForAll(
|
|
@@ -53,7 +51,7 @@ async function wrapOther(
|
|
|
53
51
|
)
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
return nameWrapper.wrap(
|
|
54
|
+
return nameWrapper.populateTransaction.wrap(
|
|
57
55
|
hexEncodeName(name),
|
|
58
56
|
wrappedOwner,
|
|
59
57
|
decodedFuses,
|
|
@@ -62,20 +60,19 @@ async function wrapOther(
|
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
export default async function (
|
|
65
|
-
{ contracts,
|
|
63
|
+
{ contracts, signer, populate }: ENSArgs<'contracts' | 'signer' | 'populate'>,
|
|
66
64
|
name: string,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
{
|
|
66
|
+
wrappedOwner,
|
|
67
|
+
fuseOptions,
|
|
68
|
+
resolverAddress,
|
|
69
|
+
}: {
|
|
70
|
+
wrappedOwner: string
|
|
71
|
+
fuseOptions?: FuseOptions | string | number
|
|
72
|
+
resolverAddress?: string
|
|
73
|
+
},
|
|
71
74
|
) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const address = await signer?.getAddress()
|
|
75
|
-
|
|
76
|
-
if (!signer || !address) {
|
|
77
|
-
throw new Error('No signer found')
|
|
78
|
-
}
|
|
75
|
+
const address = await signer.getAddress()
|
|
79
76
|
|
|
80
77
|
let decodedFuses: string
|
|
81
78
|
|
|
@@ -123,6 +120,7 @@ export default async function (
|
|
|
123
120
|
decodedFuses,
|
|
124
121
|
resolverAddress,
|
|
125
122
|
address,
|
|
123
|
+
signer,
|
|
126
124
|
)
|
|
127
125
|
}
|
|
128
126
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JsonRpcSigner } from '@ethersproject/providers'
|
|
2
|
+
import { ContractTransaction, ethers, PopulatedTransaction } from 'ethers'
|
|
2
3
|
import ContractManager from './contracts'
|
|
3
4
|
import { getContractAddress as _getContractAddress } from './contracts/getContractAddress'
|
|
4
5
|
import { SupportedNetworkId } from './contracts/types'
|
|
@@ -11,6 +12,7 @@ import type {
|
|
|
11
12
|
import type burnFuses from './functions/burnFuses'
|
|
12
13
|
import type createSubname from './functions/createSubname'
|
|
13
14
|
import type deleteSubname from './functions/deleteSubname'
|
|
15
|
+
import type getDNSOwner from './functions/getDNSOwner'
|
|
14
16
|
import type getExpiry from './functions/getExpiry'
|
|
15
17
|
import type getFuses from './functions/getFuses'
|
|
16
18
|
import type {
|
|
@@ -35,6 +37,7 @@ import type {
|
|
|
35
37
|
} from './functions/getSpecificRecord'
|
|
36
38
|
import type getSubnames from './functions/getSubnames'
|
|
37
39
|
import type setName from './functions/setName'
|
|
40
|
+
import type setRecord from './functions/setRecord'
|
|
38
41
|
import type setRecords from './functions/setRecords'
|
|
39
42
|
import type setResolver from './functions/setResolver'
|
|
40
43
|
import type transferName from './functions/transferName'
|
|
@@ -43,6 +46,7 @@ import type unwrapName from './functions/unwrapName'
|
|
|
43
46
|
import type wrapName from './functions/wrapName'
|
|
44
47
|
import GqlManager from './GqlManager'
|
|
45
48
|
import singleCall from './utils/singleCall'
|
|
49
|
+
import writeTx from './utils/writeTx'
|
|
46
50
|
|
|
47
51
|
type ENSOptions = {
|
|
48
52
|
graphURI?: string | null
|
|
@@ -52,6 +56,7 @@ type ENSOptions = {
|
|
|
52
56
|
export type InternalENS = {
|
|
53
57
|
options?: ENSOptions
|
|
54
58
|
provider?: ethers.providers.Provider
|
|
59
|
+
signer: JsonRpcSigner
|
|
55
60
|
graphURI?: string | null
|
|
56
61
|
} & ENS
|
|
57
62
|
|
|
@@ -75,6 +80,28 @@ type FirstArg<F> = F extends (x: infer A, ...args: any[]) => any ? A : never
|
|
|
75
80
|
|
|
76
81
|
type FunctionDeps<F> = Extract<keyof FirstArg<F>, string>[]
|
|
77
82
|
|
|
83
|
+
type WriteOptions = {
|
|
84
|
+
addressOrIndex?: string | number
|
|
85
|
+
signer?: JsonRpcSigner
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type OptionalWriteOptions<F> = F extends (
|
|
89
|
+
x: any,
|
|
90
|
+
arg_0: infer Z,
|
|
91
|
+
options?: infer P,
|
|
92
|
+
) => infer R
|
|
93
|
+
? (name: Z, options?: P & WriteOptions) => R
|
|
94
|
+
: F extends (x: any, arg_0: infer Z, options: infer P) => infer R
|
|
95
|
+
? (name: Z, options: P & WriteOptions) => R
|
|
96
|
+
: never
|
|
97
|
+
|
|
98
|
+
interface WriteFunction<F extends (...args: any) => any> extends Function {
|
|
99
|
+
(...args: Parameters<OptionalWriteOptions<F>>): Promise<ContractTransaction>
|
|
100
|
+
populateTransaction: (
|
|
101
|
+
...args: Parameters<OptionalWriteOptions<F>>
|
|
102
|
+
) => Promise<PopulatedTransaction>
|
|
103
|
+
}
|
|
104
|
+
|
|
78
105
|
const graphURIEndpoints: Record<string, string> = {
|
|
79
106
|
1: 'https://api.thegraph.com/subgraphs/name/ensdomains/ens',
|
|
80
107
|
3: 'https://api.thegraph.com/subgraphs/name/ensdomains/ensropsten',
|
|
@@ -171,7 +198,13 @@ export class ENS {
|
|
|
171
198
|
path: string,
|
|
172
199
|
dependencies: FunctionDeps<F>,
|
|
173
200
|
exportName: string = 'default',
|
|
174
|
-
subFunc?:
|
|
201
|
+
subFunc?:
|
|
202
|
+
| 'raw'
|
|
203
|
+
| 'decode'
|
|
204
|
+
| 'combine'
|
|
205
|
+
| 'batch'
|
|
206
|
+
| 'write'
|
|
207
|
+
| 'populateTransaction',
|
|
175
208
|
passthrough?: RawFunction,
|
|
176
209
|
): Function => {
|
|
177
210
|
// if batch is specified, create batch func
|
|
@@ -185,18 +218,40 @@ export class ENS {
|
|
|
185
218
|
await thisRef.checkInitialProvider()
|
|
186
219
|
// import the module dynamically
|
|
187
220
|
const mod = await import(
|
|
188
|
-
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true */
|
|
221
|
+
/* webpackMode: "lazy", webpackChunkName: "[request]", webpackPreload: true, webpackExclude: /.*\.ts$/ */
|
|
189
222
|
`./functions/${path}`
|
|
190
223
|
)
|
|
191
224
|
|
|
192
225
|
// if combine isn't specified, run normally
|
|
193
226
|
// otherwise, create a function from the raw and decode functions
|
|
194
227
|
if (subFunc !== 'combine') {
|
|
228
|
+
const writeable =
|
|
229
|
+
subFunc === 'write' || subFunc === 'populateTransaction'
|
|
195
230
|
// get the function to call
|
|
196
|
-
const func =
|
|
231
|
+
const func =
|
|
232
|
+
subFunc && !writeable ? mod[exportName][subFunc] : mod[exportName]
|
|
197
233
|
// get the dependencies to forward to the function as the first arg
|
|
198
|
-
|
|
234
|
+
let dependenciesToForward =
|
|
199
235
|
thisRef.forwardDependenciesFromArray<F>(dependencies)
|
|
236
|
+
|
|
237
|
+
// if func is write func, inject signer into dependencies
|
|
238
|
+
if (writeable) {
|
|
239
|
+
const options = (args[1] || {}) as WriteOptions
|
|
240
|
+
const signer =
|
|
241
|
+
options.signer ||
|
|
242
|
+
thisRef.provider?.getSigner(options.addressOrIndex)
|
|
243
|
+
const populate = subFunc === 'populateTransaction'
|
|
244
|
+
if (!signer) {
|
|
245
|
+
throw new Error('No signer specified')
|
|
246
|
+
}
|
|
247
|
+
delete options.addressOrIndex
|
|
248
|
+
delete options.signer
|
|
249
|
+
dependenciesToForward = { ...dependenciesToForward, signer }
|
|
250
|
+
return func(dependenciesToForward, args[0], options).then(
|
|
251
|
+
writeTx(signer, populate),
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
200
255
|
// return the function with the dependencies forwarded
|
|
201
256
|
return func(dependenciesToForward, ...args)
|
|
202
257
|
} else {
|
|
@@ -236,6 +291,13 @@ export class ENS {
|
|
|
236
291
|
'batch',
|
|
237
292
|
{ raw: mainFunc.raw as any, decode: mainFunc.decode as any },
|
|
238
293
|
)
|
|
294
|
+
} else if (subFunc === 'write') {
|
|
295
|
+
mainFunc.populateTransaction = this.importGenerator<F>(
|
|
296
|
+
path,
|
|
297
|
+
dependencies,
|
|
298
|
+
exportName,
|
|
299
|
+
'populateTransaction',
|
|
300
|
+
)
|
|
239
301
|
}
|
|
240
302
|
|
|
241
303
|
return mainFunc as Function
|
|
@@ -255,6 +317,25 @@ export class ENS {
|
|
|
255
317
|
): OmitFirstArg<F> =>
|
|
256
318
|
this.importGenerator<F>(path, dependencies, exportName) as OmitFirstArg<F>
|
|
257
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Generates a write wrapped function
|
|
322
|
+
* @param {string} path - The path of the exported function
|
|
323
|
+
* @param {FunctionDeps} dependencies - An array of ENS properties
|
|
324
|
+
* @param {string} exportName - The export name of the target function
|
|
325
|
+
* @returns {OmitFirstArg} - The generated wrapped function
|
|
326
|
+
*/
|
|
327
|
+
private generateWriteFunction = <F extends (...args: any) => any>(
|
|
328
|
+
path: string,
|
|
329
|
+
dependencies: FunctionDeps<F>,
|
|
330
|
+
exportName: string = 'default',
|
|
331
|
+
): WriteFunction<F> =>
|
|
332
|
+
this.importGenerator<F>(
|
|
333
|
+
path,
|
|
334
|
+
dependencies,
|
|
335
|
+
exportName,
|
|
336
|
+
'write',
|
|
337
|
+
) as WriteFunction<F>
|
|
338
|
+
|
|
258
339
|
/**
|
|
259
340
|
* Generates a wrapped function from raw and decode exports
|
|
260
341
|
* @param {string} path - The path of the exported function
|
|
@@ -321,6 +402,7 @@ export class ENS {
|
|
|
321
402
|
'gqlInstance',
|
|
322
403
|
'getName',
|
|
323
404
|
'resolverMulticallWrapper',
|
|
405
|
+
'multicallWrapper',
|
|
324
406
|
'_getAddr',
|
|
325
407
|
'_getContentHash',
|
|
326
408
|
'_getText',
|
|
@@ -453,54 +535,61 @@ export class ENS {
|
|
|
453
535
|
'multicallWrapper',
|
|
454
536
|
)
|
|
455
537
|
|
|
456
|
-
public setName = this.
|
|
538
|
+
public setName = this.generateWriteFunction<typeof setName>('setName', [
|
|
457
539
|
'contracts',
|
|
458
|
-
'provider',
|
|
459
540
|
])
|
|
460
541
|
|
|
461
|
-
public setRecords = this.
|
|
542
|
+
public setRecords = this.generateWriteFunction<typeof setRecords>(
|
|
543
|
+
'setRecords',
|
|
544
|
+
['contracts', 'provider', 'getResolver'],
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
public setRecord = this.generateWriteFunction<typeof setRecord>('setRecord', [
|
|
462
548
|
'contracts',
|
|
463
549
|
'provider',
|
|
464
550
|
'getResolver',
|
|
465
551
|
])
|
|
466
552
|
|
|
467
|
-
public setResolver = this.
|
|
553
|
+
public setResolver = this.generateWriteFunction<typeof setResolver>(
|
|
468
554
|
'setResolver',
|
|
469
|
-
['contracts'
|
|
555
|
+
['contracts'],
|
|
470
556
|
)
|
|
471
557
|
|
|
472
|
-
public transferName = this.
|
|
558
|
+
public transferName = this.generateWriteFunction<typeof transferName>(
|
|
473
559
|
'transferName',
|
|
474
|
-
['contracts'
|
|
560
|
+
['contracts'],
|
|
475
561
|
)
|
|
476
562
|
|
|
477
|
-
public wrapName = this.
|
|
563
|
+
public wrapName = this.generateWriteFunction<typeof wrapName>('wrapName', [
|
|
478
564
|
'contracts',
|
|
479
|
-
'provider',
|
|
480
565
|
])
|
|
481
566
|
|
|
482
|
-
public unwrapName = this.
|
|
483
|
-
'
|
|
484
|
-
'
|
|
485
|
-
|
|
567
|
+
public unwrapName = this.generateWriteFunction<typeof unwrapName>(
|
|
568
|
+
'unwrapName',
|
|
569
|
+
['contracts'],
|
|
570
|
+
)
|
|
486
571
|
|
|
487
|
-
public burnFuses = this.
|
|
572
|
+
public burnFuses = this.generateWriteFunction<typeof burnFuses>('burnFuses', [
|
|
488
573
|
'contracts',
|
|
489
|
-
'provider',
|
|
490
574
|
])
|
|
491
575
|
|
|
492
|
-
public createSubname = this.
|
|
576
|
+
public createSubname = this.generateWriteFunction<typeof createSubname>(
|
|
493
577
|
'createSubname',
|
|
494
|
-
['contracts'
|
|
578
|
+
['contracts'],
|
|
495
579
|
)
|
|
496
580
|
|
|
497
|
-
public deleteSubname = this.
|
|
581
|
+
public deleteSubname = this.generateWriteFunction<typeof deleteSubname>(
|
|
498
582
|
'deleteSubname',
|
|
499
|
-
['
|
|
583
|
+
['transferSubname'],
|
|
500
584
|
)
|
|
501
585
|
|
|
502
|
-
public transferSubname = this.
|
|
586
|
+
public transferSubname = this.generateWriteFunction<typeof transferSubname>(
|
|
503
587
|
'transferSubname',
|
|
504
|
-
['contracts'
|
|
588
|
+
['contracts'],
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
public getDNSOwner = this.generateFunction<typeof getDNSOwner>(
|
|
592
|
+
'getDNSOwner',
|
|
593
|
+
[],
|
|
505
594
|
)
|
|
506
595
|
}
|