-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RSKOwner contract to the subgraph
- Loading branch information
1 parent
c8d34ef
commit de85f27
Showing
9 changed files
with
832 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ByteArray, crypto, ens, log } from "@graphprotocol/graph-ts"; | ||
import { | ||
Approval as ApprovalEvent, | ||
ApprovalForAll as ApprovalForAllEvent, | ||
ExpirationChanged as ExpirationChangedEvent, | ||
OwnershipTransferred as OwnershipTransferredEvent, | ||
Transfer as TransferEvent, | ||
} from "../generated/RSKOwner/RSKOwner" | ||
import { | ||
Account, | ||
Domain, | ||
NameRegistered, | ||
NameTransferred, | ||
Registration, | ||
Transfer, | ||
} from "../generated/schema" | ||
import { checkValidLabel, concat, createEventID, RSK_NODE, uint256ToByteArray } from "./utils"; | ||
|
||
var rootNode: ByteArray = ByteArray.fromHexString(RSK_NODE); | ||
|
||
export function handleExpirationChanged(event: ExpirationChangedEvent): void { | ||
let label = uint256ToByteArray(event.params.tokenId); | ||
let domain = Domain.load(crypto.keccak256(concat(rootNode, label)).toHex()); | ||
|
||
// Workaround for the case when the domain is not found | ||
if (domain == null) return ; | ||
|
||
let registration = new Registration(label.toHex()); | ||
|
||
registration.domain = domain.id; | ||
registration.registrationDate = event.block.timestamp; | ||
registration.expiryDate = event.params.expirationTime; | ||
registration.registrant = domain.owner; | ||
|
||
domain.expiryDate = event.params.expirationTime; | ||
|
||
|
||
let labelName = ens.nameByHash(label.toHexString()); | ||
if (checkValidLabel(labelName)) { | ||
domain.labelName = labelName; | ||
domain.name = labelName! + ".rsk"; | ||
registration.labelName = labelName; | ||
} | ||
domain.save(); | ||
registration.save(); | ||
|
||
let registrationEvent = new NameRegistered(createEventID(event)); | ||
registrationEvent.registration = registration.id; | ||
registrationEvent.blockNumber = event.block.number.toI32(); | ||
registrationEvent.transactionID = event.transaction.hash; | ||
registrationEvent.expiryDate = event.params.expirationTime; | ||
registrationEvent.registrant = domain.owner; | ||
registrationEvent.save(); | ||
} | ||
|
||
export function handleTransfer(event: TransferEvent): void { | ||
let account = new Account(event.params.to.toHex()); | ||
account.save(); | ||
|
||
let label = uint256ToByteArray(event.params.tokenId); | ||
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)); | ||
transferEvent.registration = label.toHex(); | ||
transferEvent.blockNumber = event.block.number.toI32(); | ||
transferEvent.transactionID = event.transaction.hash; | ||
transferEvent.newOwner = account.id; | ||
transferEvent.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "0.6.0", | ||
"timestamp": 1737655167212 | ||
"timestamp": 1738072715812 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { newMockEvent } from "matchstick-as" | ||
import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts" | ||
import { | ||
Approval, | ||
ApprovalForAll, | ||
ExpirationChanged, | ||
OwnershipTransferred, | ||
Transfer | ||
} from "../generated/RSKOwner/RSKOwner" | ||
|
||
export function createApprovalEvent( | ||
owner: Address, | ||
approved: Address, | ||
tokenId: BigInt | ||
): Approval { | ||
let approvalEvent = changetype<Approval>(newMockEvent()) | ||
|
||
approvalEvent.parameters = new Array() | ||
|
||
approvalEvent.parameters.push( | ||
new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) | ||
) | ||
approvalEvent.parameters.push( | ||
new ethereum.EventParam("approved", ethereum.Value.fromAddress(approved)) | ||
) | ||
approvalEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"tokenId", | ||
ethereum.Value.fromUnsignedBigInt(tokenId) | ||
) | ||
) | ||
|
||
return approvalEvent | ||
} | ||
|
||
export function createApprovalForAllEvent( | ||
owner: Address, | ||
operator: Address, | ||
approved: boolean | ||
): ApprovalForAll { | ||
let approvalForAllEvent = changetype<ApprovalForAll>(newMockEvent()) | ||
|
||
approvalForAllEvent.parameters = new Array() | ||
|
||
approvalForAllEvent.parameters.push( | ||
new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)) | ||
) | ||
approvalForAllEvent.parameters.push( | ||
new ethereum.EventParam("operator", ethereum.Value.fromAddress(operator)) | ||
) | ||
approvalForAllEvent.parameters.push( | ||
new ethereum.EventParam("approved", ethereum.Value.fromBoolean(approved)) | ||
) | ||
|
||
return approvalForAllEvent | ||
} | ||
|
||
export function createExpirationChangedEvent( | ||
tokenId: BigInt, | ||
expirationTime: BigInt | ||
): ExpirationChanged { | ||
let expirationChangedEvent = changetype<ExpirationChanged>(newMockEvent()) | ||
|
||
expirationChangedEvent.parameters = new Array() | ||
|
||
expirationChangedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"tokenId", | ||
ethereum.Value.fromUnsignedBigInt(tokenId) | ||
) | ||
) | ||
expirationChangedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"expirationTime", | ||
ethereum.Value.fromUnsignedBigInt(expirationTime) | ||
) | ||
) | ||
|
||
return expirationChangedEvent | ||
} | ||
|
||
export function createOwnershipTransferredEvent( | ||
previousOwner: Address, | ||
newOwner: Address | ||
): OwnershipTransferred { | ||
let ownershipTransferredEvent = | ||
changetype<OwnershipTransferred>(newMockEvent()) | ||
|
||
ownershipTransferredEvent.parameters = new Array() | ||
|
||
ownershipTransferredEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"previousOwner", | ||
ethereum.Value.fromAddress(previousOwner) | ||
) | ||
) | ||
ownershipTransferredEvent.parameters.push( | ||
new ethereum.EventParam("newOwner", ethereum.Value.fromAddress(newOwner)) | ||
) | ||
|
||
return ownershipTransferredEvent | ||
} | ||
|
||
export function createTransferEvent( | ||
from: Address, | ||
to: Address, | ||
tokenId: BigInt | ||
): Transfer { | ||
let transferEvent = changetype<Transfer>(newMockEvent()) | ||
|
||
transferEvent.parameters = new Array() | ||
|
||
transferEvent.parameters.push( | ||
new ethereum.EventParam("from", ethereum.Value.fromAddress(from)) | ||
) | ||
transferEvent.parameters.push( | ||
new ethereum.EventParam("to", ethereum.Value.fromAddress(to)) | ||
) | ||
transferEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"tokenId", | ||
ethereum.Value.fromUnsignedBigInt(tokenId) | ||
) | ||
) | ||
|
||
return transferEvent | ||
} |
Oops, something went wrong.