Skip to content

Commit

Permalink
build pipeline overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jul 6, 2023
1 parent 2ec84f8 commit 028511b
Show file tree
Hide file tree
Showing 200 changed files with 3,020 additions and 2,020 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules/
dist/
archives/
data/

*.tsbuildinfo
13 changes: 13 additions & 0 deletions examples/basic-esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "basic-esm",
"private": true,
"type": "module",
"version": "0.0.1",
"scripts": {
"start": "node src/index.js"
},
"dependencies": {
"@ensdomains/ensjs": "workspace:*",
"viem": "^1.2.9"
}
}
30 changes: 30 additions & 0 deletions examples/basic-esm/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createEnsPublicClient } from '@ensdomains/ensjs'
import { getAddressRecord, getTextRecord } from '@ensdomains/ensjs/public'
import { http } from 'viem'
import { mainnet } from 'viem/chains'

const client = createEnsPublicClient({
chain: mainnet,
transport: http('https://web3.ens.domains/v1/mainnet'),
})

const main = async () => {
const records = await client.getSubgraphRecords({ name: 'ens.eth' })
const recordData = await client.getRecords({
name: 'ens.eth',
records: {
abi: true,
contentHash: true,
...(records || {}),
},
})
console.log(recordData)

const batchData = await client.ensBatch(
getTextRecord.batch({ name: 'ens.eth', key: 'com.twitter' }),
getAddressRecord.batch({ name: 'ens.eth', coin: 'ETH' }),
)
console.log(batchData)
}

main()
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "ensjs-examples",
"name": "basic-tsnode-esm",
"private": true,
"type": "module",
"version": "0.0.1",
"scripts": {
"start": "ts-node --esm --experimentalSpecifierResolution node src/index.ts"
"start": "ts-node-esm src/index.ts"
},
"dependencies": {
"@ensdomains/ensjs": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
createEnsPublicClient,
getAddressRecord,
getTextRecord,
} from '@ensdomains/ensjs'
import { createEnsPublicClient } from '@ensdomains/ensjs'
import { getAddressRecord, getTextRecord } from '@ensdomains/ensjs/public'
import { http } from 'viem'
import { mainnet } from 'viem/chains'

Expand Down
10 changes: 10 additions & 0 deletions examples/basic-tsnode-esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"ts-node": {
"compilerOptions": {
"target": "es2020",
"esModuleInterop": true
}
},
"include": ["src/**/*.ts"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.8.8",
"ts-node": "^10.7.0",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
},
"resolutions": {
"@nomiclabs/hardhat-ethers": "npm:[email protected]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/* eslint-disable import/no-extraneous-dependencies */

import { Interface } from 'ethers/lib/utils'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { namehash } from '../src/utils/normalise'
// eslint-disable-next-line @typescript-eslint/naming-convention
const { Interface } = require('ethers/lib/utils')
const { ethers } = require('hardhat')
const { namehash, labelhash } = require('viem/ens')

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

function computeInterfaceId(iface: Interface) {
/**
* @param {import('ethers/lib/utils').Interface} iface
*/
function computeInterfaceId(iface) {
return makeInterfaceId.ERC165(
Object.values(iface.functions).map((frag) => frag.format('sighash')),
)
}

const labelHash = (label: string) =>
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(label))

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts, deployments, network } = hre
const { deploy } = deployments
const { deployer, owner } = await getNamedAccounts()
Expand Down Expand Up @@ -49,7 +50,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
})

console.log('Temporarily setting owner of eth tld to owner ')
const tx = await root.setSubnodeOwner(labelHash('eth'), owner)
const tx = await root.setSubnodeOwner(labelhash('eth'), owner)
await tx.wait()

console.log('Set default resolver for eth tld to public resolver')
Expand Down Expand Up @@ -81,7 +82,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await tx4.wait()

console.log('Set owner of eth tld back to registrar')
const tx11 = await root.setSubnodeOwner(labelHash('eth'), registrar.address)
const tx11 = await root.setSubnodeOwner(labelhash('eth'), registrar.address)
await tx11.wait()

return true
Expand All @@ -97,4 +98,4 @@ func.dependencies = [
'ETHRegistrarController',
]

