Skip to content

Commit

Permalink
Merge pull request #76 from ensdomains/feat/owners-on-domain-entity
Browse files Browse the repository at this point in the history
feat: add more data to domain entity
  • Loading branch information
TateB authored Jun 7, 2023
2 parents 8d808ff + d52c09f commit 1ae310e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "graph test",
"setup": "yarn codegen && yarn create-local && yarn deploy-local",
"create-local": "graph create graphprotocol/ens --node http://127.0.0.1:8020",
"deploy-local": "graph deploy graphprotocol/ens --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020/ --version-label 0.0.1",
"deploy-local": "graph deploy graphprotocol/ens --ipfs http://localhost:5001 --node http://127.0.0.1:8020/ --version-label 0.0.1",
"remove-local": "graph remove graphprotocol/ens --node http://127.0.0.1:8020",
"docker:setup": "yarn codegen && yarn docker:create-local && yarn docker:deploy-local",
"docker:create-local": "graph create graphprotocol/ens --node http://ens-app_graph-node_1:8020",
Expand Down
20 changes: 16 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@ type Domain @entity {
subdomainCount: Int!
"Address logged from current resolver, if any"
resolvedAddress: Account
"The account that owns the domain"
owner: Account!

"The resolver that controls the domain's settings"
resolver: Resolver
"The time-to-live (TTL) value of the domain's records"
ttl: BigInt

"Indicates whether the domain has been migrated to a new registrar"
isMigrated: Boolean!
"The time when the domain was created"
createdAt: BigInt!
"The events associated with the domain"
events: [DomainEvent!]! @derivedFrom(field: "domain")

"The account that owns the domain"
owner: Account!
"The account that owns the ERC721 NFT for the domain"
registrant: Account
"The account that owns the wrapped domain"
wrappedOwner: Account

"The expiry date for the domain, from either the registration, or the wrapped domain if PCC is burned"
expiryDate: BigInt

"The registration associated with the domain"
registration: Registration @derivedFrom(field: "domain")
"The wrapped domain associated with the domain"
wrappedDomain: WrappedDomain @derivedFrom(field: "domain")

"The events associated with the domain"
events: [DomainEvent!]! @derivedFrom(field: "domain")
}

interface DomainEvent {
Expand Down
20 changes: 17 additions & 3 deletions src/ethRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
checkValidLabel,
concat,
createEventID,
ETH_NODE,
uint256ToByteArray,
} from "./utils";

Expand Down Expand Up @@ -33,9 +34,9 @@ import {
Registration,
} from "./types/schema";

var rootNode: ByteArray = byteArrayFromHex(
"93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae"
);
const GRACE_PERIOD_SECONDS = BigInt.fromI32(7776000); // 90 days

var rootNode: ByteArray = byteArrayFromHex(ETH_NODE);

