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 cost event #50

Draft
wants to merge 1 commit into
base: full-wrapper-support
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"devDependencies": {
"@ensdomains/content-hash": "^2.5.3",
"@graphprotocol/graph-cli": "^0.23.2",
"@graphprotocol/graph-ts": "^0.23.1"
"@graphprotocol/graph-ts": "^0.23.1",
"assemblyscript": "0.20.19"
}
}
17 changes: 17 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ type NameRegistered implements RegistrationEvent @entity {
expiryDate: BigInt!
}

type NameRegisteredWithCost implements RegistrationEvent @entity {
id: ID!
registration: Registration!
blockNumber: Int!
transactionID: Bytes!
baseCost: BigInt!
premium: BigInt
}

type NameRenewed implements RegistrationEvent @entity {
id: ID!
registration: Registration!
Expand All @@ -128,6 +137,14 @@ type NameRenewed implements RegistrationEvent @entity {
expiryDate: BigInt!
}

type NameRenewedWithCost implements RegistrationEvent @entity {
id: ID!
registration: Registration!
blockNumber: Int!
transactionID: Bytes!
cost: BigInt!
}

type NameTransferred implements RegistrationEvent @entity {
id: ID!
registration: Registration!
Expand Down
33 changes: 30 additions & 3 deletions src/ethRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Bytes,
crypto,
ens,
ethereum,
log
} from '@graphprotocol/graph-ts'

Expand All @@ -18,7 +19,7 @@ import {
} from './types/BaseRegistrar/BaseRegistrar'

import {
NameRegistered as ControllerNameRegisteredEventOld,
NameRegistered as ControllerNameRegisteredEventOld
} from './types/EthRegistrarControllerOld/EthRegistrarControllerOld'

import {
Expand All @@ -27,7 +28,7 @@ import {
} from './types/EthRegistrarController/EthRegistrarController'

// Import entity types generated from the GraphQL schema
import { Account, Domain, NameRegistered, NameRenewed, NameTransferred, Registration } from './types/schema'
import { Account, Domain, NameRegistered, NameRegisteredWithCost, NameRenewed, NameRenewedWithCost, NameTransferred, Registration } from './types/schema'

var rootNode:ByteArray = byteArrayFromHex("93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae")

Expand Down Expand Up @@ -62,14 +63,40 @@ export function handleNameRegistered(event: NameRegisteredEvent): void {

export function handleNameRegisteredByControllerOld(event: ControllerNameRegisteredEventOld): void {
setNamePreimage(event.params.name, event.params.label, event.params.cost);
makeNameRegisteredWithCostEvent(event);
}

export function handleNameRegisteredByController(event: ControllerNameRegisteredEvent): void {
setNamePreimage(event.params.name, event.params.label, event.params.baseCost.plus(event.params.premium))
setNamePreimage(event.params.name, event.params.label, event.params.baseCost.plus(event.params.premium));
makeNameRegisteredWithCostEvent(event);
}

export function handleNameRenewedByController(event: ControllerNameRenewedEvent): void {
setNamePreimage(event.params.name, event.params.label, event.params.cost);

let renewalEvent = new NameRenewedWithCost(createEventID(event))
renewalEvent.registration = event.params.label.toHex()
renewalEvent.blockNumber = event.block.number.toI32()
renewalEvent.transactionID = event.transaction.hash
renewalEvent.cost = event.params.cost
renewalEvent.save()
}

function makeNameRegisteredWithCostEvent<E extends ethereum.Event>(event: E): void {
let registrationEvent = new NameRegisteredWithCost(createEventID(event))
registrationEvent.blockNumber = event.block.number.toI32()
registrationEvent.transactionID = event.transaction.hash
if (event instanceof ControllerNameRegisteredEvent) {
registrationEvent.premium = event.params.premium
registrationEvent.baseCost = event.params.baseCost
registrationEvent.registration = event.params.owner.toHex()
} else {
let oldEvent = changetype<ControllerNameRegisteredEventOld>(event)
registrationEvent.premium = BigInt.fromI32(0)
registrationEvent.baseCost = oldEvent.params.cost
registrationEvent.registration = oldEvent.params.owner.toHex()
}
registrationEvent.save()
}

function setNamePreimage(name: string, label: Bytes, cost: BigInt): void {
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extend": "./node_modules/@graphprotocol/graph-ts/tsconfig.json",
"extends": "@graphprotocol/graph-ts",
"compilerOptions": {
"target": "ES2020",
"moduleResolution": "node",
"types": ["@graphprotocol/graph-ts"]
}
"moduleResolution": "node"
},
"include": ["src/**/*.ts"]
}
18 changes: 18 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ assemblyscript@0.19.10:
binaryen "101.0.0-nightly.20210723"
long "^4.0.0"

assemblyscript@0.20.19:
version "0.20.19"
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.20.19.tgz#7c29f506a31d526f7d7e3b22908cc8774b378681"
integrity sha512-IJN2CaAwCdRgTSZz3GiuYyXtXIjETBrlzky9ww9jFlEgH8i0pNFt6MAS3viogkofem+rcY6Fhr/clk+b6LWLBw==
dependencies:
binaryen "109.0.0-nightly.20220813"
long "^5.2.0"

assert-plus@1.0.0, assert-plus@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
Expand Down Expand Up @@ -343,6 +351,11 @@ binaryen@101.0.0-nightly.20210723:
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-101.0.0-nightly.20210723.tgz#b6bb7f3501341727681a03866c0856500eec3740"
integrity sha512-eioJNqhHlkguVSbblHOtLqlhtC882SOEPKmNFZaDuz1hzQjolxZ+eu3/kaS10n3sGPONsIZsO7R9fR00UyhEUA==

binaryen@109.0.0-nightly.20220813:
version "109.0.0-nightly.20220813"
resolved "https://registry.yarnpkg.com/binaryen/-/binaryen-109.0.0-nightly.20220813.tgz#6928acf8820fc1270d41dbb157c0c2337a067d20"
integrity sha512-u85Ti3LiGRrV0HqdNDRknalkx7QiCSL0jNsEsT522nnZacWxUaSJEILphxc2OnzmHVtdiWBE3c4lEzlU3ZEyDw==

bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
Expand Down Expand Up @@ -2005,6 +2018,11 @@ long@^4.0.0:
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

long@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.0.tgz#2696dadf4b4da2ce3f6f6b89186085d94d52fd61"
integrity sha512-9RTUNjK60eJbx3uz+TEGF7fUr29ZDxR5QzXcyDpeSfeH28S9ycINflOgOlppit5U+4kNTe83KQnMEerw7GmE8w==

looper@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/looper/-/looper-3.0.0.tgz#2efa54c3b1cbaba9b94aee2e5914b0be57fbb749"
Expand Down