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