Skip to content

Commit

Permalink
Merge pull request #72 from ensdomains/fix/grace-period-ownership
Browse files Browse the repository at this point in the history
fix: added graph fetch for grace period owner value
  • Loading branch information
TateB authored Oct 24, 2022
2 parents 653b97c + 5708a67 commit 787c1e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
46 changes: 38 additions & 8 deletions packages/ensjs/src/functions/getOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,27 @@ const raw = async (
return multicallWrapper.raw(data)
}

const registrantQuery = `
query GetRegistrant($namehash: String!) {
domain(id: $namehash) {
registration {
registrant {
id
}
}
}
}
`

const singleContractOwnerDecode = (data: string) =>
ethers.utils.defaultAbiCoder.decode(['address'], data)[0]

const decode = async (
{ contracts, multicallWrapper }: ENSArgs<'contracts' | 'multicallWrapper'>,
{
contracts,
multicallWrapper,
gqlInstance,
}: ENSArgs<'contracts' | 'multicallWrapper' | 'gqlInstance'>,
data: string,
name: string,
contract?: 'nameWrapper' | 'registry' | 'registrar',
Expand Down Expand Up @@ -131,12 +147,20 @@ const decode = async (

const registryOwner = (decodedData[0] as ethers.utils.Result)[0]
const nameWrapperOwner = (decodedData[1] as ethers.utils.Result)[0]
const registrarOwner = (
decodedData[2] as ethers.utils.Result | undefined
)?.[0]
let registrarOwner = (decodedData[2] as ethers.utils.Result | undefined)?.[0]

// check for only .eth names
if (labels[labels.length - 1] === 'eth') {
if (!registrarOwner && labels.length === 2) {
const graphRegistrantResult = await gqlInstance?.request(
registrantQuery,
{
namehash: makeNamehash(name),
},
)
registrarOwner =
graphRegistrantResult.domain?.registration?.registrant?.id
}
// if the owner on the registrar is the namewrapper, then the namewrapper owner is the owner
// there is no "registrant" for wrapped names
if (registrarOwner === nameWrapper.address) {
Expand All @@ -156,10 +180,16 @@ const decode = async (
ownershipLevel: 'registrar',
}
}
if (
labels.length > 2 &&
ethers.utils.hexStripZeros(registryOwner) !== '0x'
) {
if (ethers.utils.hexStripZeros(registryOwner) !== '0x') {
// if there is no registrar owner, but the label length is two, then the domain is an expired 2LD .eth
// so we still want to return the ownership values
if (labels.length === 2) {
return {
registrant: undefined,
owner: registryOwner,
ownershipLevel: 'registrar',
}
}
// this means that the subname is wrapped
if (
registryOwner === nameWrapper.address &&
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
} from './functions/getSpecificRecord'
import type getSubnames from './functions/getSubnames'
import type getWrapperData from './functions/getWrapperData'
import importDNSSECName from './functions/importDNSSECName'
import type registerName from './functions/registerName'
import type {
// eslint-disable-next-line import/no-named-default
Expand All @@ -51,7 +52,6 @@ import type wrapName from './functions/wrapName'
import GqlManager from './GqlManager'
import singleCall from './utils/singleCall'
import writeTx from './utils/writeTx'
import importDNSSECName from './functions/importDNSSECName'

export type {
Fuse,
Expand Down Expand Up @@ -500,7 +500,7 @@ export class ENS {

public getOwner = this.generateRawFunction<typeof getOwner>(
'initialGetters',
['contracts', 'multicallWrapper'],
['contracts', 'multicallWrapper', 'gqlInstance'],
'getOwner',
)

Expand Down

0 comments on commit 787c1e6

Please sign in to comment.