@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.
Files changed (147) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/GqlManager.d.ts +3 -0
  3. package/dist/cjs/GqlManager.js +62 -2
  4. package/dist/cjs/functions/burnFuses.d.ts +3 -2
  5. package/dist/cjs/functions/burnFuses.js +4 -8
  6. package/dist/cjs/functions/createSubname.d.ts +1 -5
  7. package/dist/cjs/functions/createSubname.js +5 -8
  8. package/dist/cjs/functions/deleteSubname.d.ts +3 -3
  9. package/dist/cjs/functions/deleteSubname.js +5 -2
  10. package/dist/cjs/functions/getDNSOwner.d.ts +7 -0
  11. package/dist/cjs/functions/getDNSOwner.js +81 -0
  12. package/dist/cjs/functions/getFuses.js +3 -2
  13. package/dist/cjs/functions/getOwner.js +7 -6
  14. package/dist/cjs/functions/getProfile.d.ts +4 -1
  15. package/dist/cjs/functions/getProfile.js +102 -24
  16. package/dist/cjs/functions/getRecords.d.ts +1 -0
  17. package/dist/cjs/functions/getSpecificRecord.js +22 -5
  18. package/dist/cjs/functions/getSubnames.js +6 -6
  19. package/dist/cjs/functions/setName.d.ts +4 -3
  20. package/dist/cjs/functions/setName.js +5 -10
  21. package/dist/cjs/functions/setRecord.d.ts +18 -0
  22. package/dist/cjs/functions/setRecord.js +27 -0
  23. package/dist/cjs/functions/setRecords.d.ts +4 -2
  24. package/dist/cjs/functions/setRecords.js +14 -12
  25. package/dist/cjs/functions/setResolver.d.ts +4 -4
  26. package/dist/cjs/functions/setResolver.js +6 -12
  27. package/dist/cjs/functions/transferName.d.ts +4 -3
  28. package/dist/cjs/functions/transferName.js +9 -13
  29. package/dist/cjs/functions/transferSubname.d.ts +4 -3
  30. package/dist/cjs/functions/transferSubname.js +5 -8
  31. package/dist/cjs/functions/unwrapName.d.ts +4 -3
  32. package/dist/cjs/functions/unwrapName.js +5 -9
  33. package/dist/cjs/functions/wrapName.d.ts +5 -3
  34. package/dist/cjs/functions/wrapName.js +8 -12
  35. package/dist/cjs/index.d.ts +48 -46
  36. package/dist/cjs/index.js +43 -19
  37. package/dist/cjs/utils/labels.js +5 -4
  38. package/dist/cjs/utils/makeHashIndexes.js +2 -2
  39. package/dist/cjs/utils/normalise.d.ts +1 -0
  40. package/dist/cjs/utils/normalise.js +27 -1
  41. package/dist/cjs/utils/recordHelpers.d.ts +3 -0
  42. package/dist/cjs/utils/recordHelpers.js +42 -15
  43. package/dist/cjs/utils/registerHelpers.js +3 -4
  44. package/dist/cjs/utils/writeTx.d.ts +4 -0
  45. package/dist/cjs/utils/writeTx.js +3 -0
  46. package/dist/esm/GqlManager.d.ts +3 -0
  47. package/dist/esm/GqlManager.js +58 -2
  48. package/dist/esm/functions/burnFuses.d.ts +3 -2
  49. package/dist/esm/functions/burnFuses.js +4 -8
  50. package/dist/esm/functions/createSubname.d.ts +1 -5
  51. package/dist/esm/functions/createSubname.js +5 -8
  52. package/dist/esm/functions/deleteSubname.d.ts +3 -3
  53. package/dist/esm/functions/deleteSubname.js +5 -2
  54. package/dist/esm/functions/getDNSOwner.d.ts +7 -0
  55. package/dist/esm/functions/getDNSOwner.js +51 -0
  56. package/dist/esm/functions/getFuses.js +4 -3
  57. package/dist/esm/functions/getOwner.js +7 -6
  58. package/dist/esm/functions/getProfile.d.ts +4 -1
  59. package/dist/esm/functions/getProfile.js +102 -24
  60. package/dist/esm/functions/getRecords.d.ts +1 -0
  61. package/dist/esm/functions/getSpecificRecord.js +22 -5
  62. package/dist/esm/functions/getSubnames.js +3 -3
  63. package/dist/esm/functions/setName.d.ts +4 -3
  64. package/dist/esm/functions/setName.js +5 -10
  65. package/dist/esm/functions/setRecord.d.ts +18 -0
  66. package/dist/esm/functions/setRecord.js +24 -0
  67. package/dist/esm/functions/setRecords.d.ts +4 -2
  68. package/dist/esm/functions/setRecords.js +14 -12
  69. package/dist/esm/functions/setResolver.d.ts +4 -4
  70. package/dist/esm/functions/setResolver.js +6 -12
  71. package/dist/esm/functions/transferName.d.ts +4 -3
  72. package/dist/esm/functions/transferName.js +9 -13
  73. package/dist/esm/functions/transferSubname.d.ts +4 -3
  74. package/dist/esm/functions/transferSubname.js +5 -8
  75. package/dist/esm/functions/unwrapName.d.ts +4 -3
  76. package/dist/esm/functions/unwrapName.js +5 -9
  77. package/dist/esm/functions/wrapName.d.ts +5 -3
  78. package/dist/esm/functions/wrapName.js +8 -12
  79. package/dist/esm/index.d.ts +48 -46
  80. package/dist/esm/index.js +43 -19
  81. package/dist/esm/utils/labels.js +5 -4
  82. package/dist/esm/utils/makeHashIndexes.js +2 -2
  83. package/dist/esm/utils/normalise.d.ts +1 -0
  84. package/dist/esm/utils/normalise.js +25 -0
  85. package/dist/esm/utils/recordHelpers.d.ts +3 -0
  86. package/dist/esm/utils/recordHelpers.js +40 -14
  87. package/dist/esm/utils/registerHelpers.js +3 -4
  88. package/dist/esm/utils/writeTx.d.ts +4 -0
  89. package/dist/esm/utils/writeTx.js +1 -0
  90. package/package.json +15 -7
  91. package/src/@types/dns-packet/index.d.ts +114 -0
  92. package/src/GqlManager.test.ts +170 -0
  93. package/src/GqlManager.ts +67 -2
  94. package/src/{tests → functions}/batch.test.ts +1 -1
  95. package/src/{tests → functions}/batchWrappers.test.ts +1 -1
  96. package/src/{tests → functions}/burnFuses.test.ts +12 -10
  97. package/src/functions/burnFuses.ts +9 -11
  98. package/src/{tests → functions}/createSubname.test.ts +12 -16
  99. package/src/functions/createSubname.ts +7 -13
  100. package/src/{tests → functions}/deleteSubname.test.ts +32 -32
  101. package/src/functions/deleteSubname.ts +9 -12
  102. package/src/functions/getDNSOwner.test.ts +122 -0
  103. package/src/functions/getDNSOwner.ts +61 -0
  104. package/src/{tests → functions}/getExpiry.test.ts +1 -1
  105. package/src/{tests → functions}/getFuses.test.ts +12 -10
  106. package/src/functions/getFuses.ts +4 -3
  107. package/src/{tests → functions}/getHistory.test.ts +1 -1
  108. package/src/{tests → functions}/getName.test.ts +1 -1
  109. package/src/{tests → functions}/getNames.test.ts +1 -1
  110. package/src/{tests → functions}/getOwner.test.ts +14 -2
  111. package/src/functions/getOwner.ts +7 -7
  112. package/src/{tests → functions}/getProfile.test.ts +45 -12
  113. package/src/functions/getProfile.ts +151 -24
  114. package/src/functions/getRecords.ts +1 -0
  115. package/src/{tests → functions}/getResolver.test.ts +1 -1
  116. package/src/{tests → functions}/getSpecificRecord.test.ts +1 -1
  117. package/src/functions/getSpecificRecord.ts +28 -8
  118. package/src/{tests → functions}/getSubnames.test.ts +1 -1
  119. package/src/functions/getSubnames.ts +68 -66
  120. package/src/{tests → functions}/makeCommitment.test.ts +1 -1
  121. package/src/functions/normalise.test.ts +22 -0
  122. package/src/{tests → functions}/setName.test.ts +3 -2
  123. package/src/functions/setName.ts +15 -17
  124. package/src/functions/setRecord.test.ts +100 -0
  125. package/src/functions/setRecord.ts +63 -0
  126. package/src/{tests → functions}/setRecords.test.ts +12 -10
  127. package/src/functions/setRecords.ts +22 -16
  128. package/src/{tests → functions}/setResolver.test.ts +12 -15
  129. package/src/functions/setResolver.ts +15 -20
  130. package/src/{tests → functions}/transferName.test.ts +30 -31
  131. package/src/functions/transferName.ts +19 -22
  132. package/src/{tests → functions}/transferSubname.test.ts +34 -34
  133. package/src/functions/transferSubname.ts +21 -13
  134. package/src/{tests → functions}/unwrapName.test.ts +24 -23
  135. package/src/functions/unwrapName.ts +20 -15
  136. package/src/{tests → functions}/wrapName.test.ts +19 -19
  137. package/src/functions/wrapName.ts +20 -22
  138. package/src/index.ts +115 -26
  139. package/src/tests/populateTransaction.test.ts +40 -0
  140. package/src/tests/signerInjection.test.ts +46 -0
  141. package/src/tests/withProvider.test.ts +1 -1
  142. package/src/utils/labels.ts +6 -4
  143. package/src/utils/makeHashIndexes.ts +4 -4
  144. package/src/utils/normalise.ts +29 -0
  145. package/src/utils/recordHelpers.ts +52 -18
  146. package/src/utils/registerHelpers.ts +3 -4
  147. package/src/utils/writeTx.ts +6 -0
