Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Context #73

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 238 additions & 0 deletions abis/ContextResolver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
[
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "uint256",
"name": "_coinType",
"type": "uint256"
},
{
"internalType": "string",
"name": "_graphqlUrl",
"type": "string"
},
{
"internalType": "uint8",
"name": "_storageType",
"type": "uint8"
},
{
"internalType": "bytes",
"name": "_context",
"type": "bytes"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "name",
"type": "string"
},
{
"indexed": false,
"internalType": "uint256",
"name": "coinType",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "graphqlUrl",
"type": "string"
},
{
"indexed": false,
"internalType": "uint8",
"name": "storageType",
"type": "uint8"
},
{
"indexed": false,
"internalType": "bytes",
"name": "context",
"type": "bytes"
}
],
"name": "MetadataChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "node",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint64",
"name": "newVersion",
"type": "uint64"
}
],
"name": "VersionChanged",
"type": "event"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "node",
"type": "bytes32"
}
],
"name": "clearRecords",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "coinType",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "context",
"outputs": [
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "graphqlUrl",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "metadata",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "string",
"name": "",
"type": "string"
},
{
"internalType": "uint8",
"name": "",
"type": "uint8"
},
{
"internalType": "bytes",
"name": "",
"type": "bytes"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"name": "recordVersions",
"outputs": [
{
"internalType": "uint64",
"name": "",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "storageType",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceID",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
16 changes: 16 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ type Account @entity {
registrations: [Registration!] @derivedFrom(field: "registrant")
}

type Offchain @entity {
"l1 resolver address"
id: ID!
"Name of the Chain"
name: String
"coin type"
coinType: BigInt
"url of the graphql endpoint"
graphqlUrl: String
"0 for evm, 1 for non blockchain, 2 for starknet"
storageType: Int
"context, resolver address if evm Chain"
context: Bytes
}

type Resolver @entity {
"The unique identifier for this resolver, which is a concatenation of the resolver address and the domain namehash"
id: ID!
Expand All @@ -282,6 +297,7 @@ type Resolver @entity {
"The set of observed SLIP-44 coin types for this resolver"
coinTypes: [BigInt!]
"The events associated with this resolver"
offchain: Offchain
events: [ResolverEvent!]! @derivedFrom(field: "resolver")
}

Expand Down
5 changes: 5 additions & 0 deletions src/ensRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NewOwner,
NewResolver,
NewTTL,
Offchain,
Resolver,
Transfer,
} from "./types/schema";
Expand Down Expand Up @@ -184,6 +185,10 @@ export function handleNewResolver(event: NewResolverEvent): void {
resolver = new Resolver(id);
resolver.domain = event.params.node.toHexString();
resolver.address = event.params.resolver;
let offchain = Offchain.load(event.params.resolver.toHexString());
if(offchain){
resolver.offchain = offchain.id;
}
resolver.save();
// since this is a new resolver entity, there can't be a resolved address yet so set to null
domain.resolvedAddress = null;
Expand Down
15 changes: 15 additions & 0 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
VersionChanged as VersionChangedEvent,
} from "./types/Resolver/Resolver";

import {
MetadataChanged as MetadataChangedEvent
} from "./types/ContextResolver/ContextResolver";

import {
AbiChanged,
Account,
Expand All @@ -22,6 +26,7 @@ import {
ContenthashChanged,
Domain,
InterfaceChanged,
Offchain,
MulticoinAddrChanged,
NameChanged,
PubkeyChanged,
Expand All @@ -30,6 +35,16 @@ import {
VersionChanged,
} from "./types/schema";

export function handleMetadataChanged(event: MetadataChangedEvent): void {
let offchain = new Offchain(event.address.toHexString());
offchain.name = event.params.name
offchain.coinType = event.params.coinType
offchain.graphqlUrl = event.params.graphqlUrl
offchain.storageType = event.params.storageType
offchain.context = event.params.context
offchain.save()
}

export function handleAddrChanged(event: AddrChangedEvent): void {
let account = new Account(event.params.a.toHexString());
account.save();
Expand Down
20 changes: 19 additions & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ dataSources:
handler: handleTextChangedWithValue
- event: "VersionChanged(indexed bytes32,uint64)"
handler: handleVersionChanged
- kind: ethereum/contract
name: ContextResolver
network: mainnet
source:
abi: ContextResolver
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
file: ./src/resolver.ts
entities:
- MetadataChanged
abis:
- name: ContextResolver
file: ./abis/ContextResolver.json
eventHandlers:
- event: "MetadataChanged(string,uint256,string,uint8,bytes)"
handler: handleMetadataChanged
- kind: ethereum/contract
name: BaseRegistrar
network: mainnet
Expand Down Expand Up @@ -214,4 +232,4 @@ dataSources:
- event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256)
handler: handleTransferSingle
- event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
handler: handleTransferBatch
handler: handleTransferBatch