Skip to content

Commit

Permalink
Merge pull request #98 from ensdomains/feat/static-ens
Browse files Browse the repository at this point in the history
feat: `StaticENS` class
  • Loading branch information
TateB authored Jan 16, 2023
2 parents 38df6bf + 3c05bb7 commit 79111c6
Show file tree
Hide file tree
Showing 105 changed files with 9,766 additions and 9,258 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
strategy:
matrix:
node-version: [16]
type: ['static', 'dynamic']
steps:
- uses: actions/checkout@v3

Expand All @@ -26,6 +27,8 @@ jobs:

- name: Run tests
run: pnpm -F @ensdomains/ensjs tenv start
env:
STATIC_ENS: ${{ matrix.type == 'static' }}
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"resolutions": {
"@nomiclabs/hardhat-ethers": "npm:[email protected]"
},
"dependencies": {
"ethers": "^5.6.1"
},
"dependenciesMeta": {
"ens-contracts": {
"built": false,
Expand Down
3 changes: 2 additions & 1 deletion packages/ensjs/deploy/00_deploy_bulk_renewal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */

import { Interface, namehash } from 'ethers/lib/utils'
import { Interface } from '@ethersproject/abi'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { namehash } from '../src/utils/normalise'

const { makeInterfaceId } = require('@openzeppelin/test-helpers')

Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/deploy/00_legacy_registry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */

import { namehash } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { labelhash } from '../src/utils/labels'
import { namehash } from '../src/utils/normalise'

const ZERO_HASH =
'0x0000000000000000000000000000000000000000000000000000000000000000'
Expand Down
2 changes: 1 addition & 1 deletion packages/ensjs/ens-test-env.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
deployCommand: 'pnpm hardhat deploy',
scripts: [
{
command: 'pnpm test',
command: process.env.STATIC_ENS ? 'pnpm test:static' : 'pnpm test',
name: 'jest',
prefixColor: 'yellow.bold',
finishOnExit: true,
Expand Down
9 changes: 6 additions & 3 deletions packages/ensjs/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ esbuild.build({
setup(build) {
build.onResolve({ filter: /.*/ }, (args) => {
if (args.importer) {
if (args.path.startsWith('ethers/'))
return { path: args.path + '.js', external: true }
if (args.path.match(/^@ethersproject\/.*\//))
return {
path: args.path.replace('/lib/', '/lib.esm/') + '.js',
external: true,
}
if (args.path.startsWith('./') || args.path.startsWith('../'))
return { path: args.path + '.mjs', external: true }
return { path: args.path, external: true }
Expand All @@ -56,7 +59,7 @@ esbuild.build({
build.onResolve({ filter: /.*/ }, (args) => {
if (args.importer) {
if (
args.path.startsWith('ethers/') ||
args.path.match(/^@ethersproject\/.*\//) ||
args.path.startsWith('./') ||
args.path.startsWith('../')
)
Expand Down
35 changes: 31 additions & 4 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"typesVersions": {
"*": {
"static": [
"./dist/types/static.d.ts"
],
"contracts/*": [
"./dist/types/contracts/*"
],
Expand Down Expand Up @@ -58,6 +61,7 @@
"generate-abis": "hardhat export-abi",
"start": "ts-node --files src/index.test.ts",
"test": "jest --run-in-band",
"test:static": "STATIC_ENS=true jest --run-in-band",
"test:watch": "jest --watch --run-in-band",
"test:specific": "ts-node --files ",
"clean": "rm -rf ./dist ./README.md ./LICENSE",
Expand All @@ -74,18 +78,29 @@
"@ensdomains/dnsprovejs": "^0.4.1",
"@ensdomains/dnssecoraclejs": "^0.2.7",
"dns-packet": "^5.3.1",
"ethers": "^5.6.1",
"graphql": "^16.3.0",
"graphql-request": "next",
"idna-uts46-hx": "3.4.0",
"traverse": "^0.6.6"
},
"devDependencies": {
"ethers": "^5.7.2",
"@ensdomains/buffer": "^0.0.13",
"@ensdomains/ens-contracts": "^0.0.15",
"@ensdomains/ens-test-env": "workspace:*",
"@ethersproject/abi": "^5.6.0",
"@ethersproject/providers": "^5.6.2",
"@ethersproject/abi": "^5.6.4",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/solidity": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/web": "^5.7.1",
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
"@openzeppelin/contracts": "^4.5.0",
"@openzeppelin/test-helpers": "^0.5.16",
Expand Down Expand Up @@ -117,6 +132,18 @@
"wait-on": "^6.0.1"
},
"peerDependencies": {
"ethers": "*"
"@ethersproject/abi": "^5.6.4",
"@ethersproject/abstract-provider": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/solidity": "^5.7.0",
"@ethersproject/strings": "^5.7.0",
"@ethersproject/transactions": "^5.7.0",
"@ethersproject/web": "^5.7.1"
}
}
22 changes: 15 additions & 7 deletions packages/ensjs/src/GqlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
SelectionSetNode,
visit as Visit,
} from 'graphql'
import type { gql, GraphQLClient } from 'graphql-request'
import type Traverse from 'traverse'
import { namehash } from './utils/normalise'

Expand Down Expand Up @@ -78,9 +79,17 @@ export const responseMiddleware =

export default class GqlManager {
// eslint-disable-next-line class-methods-use-this
public gql: any = () => null
public gql: typeof gql | ((query: TemplateStringsArray) => string) = (
query: TemplateStringsArray,
) => query.join()

public client?: any | null = null
public client:
| GraphQLClient
| {
request: () => Promise<null>
} = {
request: () => Promise.resolve(null),
}

public setUrl = async (url: string | null) => {
if (url) {
Expand All @@ -96,11 +105,10 @@ export default class GqlManager {
})
this.gql = imported.gql
} else {
this.client = null
this.gql = () => null
this.client = {
request: () => Promise.resolve(null),
}
this.gql = (query: TemplateStringsArray) => query.join()
}
}

public request = (...arg: any[]) =>
this.client ? this.client.request(...arg) : null
}
4 changes: 2 additions & 2 deletions packages/ensjs/src/contracts/baseRegistrar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import type { JsonRpcProvider } from '@ethersproject/providers'
import { BaseRegistrarImplementation__factory } from '../generated/factories/BaseRegistrarImplementation__factory'

export default (provider: ethers.providers.JsonRpcProvider, address: string) =>
export default (provider: JsonRpcProvider, address: string) =>
BaseRegistrarImplementation__factory.connect(address, provider)
4 changes: 2 additions & 2 deletions packages/ensjs/src/contracts/bulkRenewal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers'
import type { JsonRpcProvider } from '@ethersproject/providers'
import { BulkRenewal__factory } from '../generated/factories/BulkRenewal__factory'

// Use a higher-order function to overide the address that is passed in from getContractAddress()
export default (provider: ethers.providers.JsonRpcProvider, address: string) =>
export default (provider: JsonRpcProvider, address: string) =>
BulkRenewal__factory.connect(address, provider)
4 changes: 2 additions & 2 deletions packages/ensjs/src/contracts/dnsRegistrar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import type { JsonRpcProvider } from '@ethersproject/providers'
import { DNSRegistrar__factory } from '../generated/factories/DNSRegistrar__factory'

export default (provider: ethers.providers.JsonRpcProvider, address: string) =>
export default (provider: JsonRpcProvider, address: string) =>
DNSRegistrar__factory.connect(address, provider)
4 changes: 2 additions & 2 deletions packages/ensjs/src/contracts/ethRegistrarController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import type { JsonRpcProvider } from '@ethersproject/providers'
import { ETHRegistrarController__factory } from '../generated/factories/ETHRegistrarController__factory'

export default (provider: ethers.providers.JsonRpcProvider, address: string) =>
export default (provider: JsonRpcProvider, address: string) =>
ETHRegistrarController__factory.connect(address, provider)
48 changes: 48 additions & 0 deletions packages/ensjs/src/contracts/factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { BaseRegistrarImplementation__factory } from '../generated/factories/BaseRegistrarImplementation__factory'
import type { BulkRenewal__factory } from '../generated/factories/BulkRenewal__factory'
import type { DefaultReverseResolver__factory } from '../generated/factories/DefaultReverseResolver__factory'
import type { DNSRegistrar__factory } from '../generated/factories/DNSRegistrar__factory'
import type { DNSSECImpl__factory } from '../generated/factories/DNSSECImpl__factory'
import type { ENSRegistry__factory } from '../generated/factories/ENSRegistry__factory'
import type { ETHRegistrarController__factory } from '../generated/factories/ETHRegistrarController__factory'
import type { Multicall__factory } from '../generated/factories/Multicall__factory'
import type { NameWrapper__factory } from '../generated/factories/NameWrapper__factory'
import type { P256SHA256Algorithm__factory } from '../generated/factories/P256SHA256Algorithm__factory'
import type { PublicResolver__factory } from '../generated/factories/PublicResolver__factory'
import type { ReverseRegistrar__factory } from '../generated/factories/ReverseRegistrar__factory'
import type { Root__factory } from '../generated/factories/Root__factory'
import type { RSASHA1Algorithm__factory } from '../generated/factories/RSASHA1Algorithm__factory'
import type { RSASHA256Algorithm__factory } from '../generated/factories/RSASHA256Algorithm__factory'
import type { SHA1Digest__factory } from '../generated/factories/SHA1Digest__factory'
import type { SHA1NSEC3Digest__factory } from '../generated/factories/SHA1NSEC3Digest__factory'
import type { SHA256Digest__factory } from '../generated/factories/SHA256Digest__factory'
import type { StaticMetadataService__factory } from '../generated/factories/StaticMetadataService__factory'
import type { TLDPublicSuffixList__factory } from '../generated/factories/TLDPublicSuffixList__factory'
import type { UniversalResolver__factory } from '../generated/factories/UniversalResolver__factory'

type Factories = {
BaseRegistrarImplementation: BaseRegistrarImplementation__factory
DefaultReverseResolver: DefaultReverseResolver__factory
DNSRegistrar: DNSRegistrar__factory
DNSSECImpl: DNSSECImpl__factory
ENSRegistry: ENSRegistry__factory
ETHRegistrarController: ETHRegistrarController__factory
P256SHA256Algorithm: P256SHA256Algorithm__factory
PublicResolver: PublicResolver__factory
ReverseRegistrar: ReverseRegistrar__factory
Root: Root__factory
RSASHA1Algorithm: RSASHA1Algorithm__factory
RSASHA256Algorithm: RSASHA256Algorithm__factory
SHA1Digest: SHA1Digest__factory
SHA1NSEC3Digest: SHA1NSEC3Digest__factory
SHA256Digest: SHA256Digest__factory
TLDPublicSuffixList: TLDPublicSuffixList__factory
Multicall: Multicall__factory
NameWrapper: NameWrapper__factory
StaticMetadataService: StaticMetadataService__factory
UniversalResolver: UniversalResolver__factory
BulkRenewal: BulkRenewal__factory
}

export default Factories
2 changes: 1 addition & 1 deletion packages/ensjs/src/contracts/getContractAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const addresses: Record<
'3': '0x13F0659Ee6bb7484C884FEeFb7F75C93951ef837',
'5': '0xE264d5bb84bA3b8061ADC38D3D76e6674aB91852',
},
ENSRegistryWithFallback: {
ENSRegistry: {
'1': '0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e',
'3': '0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e',
'4': '0x00000000000c2e074ec69a0dfb2997ba6c7d2e1e',
Expand Down
Loading

0 comments on commit 79111c6

Please sign in to comment.