export default func
module.exports = func
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable import/no-extraneous-dependencies */
import { existsSync, mkdirSync } from 'fs'
import { readFile, writeFile } from 'fs/promises'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { resolve } from 'path'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { existsSync, mkdirSync } = require('fs')
const { readFile, writeFile } = require('fs/promises')
const { resolve } = require('path')

/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts } = hre
const { deployer } = await getNamedAccounts()

let contractJson: any
let contractJson

const jsonPath = resolve(__dirname, '../cache/multicall.json')

Expand All @@ -35,4 +36,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

func.id = 'multicall'

export default func
module.exports = func
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/* eslint-disable import/no-extraneous-dependencies */

import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { labelhash } from 'viem'
import { namehash } from '../src/utils/normalise'
const { ethers } = require('hardhat')
const { labelhash, namehash } = require('viem/ens')

const ZERO_HASH =
'0x0000000000000000000000000000000000000000000000000000000000000000'

const names = ['legacy']

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts } = hre
const { owner } = await getNamedAccounts()

Expand Down Expand Up @@ -43,7 +42,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
func.id = 'legacy-registry-names'
func.tags = ['legacy-registry-names']
func.dependencies = ['ENSRegistry']
func.skip = async function (hre: HardhatRuntimeEnvironment) {
func.skip = async function (hre) {
const { getNamedAccounts } = hre
const { owner } = await getNamedAccounts()

Expand All @@ -57,4 +56,4 @@ func.skip = async function (hre: HardhatRuntimeEnvironment) {
}
func.runAtTheEnd = true

export default func
module.exports = func
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-await-in-loop */
import cbor from 'cbor'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import pako from 'pako'
import { labelhash, toBytes } from 'viem'
import { namehash } from '../src/utils/normalise'
const cbor = require('cbor')
const { ethers } = require('hardhat')
const pako = require('pako')
const { labelhash, namehash, toBytes } = require('viem')

const dummyABI = [
{
Expand Down Expand Up @@ -127,33 +124,38 @@ const dummyABI = [
},
]

type Subname = {
label: string
namedOwner: string
}
/**
* @typedef {{
* label: string
* namedOwner: string
* }} Subname
*/

const names: {
label: string
namedOwner: string
namedAddr: string
records?: {
text?: {
key: string
value: string
}[]
addr?: {
key: number
value: string
}[]
contenthash?: string
abi?: {
contentType: 1 | 2 | 4 | 8 | 256
data: object | string
}
}
duration?: number
subnames?: Subname[]
}[] = [
/**
* @type {{
* label: string
* namedOwner: string
* namedAddr: string
* records?: {
* text?: {
* key: string
* value: string
* }[]
* addr?: {
* key: number
* value: string
* }[]
* contenthash?: string
* abi?: {
* contentType: 1 | 2 | 4 | 8 | 256
* data: object | string
* }
* }
* duration?: number
* subnames?: Subname[]
* }[]}
*/
const names = [
{
label: 'test123',
namedOwner: 'owner',
Expand Down Expand Up @@ -314,7 +316,10 @@ const names: {
})),
]

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/**
* @type {import('hardhat-deploy/types').DeployFunction}
*/
const func = async function (hre) {
const { getNamedAccounts, network } = hre
const allNamedAccts = await getNamedAccounts()

Expand Down Expand Up @@ -408,15 +413,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
if (records.abi) {
console.log('ABI')
let data: string | Buffer | Uint8Array
/**
* @type {string | Buffer | Uint8Array}
*/
let data
if (records.abi.contentType === 1 || records.abi.contentType === 256) {
data = JSON.stringify(records.abi.data)
} else if (records.abi.contentType === 2) {
data = pako.deflate(JSON.stringify(records.abi.data))
} else if (records.abi.contentType === 4) {
data = cbor.encode(records.abi.data)
} else {
data = records.abi.data as string
data = records.abi.data
}
if (typeof data === 'string') data = toBytes(data)
const setABITx = await _publicResolver.setABI(
Expand Down Expand Up @@ -461,4 +469,4 @@ func.tags = ['register-unwrapped-names']
func.dependencies = ['LegacyETHRegistrarController']
func.runAtTheEnd = true

export default func
module.exports = func
Loading

0 comments on commit 028511b

Please sign in to comment.