@@ -1,6 +1,7 @@
1
- import { ethers, utils } from 'ethers'
1
+ import { ethers } from 'ethers'
2
2
  import { ENS } from '..'
3
- import setup from './setup'
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
- 'registry',
35
- accounts[1],
36
- { addressOrIndex: 0 },
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(utils.namehash('test.parthtejpal.eth'))
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
- 'parthtejpal.eth',
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 createSubnameTx.wait()
58
-
59
- const tx = await ENSInstance.transferSubname(
51
+ await wrapNameTx.wait()
52
+ const createSubnameTx = await ENSInstance.createSubname(
60
53
  'test.parthtejpal.eth',
61
- 'nameWrapper',
62
- accounts[1],
63
- { addressOrIndex: 0 },
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, provider }: ENSArgs<'contracts' | 'provider'>,
6
+ { contracts, signer }: ENSArgs<'contracts' | 'signer'>,
6
7
  name: string,
7
- contract: 'registry' | 'nameWrapper',
8
- address: string,
9
- options?: { addressOrIndex?: string | number },
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 = ethers.utils.namehash(labels.join('.'))
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(parentNodehash, labelhash, address)
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(parentNodehash, label, address, '0')
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 './setup'
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
- 'parthtejpal.eth',
26
- accounts[0],
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
- 'parthtejpal.eth',
32
- accounts[0],
33
- accounts[0],
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
- 'parthtejpal.eth',
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', accounts[0])
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(utils.namehash('test.parthtejpal.eth'))
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, provider }: ENSArgs<'contracts' | 'provider'>,
6
+ { contracts, signer }: ENSArgs<'contracts' | 'signer'>,
6
7
  name: string,
