@ensdomains/ensjs 3.0.0-alpha.20 → 3.0.0-alpha.21
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/{functions/renewName.js → contracts/bulkRenewal.js} +6 -14
- package/dist/cjs/contracts/getContractAddress.js +2 -1
- package/dist/cjs/contracts/index.js +5 -0
- package/dist/cjs/functions/deleteSubname.js +40 -8
- package/dist/cjs/functions/getPrice.js +55 -8
- package/dist/cjs/functions/getSubnames.js +30 -94
- package/dist/cjs/functions/renewNames.js +42 -0
- package/dist/cjs/generated/BulkRenewal.js +16 -0
- package/dist/cjs/generated/factories/BulkRenewal__factory.js +120 -0
- package/dist/cjs/generated/factories/index.js +2 -0
- package/dist/cjs/generated/index.js +2 -0
- package/dist/cjs/index.js +5 -4
- package/dist/esm/contracts/bulkRenewal.mjs +6 -0
- package/dist/esm/contracts/getContractAddress.mjs +2 -1
- package/dist/esm/contracts/index.mjs +5 -0
- package/dist/esm/functions/deleteSubname.mjs +40 -8
- package/dist/esm/functions/getPrice.mjs +56 -9
- package/dist/esm/functions/getSubnames.mjs +30 -94
- package/dist/esm/functions/renewNames.mjs +23 -0
- package/dist/esm/generated/BulkRenewal.mjs +0 -0
- package/dist/esm/generated/factories/BulkRenewal__factory.mjs +108 -0
- package/dist/esm/generated/factories/index.mjs +2 -0
- package/dist/esm/generated/index.mjs +2 -0
- package/dist/esm/index.mjs +5 -4
- package/dist/types/contracts/bulkRenewal.d.ts +3 -0
- package/dist/types/contracts/index.d.ts +1 -0
- package/dist/types/contracts/types.d.ts +1 -1
- package/dist/types/functions/deleteSubname.d.ts +5 -2
- package/dist/types/functions/getPrice.d.ts +2 -2
- package/dist/types/functions/getSubnames.d.ts +1 -1
- package/dist/types/functions/{renewName.d.ts → renewNames.d.ts} +2 -2
- package/dist/types/generated/BulkRenewal.d.ts +76 -0
- package/dist/types/generated/factories/BulkRenewal__factory.d.ts +32 -0
- package/dist/types/generated/factories/index.d.ts +1 -0
- package/dist/types/generated/index.d.ts +2 -0
- package/dist/types/index.d.ts +5 -5
- package/package.json +1 -1
- package/src/contracts/bulkRenewal.ts +6 -0
- package/src/contracts/getContractAddress.ts +1 -0
- package/src/contracts/index.ts +6 -0
- package/src/contracts/types.ts +1 -0
- package/src/functions/deleteSubname.ts +51 -11
- package/src/functions/getNames.test.ts +10 -1
- package/src/functions/getPrice.test.ts +52 -0
- package/src/functions/getPrice.ts +61 -9
- package/src/functions/getProfile.test.ts +5 -1
- package/src/functions/getSubnames.test.ts +669 -29
- package/src/functions/getSubnames.ts +39 -98
- package/src/functions/{renewName.test.ts → renewNames.test.ts} +22 -2
- package/src/functions/renewNames.ts +30 -0
- package/src/generated/BulkRenewal.ts +197 -0
- package/src/generated/factories/BulkRenewal__factory.ts +108 -0
- package/src/generated/factories/index.ts +1 -0
- package/src/generated/index.ts +2 -0
- package/src/index.ts +6 -5
- package/dist/esm/functions/renewName.mjs +0 -14
- package/src/functions/renewName.ts +0 -22
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BaseRegistrarImplementation__factory } from "./BaseRegistrarImplementation__factory";
|
|
2
|
+
export { BulkRenewal__factory } from "./BulkRenewal__factory";
|
|
2
3
|
export { DNSRegistrar__factory } from "./DNSRegistrar__factory";
|
|
3
4
|
export { DNSSECImpl__factory } from "./DNSSECImpl__factory";
|
|
4
5
|
export { DefaultReverseResolver__factory } from "./DefaultReverseResolver__factory";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { BaseRegistrarImplementation } from "./BaseRegistrarImplementation";
|
|
2
|
+
export type { BulkRenewal } from "./BulkRenewal";
|
|
2
3
|
export type { DNSRegistrar } from "./DNSRegistrar";
|
|
3
4
|
export type { DNSSECImpl } from "./DNSSECImpl";
|
|
4
5
|
export type { DefaultReverseResolver } from "./DefaultReverseResolver";
|
|
@@ -39,3 +40,4 @@ export { Multicall__factory } from "./factories/Multicall__factory";
|
|
|
39
40
|
export { NameWrapper__factory } from "./factories/NameWrapper__factory";
|
|
40
41
|
export { StaticMetadataService__factory } from "./factories/StaticMetadataService__factory";
|
|
41
42
|
export { UniversalResolver__factory } from "./factories/UniversalResolver__factory";
|
|
43
|
+
export { BulkRenewal__factory } from "./factories/BulkRenewal__factory";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type commitName from './functions/commitName';
|
|
|
8
8
|
import type createSubname from './functions/createSubname';
|
|
9
9
|
import type deleteSubname from './functions/deleteSubname';
|
|
10
10
|
import type registerName from './functions/registerName';
|
|
11
|
-
import type
|
|
11
|
+
import type renewNames from './functions/renewNames';
|
|
12
12
|
import type setName from './functions/setName';
|
|
13
13
|
import type setRecord from './functions/setRecord';
|
|
14
14
|
import type setRecords from './functions/setRecords';
|
|
@@ -367,7 +367,7 @@ export declare class ENS {
|
|
|
367
367
|
orderDirection?: "asc" | "desc" | undefined;
|
|
368
368
|
orderBy?: "labelName" | "createdAt" | undefined;
|
|
369
369
|
lastSubnames?: any[] | undefined;
|
|
370
|
-
|
|
370
|
+
search?: string | undefined;
|
|
371
371
|
}) => Promise<{
|
|
372
372
|
subnames: {
|
|
373
373
|
id: string;
|
|
@@ -401,11 +401,11 @@ export declare class ENS {
|
|
|
401
401
|
pageSize?: undefined;
|
|
402
402
|
})) => Promise<import("./functions/getNames").Name[]>;
|
|
403
403
|
getPrice: GeneratedRawFunction<{
|
|
404
|
-
raw: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">,
|
|
404
|
+
raw: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">, nameOrNames: string | string[], duration: number, legacy?: boolean | undefined) => Promise<{
|
|
405
405
|
to: string;
|
|
406
406
|
data: string;
|
|
407
407
|
}>;
|
|
408
|
-
decode: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">, data: string,
|
|
408
|
+
decode: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">, data: string, _nameOrNames: string | string[], _duration: number, legacy?: boolean | undefined) => Promise<{
|
|
409
409
|
base: ethers.BigNumber;
|
|
410
410
|
premium: ethers.BigNumber;
|
|
411
411
|
} | undefined>;
|
|
@@ -451,5 +451,5 @@ export declare class ENS {
|
|
|
451
451
|
transferSubname: WriteFunction<typeof transferSubname>;
|
|
452
452
|
commitName: WriteFunction<typeof commitName>;
|
|
453
453
|
registerName: WriteFunction<typeof registerName>;
|
|
454
|
-
|
|
454
|
+
renewNames: WriteFunction<typeof renewNames>;
|
|
455
455
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ethers } from 'ethers'
|
|
2
|
+
import { BulkRenewal__factory } from '../generated/factories/BulkRenewal__factory'
|
|
3
|
+
|
|
4
|
+
// Use a higher-order function to overide the address that is passed in from getContractAddress()
|
|
5
|
+
export default (provider: ethers.providers.JsonRpcProvider, address: string) =>
|
|
6
|
+
BulkRenewal__factory.connect(address, provider)
|
|
@@ -35,6 +35,7 @@ const addresses: Record<
|
|
|
35
35
|
'1': '0x580AF46E06DaaD47eb5940526FD64d95b815Cb70',
|
|
36
36
|
'4': '0x74e20bd2a1fe0cdbe45b9a1d89cb7e0a45b36376',
|
|
37
37
|
},
|
|
38
|
+
BulkRenewal: '0xfF252725f6122A92551A5FA9a6b6bf10eb0Be035',
|
|
38
39
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
39
40
|
}
|
|
40
41
|
|
package/src/contracts/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import getRegistry from './registry'
|
|
|
9
9
|
import getReverseRegistrar from './reverseRegistrar'
|
|
10
10
|
import { ContractName } from './types'
|
|
11
11
|
import getUniversalResolver from './universalResolver'
|
|
12
|
+
import getBulkRenewal from './bulkRenewal'
|
|
12
13
|
|
|
13
14
|
export default class ContractManager {
|
|
14
15
|
private provider: ethers.providers.Provider
|
|
@@ -73,4 +74,9 @@ export default class ContractManager {
|
|
|
73
74
|
)
|
|
74
75
|
|
|
75
76
|
public getMulticall = this.generateContractGetter('Multicall', getMulticall)
|
|
77
|
+
|
|
78
|
+
public getBulkRenewal = this.generateContractGetter(
|
|
79
|
+
'BulkRenewal',
|
|
80
|
+
getBulkRenewal,
|
|
81
|
+
)
|
|
76
82
|
}
|
package/src/contracts/types.ts
CHANGED
|
@@ -1,17 +1,57 @@
|
|
|
1
|
+
import { ethers } from 'ethers'
|
|
1
2
|
import { ENSArgs } from '..'
|
|
3
|
+
import { namehash } from '../utils/normalise'
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
contract: 'registry' | 'nameWrapper'
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
export default async function (
|
|
4
|
-
{
|
|
10
|
+
{ contracts, signer }: ENSArgs<'contracts' | 'signer' | 'getExpiry'>,
|
|
5
11
|
name: string,
|
|
6
|
-
{
|
|
7
|
-
contract,
|
|
8
|
-
}: {
|
|
9
|
-
contract: 'registry' | 'nameWrapper'
|
|
10
|
-
},
|
|
12
|
+
{ contract }: Args,
|
|
11
13
|
) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
const labels = name.split('.')
|
|
15
|
+
|
|
16
|
+
if (labels.length !== 3) {
|
|
17
|
+
throw new Error('ENS.js currently only supports deleting 2LDs, not TLDs')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (labels[2] !== 'eth') {
|
|
21
|
+
throw new Error('ENS.js currently only supports deleting .eth 2LDs')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const label = labels.shift() as string
|
|
25
|
+
const labelhash = ethers.utils.solidityKeccak256(['string'], [label])
|
|
26
|
+
const parentNodehash = namehash(labels.join('.'))
|
|
27
|
+
|
|
28
|
+
switch (contract) {
|
|
29
|
+
case 'registry': {
|
|
30
|
+
const registry = (await contracts!.getRegistry()!).connect(signer)
|
|
31
|
+
|
|
32
|
+
return registry.populateTransaction.setSubnodeRecord(
|
|
33
|
+
parentNodehash,
|
|
34
|
+
labelhash,
|
|
35
|
+
'0x0000000000000000000000000000000000000000',
|
|
36
|
+
'0x0000000000000000000000000000000000000000',
|
|
37
|
+
0,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
case 'nameWrapper': {
|
|
41
|
+
const nameWrapper = (await contracts!.getNameWrapper()!).connect(signer)
|
|
42
|
+
|
|
43
|
+
return nameWrapper.populateTransaction.setSubnodeRecord(
|
|
44
|
+
parentNodehash,
|
|
45
|
+
label,
|
|
46
|
+
'0x0000000000000000000000000000000000000000',
|
|
47
|
+
'0x0000000000000000000000000000000000000000',
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
0,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
throw new Error(`Unknown contract: ${contract}`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
17
57
|
}
|
|
@@ -30,9 +30,12 @@ const letterItems = [
|
|
|
30
30
|
|
|
31
31
|
const domainLetterItems = [
|
|
32
32
|
'[',
|
|
33
|
+
'x',
|
|
33
34
|
'w',
|
|
34
35
|
't',
|
|
35
36
|
't',
|
|
37
|
+
'l',
|
|
38
|
+
'a',
|
|
36
39
|
'9',
|
|
37
40
|
'8',
|
|
38
41
|
'7',
|
|
@@ -137,7 +140,13 @@ describe('getNames', () => {
|
|
|
137
140
|
type: 'owner',
|
|
138
141
|
page: 3,
|
|
139
142
|
})
|
|
140
|
-
expect(pageFour).toHaveLength(
|
|
143
|
+
expect(pageFour).toHaveLength(10)
|
|
144
|
+
const pageFive = await ensInstance.getNames({
|
|
145
|
+
address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
|
|
146
|
+
type: 'owner',
|
|
147
|
+
page: 4,
|
|
148
|
+
})
|
|
149
|
+
expect(pageFive).toHaveLength(totalOwnedNames % 10)
|
|
141
150
|
})
|
|
142
151
|
describe('orderBy', () => {
|
|
143
152
|
describe('registrations', () => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ENS } from '..'
|
|
2
|
+
import setup from '../tests/setup'
|
|
3
|
+
|
|
4
|
+
let ensInstance: ENS
|
|
5
|
+
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
;({ ensInstance } = await setup())
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
describe('getPrice', () => {
|
|
11
|
+
it('should return a base and premium price for an address', async () => {
|
|
12
|
+
const { base, premium } = (await ensInstance.getPrice(
|
|
13
|
+
'test123',
|
|
14
|
+
86400,
|
|
15
|
+
false,
|
|
16
|
+
))!
|
|
17
|
+
expect(base.toNumber()).toBe(86400)
|
|
18
|
+
expect(premium.toNumber()).toBe(0)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('should return a base and premium price for an array of names', async () => {
|
|
22
|
+
const { base, premium } = (await ensInstance.getPrice(
|
|
23
|
+
['test123', 'to-be-renewed'],
|
|
24
|
+
86400,
|
|
25
|
+
false,
|
|
26
|
+
))!
|
|
27
|
+
expect(base.toNumber()).toBe(86400 * 2)
|
|
28
|
+
expect(premium.toNumber()).toBe(0)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('legacy mode', () => {
|
|
32
|
+
it('should return a base and premium price for an address', async () => {
|
|
33
|
+
const { base, premium } = (await ensInstance.getPrice(
|
|
34
|
+
'test123',
|
|
35
|
+
86400,
|
|
36
|
+
true,
|
|
37
|
+
))!
|
|
38
|
+
expect(base.toNumber()).toBe(86400)
|
|
39
|
+
expect(premium.toNumber()).toBe(0)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should return a base and premium price for an array of names', async () => {
|
|
43
|
+
const { base, premium } = (await ensInstance.getPrice(
|
|
44
|
+
['test123', 'to-be-renewed'],
|
|
45
|
+
86400,
|
|
46
|
+
true,
|
|
47
|
+
))!
|
|
48
|
+
expect(base.toNumber()).toBe(86400 * 2)
|
|
49
|
+
expect(premium.toNumber()).toBe(0)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -3,16 +3,44 @@ import { ENSArgs } from '..'
|
|
|
3
3
|
|
|
4
4
|
const raw = async (
|
|
5
5
|
{ contracts, multicallWrapper }: ENSArgs<'contracts' | 'multicallWrapper'>,
|
|
6
|
-
|
|
6
|
+
nameOrNames: string | string[],
|
|
7
7
|
duration: number,
|
|
8
8
|
legacy?: boolean,
|
|
9
9
|
) => {
|
|
10
|
+
const names = Array.isArray(nameOrNames) ? nameOrNames : [nameOrNames]
|
|
11
|
+
|
|
12
|
+
if (names.length > 1) {
|
|
13
|
+
const bulkRenewal = await contracts?.getBulkRenewal()!
|
|
14
|
+
const baseCall = {
|
|
15
|
+
to: bulkRenewal.address,
|
|
16
|
+
data: bulkRenewal.interface.encodeFunctionData('rentPrice', [
|
|
17
|
+
names,
|
|
18
|
+
duration,
|
|
19
|
+
]),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (legacy) {
|
|
23
|
+
return multicallWrapper.raw([
|
|
24
|
+
baseCall,
|
|
25
|
+
{
|
|
26
|
+
to: bulkRenewal.address,
|
|
27
|
+
data: bulkRenewal.interface.encodeFunctionData('rentPrice', [
|
|
28
|
+
names,
|
|
29
|
+
0,
|
|
30
|
+
]),
|
|
31
|
+
},
|
|
32
|
+
])
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return baseCall
|
|
36
|
+
}
|
|
37
|
+
|
|
10
38
|
const controller = await contracts?.getEthRegistrarController()!
|
|
11
39
|
|
|
12
40
|
const baseCall = {
|
|
13
41
|
to: controller.address,
|
|
14
42
|
data: controller.interface.encodeFunctionData('rentPrice', [
|
|
15
|
-
|
|
43
|
+
names[0],
|
|
16
44
|
duration,
|
|
17
45
|
]),
|
|
18
46
|
}
|
|
@@ -22,27 +50,49 @@ const raw = async (
|
|
|
22
50
|
baseCall,
|
|
23
51
|
{
|
|
24
52
|
to: controller.address,
|
|
25
|
-
data: controller.interface.encodeFunctionData('rentPrice', [
|
|
53
|
+
data: controller.interface.encodeFunctionData('rentPrice', [
|
|
54
|
+
names[0],
|
|
55
|
+
0,
|
|
56
|
+
]),
|
|
26
57
|
},
|
|
27
58
|
])
|
|
28
59
|
}
|
|
29
|
-
|
|
30
60
|
return baseCall
|
|
31
61
|
}
|
|
32
62
|
|
|
33
63
|
const decode = async (
|
|
34
64
|
{ contracts, multicallWrapper }: ENSArgs<'contracts' | 'multicallWrapper'>,
|
|
35
65
|
data: string,
|
|
36
|
-
|
|
37
|
-
|
|
66
|
+
_nameOrNames: string | string[],
|
|
67
|
+
_duration: number,
|
|
38
68
|
legacy?: boolean,
|
|
39
69
|
) => {
|
|
40
70
|
if (data === null) return
|
|
41
|
-
const controller = await contracts?.getEthRegistrarController()!
|
|
42
71
|
try {
|
|
43
72
|
let base: BigNumber
|
|
44
73
|
let premium: BigNumber
|
|
45
|
-
|
|
74
|
+
|
|
75
|
+
const isBulkRenewal = Array.isArray(_nameOrNames) && _nameOrNames.length > 1
|
|
76
|
+
if (isBulkRenewal && legacy) {
|
|
77
|
+
const result = await multicallWrapper.decode(data)
|
|
78
|
+
const [price] = utils.defaultAbiCoder.decode(
|
|
79
|
+
['uint256'],
|
|
80
|
+
result[0].returnData,
|
|
81
|
+
) as [BigNumber]
|
|
82
|
+
;[premium] = utils.defaultAbiCoder.decode(
|
|
83
|
+
['uint256'],
|
|
84
|
+
result[1].returnData,
|
|
85
|
+
) as [BigNumber]
|
|
86
|
+
base = price.sub(premium)
|
|
87
|
+
} else if (isBulkRenewal) {
|
|
88
|
+
const bulkRenewal = await contracts?.getBulkRenewal()!
|
|
89
|
+
const result = bulkRenewal.interface.decodeFunctionResult(
|
|
90
|
+
'rentPrice',
|
|
91
|
+
data,
|
|
92
|
+
)
|
|
93
|
+
;[base] = result
|
|
94
|
+
premium = BigNumber.from(0)
|
|
95
|
+
} else if (!isBulkRenewal && legacy) {
|
|
46
96
|
const result = await multicallWrapper.decode(data)
|
|
47
97
|
const [price] = utils.defaultAbiCoder.decode(
|
|
48
98
|
['uint256'],
|
|
@@ -54,10 +104,12 @@ const decode = async (
|
|
|
54
104
|
) as [BigNumber]
|
|
55
105
|
base = price.sub(premium)
|
|
56
106
|
} else {
|
|
57
|
-
|
|
107
|
+
const controller = await contracts?.getEthRegistrarController()!
|
|
108
|
+
const result = controller.interface.decodeFunctionResult(
|
|
58
109
|
'rentPrice',
|
|
59
110
|
data,
|
|
60
111
|
)
|
|
112
|
+
;[base, premium] = result[0] as [BigNumber, BigNumber]
|
|
61
113
|
}
|
|
62
114
|
return {
|
|
63
115
|
base,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ethers } from 'ethers'
|
|
2
|
+
import dotenv from 'dotenv'
|
|
2
3
|
import { ENS } from '..'
|
|
3
4
|
import setup from '../tests/setup'
|
|
4
5
|
|
|
6
|
+
dotenv.config()
|
|
7
|
+
|
|
5
8
|
let ensInstance: ENS
|
|
6
9
|
let revert: Awaited<ReturnType<typeof setup>>['revert']
|
|
7
10
|
let provider: ethers.providers.JsonRpcProvider
|
|
@@ -120,13 +123,14 @@ describe('getProfile', () => {
|
|
|
120
123
|
describe('with an old resolver', () => {
|
|
121
124
|
it('should use fallback methods for a name with an older resolver (no multicall)', async () => {
|
|
122
125
|
const result = await ensInstance.getProfile('with-legacy-resolver.eth')
|
|
126
|
+
const deploymentAddresses = JSON.parse(process.env.DEPLOYMENT_ADDRESSES!)
|
|
123
127
|
expect(result).toBeDefined()
|
|
124
128
|
if (result) {
|
|
125
129
|
expect(result.address).toBe(
|
|
126
130
|
'0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
|
|
127
131
|
)
|
|
128
132
|
expect(result.resolverAddress).toBe(
|
|
129
|
-
|
|
133
|
+
deploymentAddresses.NoMulticallResolver.toLowerCase(),
|
|
130
134
|
)
|
|
131
135
|
}
|
|
132
136
|
})
|