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

Registry indexer. hash-data collection #1

Open
wants to merge 4 commits into
base: wagyu
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions subgraphs/WagyuRegistry/abis/WagyuRegistry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" },
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "_hash",
"type": "string"
}
],
"name": "TokenAdded",
"type": "event"
},
{
"inputs": [{ "internalType": "string", "name": "_hash", "type": "string" }],
"name": "addToken",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
17 changes: 17 additions & 0 deletions subgraphs/WagyuRegistry/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "WagyuRegistry",
"license": "UNLICENSED",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ WagyuRegistry",
"create-local": "graph create --node http://localhost:8020/ WagyuRegistry",
"remove-local": "graph remove --node http://localhost:8020/ WagyuRegistry",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 WagyuRegistry"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.24.0",
"@graphprotocol/graph-ts": "0.24.0",
"node-fetch": "^3.1.0"
}
}
11 changes: 11 additions & 0 deletions subgraphs/WagyuRegistry/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Token @entity {
id: ID!
hash: String
name: String!
symbol: String!
address: String!
decimals: String!
chainId: String!
logoURI: String
acttive: Boolean
}
45 changes: 45 additions & 0 deletions subgraphs/WagyuRegistry/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {Value,JSONValue, BigInt, BigDecimal, ipfs, json, Bytes, log } from "@graphprotocol/graph-ts"

import {
TokenAdded
} from "../generated/WagyuRegistry/WagyuRegistry"
import { Token } from "../generated/schema"




export function handleTokenAdded(event: TokenAdded): void {



let data = ipfs.cat(event.params._hash);

if (!data || (data as Bytes).length < 1) {
log.warning('JSON DATA FROM IPFS IS EMPTY {}', [event.params._hash]);
return;
}

let jsonData = json.fromBytes(data as Bytes);
if (jsonData.isNull()) {
log.warning('JSON DATA FROM IPFS IS NULL {}', [event.params._hash]);
return;
}



let token = new Token(event.params._hash);
token.hash=event.params._hash;

token.name=jsonData.toObject().get('tokenName').toString();
token.symbol=jsonData.toObject().get('tokenSymbol').toString();
token.address=jsonData.toObject().get('tokenAddress').toString();
token.chainId=jsonData.toObject().get('chainId').toString();
token.decimals=jsonData.toObject().get('tokenDecimals').toString();

token.logoURI=jsonData.toObject().get('icon').toString();

token.save();



}
24 changes: 24 additions & 0 deletions subgraphs/WagyuRegistry/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
specVersion: 0.0.2
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: WagyuRegistry
network: velas
source:
address: "0xa39D26ac57930604Aaeb4Ad6353628Ab5b24Fc47"
abi: WagyuRegistry
startBlock: 4843618
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
entities:
- TokenAdded
abis:
- name: WagyuRegistry
file: ./abis/WagyuRegistry.json
eventHandlers:
- event: TokenAdded(string)
handler: handleTokenAdded
file: ./src/mapping.ts
4 changes: 4 additions & 0 deletions subgraphs/WagyuRegistry/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@graphprotocol/graph-ts/types/tsconfig.base.json",
"include": ["src"]
}
Loading