7
- newController: string,
8
- newRegistrant?: string,
9
- options?: { addressOrIndex?: string | number },
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 = utils.namehash(labels.slice(1).join('.'))
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(labelhash, newRegistrant, newController)
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(parentNodehash, labelhash, newController)
37
+ return nameWrapper.populateTransaction.unwrap(
38
+ parentNodehash,
39
+ labelhash,
40
+ newController,
41
+ )
37
42
  }
38
43
  }
@@ -1,7 +1,8 @@
1
- import { BigNumber, ethers, utils } from '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 setup from './setup'
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', accounts[0])
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', accounts[0], {
38
- cannotUnwrap: true,
39
- cannotSetTtl: true,
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
- utils.namehash('parthtejpal.eth'),
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
- 'parthtejpal.eth',
53
- accounts[0],
54
- undefined,
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', 'uint96', '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['safeTransferFrom(address,address,uint256,bytes)'](
27
- address,
28
- nameWrapper.address,
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, provider }: ENSArgs<'contracts' | 'provider'>,
63
+ { contracts, signer, populate }: ENSArgs<'contracts' | 'signer' | 'populate'>,
66
64
  name: string,
67
- wrappedOwner: string,
68
- fuseOptions?: FuseOptions | string | number,
69
- resolverAddress?: string,
70
- options?: { addressOrIndex?: string | number },
65
+ {
66
+ wrappedOwner,
67
+ fuseOptions,
68
+ resolverAddress,
69
+ }: {
70
+ wrappedOwner: string
71
+ fuseOptions?: FuseOptions | string | number
72
+ resolverAddress?: string
73
+ },
71
74
  ) {
72
- const signer = provider?.getSigner(options?.addressOrIndex)
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 { ethers } from 'ethers'
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?: 'raw' | 'decode' | 'combine' | 'batch',
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 = subFunc ? mod[exportName][subFunc] : mod[exportName]
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
- const dependenciesToForward =
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.generateFunction<typeof setName>('setName', [
538
+ public setName = this.generateWriteFunction<typeof setName>('setName', [
457
539
  'contracts',
458
- 'provider',
459
540
  ])
460
541
 
461
- public setRecords = this.generateFunction<typeof setRecords>('setRecords', [
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.generateFunction<typeof setResolver>(
553
+ public setResolver = this.generateWriteFunction<typeof setResolver>(
468
554
  'setResolver',
469
- ['contracts', 'provider'],
555
+ ['contracts'],
470
556
  )
471
557
 
472
- public transferName = this.generateFunction<typeof transferName>(
558
+ public transferName = this.generateWriteFunction<typeof transferName>(
473
559
  'transferName',
474
- ['contracts', 'provider'],
560
+ ['contracts'],
475
561
  )
476
562
 
477
- public wrapName = this.generateFunction<typeof wrapName>('wrapName', [
563
+ public wrapName = this.generateWriteFunction<typeof wrapName>('wrapName', [
478
564
  'contracts',
479
- 'provider',
480
565
  ])
481
566
 
482
- public unwrapName = this.generateFunction<typeof unwrapName>('unwrapName', [
483
- 'contracts',
484
- 'provider',
485
- ])
567
+ public unwrapName = this.generateWriteFunction<typeof unwrapName>(
568
+ 'unwrapName',
569
+ ['contracts'],
570
+ )
486
571
 
487
- public burnFuses = this.generateFunction<typeof burnFuses>('burnFuses', [
572
+ public burnFuses = this.generateWriteFunction<typeof burnFuses>('burnFuses', [
488
573
  'contracts',
489
- 'provider',
490
574
  ])
491
575
 
492
- public createSubname = this.generateFunction<typeof createSubname>(
576
+ public createSubname = this.generateWriteFunction<typeof createSubname>(
493
577
  'createSubname',
494
- ['contracts', 'provider'],
578
+ ['contracts'],
495
579
  )
496
580
 
497
- public deleteSubname = this.generateFunction<typeof deleteSubname>(
581
+ public deleteSubname = this.generateWriteFunction<typeof deleteSubname>(
498
582
  'deleteSubname',
499
- ['contracts', 'provider', 'transferSubname'],
583
+ ['transferSubname'],
500
584
  )
501
585
 
502
- public transferSubname = this.generateFunction<typeof transferSubname>(
586
+ public transferSubname = this.generateWriteFunction<typeof transferSubname>(
503
587
  'transferSubname',
504
- ['contracts', 'provider'],
588
+ ['contracts'],
589
+ )
590
+
591
+ public getDNSOwner = this.generateFunction<typeof getDNSOwner>(
592
+ 'getDNSOwner',
593
+ [],
505
594
  )
506
595
  }