export function handleNameRegistered(event: NameRegisteredEvent): void {
let account = new Account(event.params.owner.toHex());
Expand All @@ -50,6 +51,9 @@ export function handleNameRegistered(event: NameRegisteredEvent): void {
registration.expiryDate = event.params.expires;
registration.registrant = account.id;

domain.registrant = account.id;
domain.expiryDate = event.params.expires.plus(GRACE_PERIOD_SECONDS);

let labelName = ens.nameByHash(label.toHexString());
if (labelName != null) {
domain.labelName = labelName;
Expand Down Expand Up @@ -112,8 +116,13 @@ function setNamePreimage(name: string, label: Bytes, cost: BigInt): void {
export function handleNameRenewed(event: NameRenewedEvent): void {
let label = uint256ToByteArray(event.params.id);
let registration = Registration.load(label.toHex())!;
let domain = Domain.load(crypto.keccak256(concat(rootNode, label)).toHex())!;

registration.expiryDate = event.params.expires;
domain.expiryDate = event.params.expires.plus(GRACE_PERIOD_SECONDS);

registration.save();
domain.save();

let registrationEvent = new NameRenewed(createEventID(event));
registrationEvent.registration = registration.id;
Expand All @@ -131,7 +140,12 @@ export function handleNameTransferred(event: TransferEvent): void {
let registration = Registration.load(label.toHex());
if (registration == null) return;

let domain = Domain.load(crypto.keccak256(concat(rootNode, label)).toHex())!;

registration.registrant = account.id;
domain.registrant = account.id;

domain.save();
registration.save();

let transferEvent = new NameTransferred(createEventID(event));
Expand Down
53 changes: 48 additions & 5 deletions src/nameWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
createEventID,
createOrLoadAccount,
createOrLoadDomain,
ETH_NODE,
} from "./utils";

function decodeName(buf: Bytes): Array<string> | null {
Expand Down Expand Up @@ -57,6 +58,12 @@ function decodeName(buf: Bytes): Array<string> | null {
return [firstLabel, list.toString()];
}

const PARENT_CANNOT_CONTROL: i32 = 65536;

function checkPccBurned(fuses: i32): boolean {
return (fuses & PARENT_CANNOT_CONTROL) == PARENT_CANNOT_CONTROL;
}

export function handleNameWrapped(event: NameWrappedEvent): void {
let decoded = decodeName(event.params.name);
let label: string | null = null;
Expand All @@ -66,7 +73,8 @@ export function handleNameWrapped(event: NameWrappedEvent): void {
name = decoded[1];
}
let node = event.params.node;
let fuses = event.params.fuses;
let expiryDate = event.params.expiry;
let fuses = event.params.fuses.toI32();
let blockNumber = event.block.number.toI32();
let transactionID = event.transaction.hash;
let owner = createOrLoadAccount(event.params.owner.toHex());
Expand All @@ -76,21 +84,28 @@ export function handleNameWrapped(event: NameWrappedEvent): void {
domain.labelName = label;
domain.name = name;
}
if (
checkPccBurned(fuses) &&
(!domain.expiryDate || expiryDate > domain.expiryDate!)
) {
domain.expiryDate = expiryDate;
}
domain.wrappedOwner = owner.id;
domain.save();

let wrappedDomain = new WrappedDomain(node.toHex());
wrappedDomain.domain = domain.id;
wrappedDomain.expiryDate = event.params.expiry;
wrappedDomain.fuses = fuses.toI32();
wrappedDomain.expiryDate = expiryDate;
wrappedDomain.fuses = fuses;
wrappedDomain.owner = owner.id;
wrappedDomain.name = name;
wrappedDomain.save();

let nameWrappedEvent = new NameWrapped(createEventID(event));
nameWrappedEvent.domain = domain.id;
nameWrappedEvent.name = name;
nameWrappedEvent.fuses = fuses.toI32();
nameWrappedEvent.expiryDate = event.params.expiry;
nameWrappedEvent.fuses = fuses;
nameWrappedEvent.expiryDate = expiryDate;
nameWrappedEvent.owner = owner.id;
nameWrappedEvent.blockNumber = blockNumber;
nameWrappedEvent.transactionID = transactionID;
Expand All @@ -103,6 +118,13 @@ export function handleNameUnwrapped(event: NameUnwrappedEvent): void {
let transactionID = event.transaction.hash;
let owner = createOrLoadAccount(event.params.owner.toHex());

let domain = createOrLoadDomain(node.toHex());
domain.wrappedOwner = null;
if (domain.expiryDate && domain.parent !== ETH_NODE) {
domain.expiryDate = null;
}
domain.save();

let nameUnwrappedEvent = new NameUnwrapped(createEventID(event));
nameUnwrappedEvent.domain = node.toHex();
nameUnwrappedEvent.owner = owner.id;
Expand All @@ -122,6 +144,13 @@ export function handleFusesSet(event: FusesSetEvent): void {
if (wrappedDomain) {
wrappedDomain.fuses = fuses.toI32();
wrappedDomain.save();
if (wrappedDomain.expiryDate && checkPccBurned(wrappedDomain.fuses)) {
let domain = createOrLoadDomain(node.toHex());
if (!domain.expiryDate || wrappedDomain.expiryDate > domain.expiryDate!) {
domain.expiryDate = wrappedDomain.expiryDate;
domain.save();
}
}
}
let fusesBurnedEvent = new FusesSet(createEventID(event));
fusesBurnedEvent.domain = node.toHex();
Expand All @@ -140,6 +169,13 @@ export function handleExpiryExtended(event: ExpiryExtendedEvent): void {
if (wrappedDomain) {
wrappedDomain.expiryDate = expiry;
wrappedDomain.save();
if (checkPccBurned(wrappedDomain.fuses)) {
let domain = createOrLoadDomain(node.toHex());
if (!domain.expiryDate || expiry > domain.expiryDate!) {
domain.expiryDate = expiry;
domain.save();
}
}
}
let expiryExtendedEvent = new ExpiryExtended(createEventID(event));
expiryExtendedEvent.domain = node.toHex();
Expand Down Expand Up @@ -169,9 +205,16 @@ function makeWrappedTransfer(
// so we need to create the WrappedDomain entity here
if (wrappedDomain == null) {
wrappedDomain = new WrappedDomain(namehash);
wrappedDomain.domain = domain.id;

// placeholders until we get the NameWrapped event
wrappedDomain.expiryDate = BigInt.fromI32(0);
wrappedDomain.fuses = 0;
}
wrappedDomain.owner = _to.id;
wrappedDomain.save();
domain.wrappedOwner = _to.id;
domain.save();
const wrappedTransfer = new WrappedTransfer(eventID);
wrappedTransfer.domain = domain.id;
wrappedTransfer.blockNumber = blockNumber;
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export function createEventID(event: ethereum.Event): string {
.concat(event.logIndex.toString());
}

export const ETH_NODE =
"93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
export const ROOT_NODE =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1782,9 +1782,9 @@ globby@^11.1.0:
merge2 "^1.4.1"
slash "^3.0.0"

"gluegun@git+https://github.com/edgeandnode/gluegun.git#v4.3.1-pin-colors-dep":
"gluegun@https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep":
version "4.3.1"
resolved "git+https://github.com/edgeandnode/gluegun.git#b34b9003d7bf556836da41b57ef36eb21570620a"
resolved "https://github.com/edgeandnode/gluegun#b34b9003d7bf556836da41b57ef36eb21570620a"
dependencies:
apisauce "^1.0.1"
app-module-path "^2.2.0"
Expand Down

0 comments on commit 1ae310e

Please sign in to comment.