From 312a681577ef06cace76f5fab06ff040d6de70eb Mon Sep 17 00:00:00 2001 From: mercuricchloride Date: Wed, 11 May 2022 15:55:37 -0700 Subject: [PATCH] Initial commit --- abis/superRare.json | 374 ++++++++++++++++++++++++++++++++++++++++++++ networks.json | 7 + package.json | 16 ++ schema.graphql | 77 +++++++++ src/mapping.ts | 151 ++++++++++++++++++ subgraph.yaml | 46 ++++++ tsconfig.json | 4 + 7 files changed, 675 insertions(+) create mode 100644 abis/superRare.json create mode 100644 networks.json create mode 100644 package.json create mode 100644 schema.graphql create mode 100644 src/mapping.ts create mode 100644 subgraph.yaml create mode 100644 tsconfig.json diff --git a/abis/superRare.json b/abis/superRare.json new file mode 100644 index 0000000..4245a22 --- /dev/null +++ b/abis/superRare.json @@ -0,0 +1,374 @@ +[ + { + "constant": false, + "inputs": [ + { "name": "_uri", "type": "string" }, + { "name": "_editions", "type": "uint256" }, + { "name": "_salePrice", "type": "uint256" } + ], + "name": "addNewTokenWithEditions", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_tokenId", "type": "uint256" }, + { "name": "_salePrice", "type": "uint256" } + ], + "name": "setSalePrice", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [{ "name": "_name", "type": "string" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_to", "type": "address" }, + { "name": "_tokenId", "type": "uint256" } + ], + "name": "approve", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "currentBidDetailsOfToken", + "outputs": [ + { "name": "", "type": "uint256" }, + { "name": "", "type": "address" } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "approvedFor", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "acceptBid", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_creator", "type": "address" }], + "name": "isWhitelisted", + "outputs": [{ "name": "", "type": "bool" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "bid", + "outputs": [], + "payable": true, + "stateMutability": "payable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_owner", "type": "address" }], + "name": "tokensOf", + "outputs": [{ "name": "", "type": "uint256[]" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_percentage", "type": "uint256" }], + "name": "setMaintainerPercentage", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_creator", "type": "address" }], + "name": "whitelistCreator", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "ownerOf", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_uri", "type": "string" }], + "name": "originalTokenOfUri", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_owner", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [{ "name": "_symbol", "type": "string" }], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "cancelBid", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "salePriceOfToken", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { "name": "_to", "type": "address" }, + { "name": "_tokenId", "type": "uint256" } + ], + "name": "transfer", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "takeOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_percentage", "type": "uint256" }], + "name": "setCreatorPercentage", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "tokenURI", + "outputs": [{ "name": "", "type": "string" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "creatorOfToken", + "outputs": [{ "name": "", "type": "address" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_tokenId", "type": "uint256" }], + "name": "buy", + "outputs": [], + "payable": true, + "stateMutability": "payable", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "_uri", "type": "string" }], + "name": "addNewToken", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "creatorPercentage", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "maintainerPercentage", + "outputs": [{ "name": "", "type": "uint256" }], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [{ "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "name": "_creator", "type": "address" }], + "name": "WhitelistCreator", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_bidder", "type": "address" }, + { "indexed": true, "name": "_amount", "type": "uint256" }, + { "indexed": true, "name": "_tokenId", "type": "uint256" } + ], + "name": "Bid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_bidder", "type": "address" }, + { "indexed": true, "name": "_seller", "type": "address" }, + { "indexed": false, "name": "_amount", "type": "uint256" }, + { "indexed": true, "name": "_tokenId", "type": "uint256" } + ], + "name": "AcceptBid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_bidder", "type": "address" }, + { "indexed": true, "name": "_amount", "type": "uint256" }, + { "indexed": true, "name": "_tokenId", "type": "uint256" } + ], + "name": "CancelBid", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_buyer", "type": "address" }, + { "indexed": true, "name": "_seller", "type": "address" }, + { "indexed": false, "name": "_amount", "type": "uint256" }, + { "indexed": true, "name": "_tokenId", "type": "uint256" } + ], + "name": "Sold", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_tokenId", "type": "uint256" }, + { "indexed": true, "name": "_price", "type": "uint256" } + ], + "name": "SalePriceSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "previousOwner", "type": "address" }, + { "indexed": true, "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_from", "type": "address" }, + { "indexed": true, "name": "_to", "type": "address" }, + { "indexed": false, "name": "_tokenId", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "name": "_owner", "type": "address" }, + { "indexed": true, "name": "_approved", "type": "address" }, + { "indexed": false, "name": "_tokenId", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + } +] diff --git a/networks.json b/networks.json new file mode 100644 index 0000000..e9cae79 --- /dev/null +++ b/networks.json @@ -0,0 +1,7 @@ +{ + "mainnet": { + "superRare": { + "address": "0x41a322b28d0ff354040e2cbc676f0320d8c8850d" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..43fb5fc --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "super-rare-proto-reputation", + "license": "UNLICENSED", + "scripts": { + "codegen": "graph codegen", + "build": "graph build", + "deploy": "graph deploy --node https://api.thegraph.com/deploy/ mercuricchloride/super-rare-proto-reputation", + "create-local": "graph create --node http://localhost:8020/ mercuricchloride/super-rare-proto-reputation", + "remove-local": "graph remove --node http://localhost:8020/ mercuricchloride/super-rare-proto-reputation", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 mercuricchloride/super-rare-proto-reputation" + }, + "dependencies": { + "@graphprotocol/graph-cli": "0.30.0-alpha.1", + "@graphprotocol/graph-ts": "0.27.0-alpha.1" + } +} diff --git a/schema.graphql b/schema.graphql new file mode 100644 index 0000000..5c320e5 --- /dev/null +++ b/schema.graphql @@ -0,0 +1,77 @@ +type BaseMetric @entity { + id: ID! + type: EventType! + transactionMetadata: TransactionMetadata! + params: MetricParam! +} + +type TransactionMetadata @entity { + id: ID! # The TxHash toHex() + txValue: BigInt! + timestamp: BigInt! + blockNumber: BigInt! + txTo: Bytes + txFrom: Bytes! + txGas: BigInt! +} + +type InMemoryIncrementStore @entity { + id: ID! # Always 1 = store this const in the mapping and always just retrieve it - then incrementValue++ when new even + incrementValue: BigInt! +} + +type EventType @entity { + id: ID! #ToHex of EventName + name: String! #The Event Name +} + +type MetricParam @entity { + id: ID! + + paramName1: String + paramValue1: String + paramType1: String + + paramName2: String + paramValue2: String + paramType2: String + + paramName3: String + paramValue3: String + paramType3: String + + paramName4: String + paramValue4: String + paramType4: String + + paramName5: String + paramValue5: String + paramType5: String + + paramName6: String + paramValue6: String + paramType6: String +} + +type BadgeType @entity { + id: ID! + name: String! #The Badge + ipfs: String! #The + soul: BigInt! + linkingParam: String! # This is what ties a baseMetric to a user + baseMetric: [BadgeMetricLookup!] #The base +} + +type BadgeMetricLookup @entity { + id: ID! #Combination of BaseMetric ID + BaseID + badge: BadgeType! #Combination of + baseMetric: BaseMetric! +} + +type UserBadge @entity { + id: ID! #BadgeTypeID + UserAddress + badge: BadgeType! #Combination of + account: Bytes! + vanityValue: Bytes! # HOW MUCH THEY HAVE CURATED IN TOTALITY + vanityName: Bytes! # +} diff --git a/src/mapping.ts b/src/mapping.ts new file mode 100644 index 0000000..df9693d --- /dev/null +++ b/src/mapping.ts @@ -0,0 +1,151 @@ +import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts" +import { + superRare, + WhitelistCreator, + Bid, + AcceptBid, + CancelBid, + Sold, + SalePriceSet, + OwnershipTransferred, + Transfer, + Approval +} from "../generated/superRare/superRare" +import { + BaseMetric, + TransactionMetadata, + InMemoryIncrementStore, + EventType, + MetricParam, + BadgeType, + BadgeMetricLookup, + UserBadge +} from "../generated/schema" + +function getOrCreateEventType(eventName: string): EventType { + let entity = EventType.load(eventName) + if (entity == null) { + entity = new EventType(eventName) + entity.save() + } + return entity +} + +function getOrCreateBaseMetric( + event: ethereum.Event, + eventType: EventType +): BaseMetric { + let baseMetricID = + eventType.id + + "-" + + event.transaction.hash.toHexString() + + "-" + + event.logIndex.toHexString() + let entity = new BaseMetric(baseMetricID) + let transactionData = getOrCreateNewTransactionMetadata(event) + entity.transactionMetadata = transactionData.id + entity.type = eventType.id + + let paramsArray = event.parameters as Array + let params = new MetricParam(baseMetricID) + for (let i = 0; i <= paramsArray.length; i++) { + let eventParam = paramsArray[i] as ethereum.EventParam + switch (i) { + case 0: + //@ts-ignore + params.paramName1 = eventParam.name.toString() + params.paramValue1 = eventParam.value.toString() + break + case 1: + //@ts-ignore + params.paramName2 = eventParam.name.toString() + params.paramValue2 = eventParam.value.toString() + break + case 2: + //@ts-ignore + params.paramName3 = eventParam.name.toString() + params.paramValue3 = eventParam.value.toString() + break + case 3: + //@ts-ignore + params.paramName4 = eventParam.name.toString() + params.paramValue4 = eventParam.value.toString() + break + case 4: + //@ts-ignore + params.paramName5 = eventParam.name.toString() + params.paramValue5 = eventParam.value.toString() + break + case 5: + //@ts-ignore + params.paramName6 = eventParam.name.toString() + params.paramValue6 = eventParam.value.toString() + break + default: + break + } + } + entity.save() + return entity +} + +function getOrCreateNewTransactionMetadata( + event: ethereum.Event +): TransactionMetadata { + let transactionMetaData = new TransactionMetadata( + event.transaction.hash.toHex() + "-" + event.logIndex.toHex() + ) + transactionMetaData.txValue = event.transaction.value + transactionMetaData.timestamp = event.block.timestamp + transactionMetaData.blockNumber = event.block.number + transactionMetaData.txTo = event.transaction.to + transactionMetaData.txFrom = event.transaction.from + transactionMetaData.txGas = event.transaction.gasPrice + transactionMetaData.save() + return transactionMetaData +} + +export function handleWhitelistCreator(event: WhitelistCreator): void { + let eventType = getOrCreateEventType("WhitelistCreator") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleBid(event: Bid): void { + let eventType = getOrCreateEventType("Bid") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleAcceptBid(event: AcceptBid): void { + let eventType = getOrCreateEventType("AcceptBid") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleCancelBid(event: CancelBid): void { + let eventType = getOrCreateEventType("CancelBid") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleSold(event: Sold): void { + let eventType = getOrCreateEventType("Sold") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleSalePriceSet(event: SalePriceSet): void { + let eventType = getOrCreateEventType("SalePriceSet") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleOwnershipTransferred(event: OwnershipTransferred): void { + let eventType = getOrCreateEventType("OwnershipTransferred") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleTransfer(event: Transfer): void { + let eventType = getOrCreateEventType("Transfer") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} + +export function handleApproval(event: Approval): void { + let eventType = getOrCreateEventType("Approval") + let baseMetric = getOrCreateBaseMetric(event, eventType) +} diff --git a/subgraph.yaml b/subgraph.yaml new file mode 100644 index 0000000..9e353cd --- /dev/null +++ b/subgraph.yaml @@ -0,0 +1,46 @@ +specVersion: 0.0.1 +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum + name: superRare + network: mainnet + source: + address: "0x41a322b28d0ff354040e2cbc676f0320d8c8850d" + abi: superRare + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - BaseMetric + - TransactionMetadata + - InMemoryIncrementStore + - EventType + - MetricParam + - BadgeType + - BadgeMetricLookup + - UserBadge + abis: + - name: superRare + file: ./abis/superRare.json + eventHandlers: + - event: WhitelistCreator(indexed address) + handler: handleWhitelistCreator + - event: Bid(indexed address,indexed uint256,indexed uint256) + handler: handleBid + - event: AcceptBid(indexed address,indexed address,uint256,indexed uint256) + handler: handleAcceptBid + - event: CancelBid(indexed address,indexed uint256,indexed uint256) + handler: handleCancelBid + - event: Sold(indexed address,indexed address,uint256,indexed uint256) + handler: handleSold + - event: SalePriceSet(indexed uint256,indexed uint256) + handler: handleSalePriceSet + - event: OwnershipTransferred(indexed address,indexed address) + handler: handleOwnershipTransferred + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + - event: Approval(indexed address,indexed address,uint256) + handler: handleApproval + file: ./src/mapping.ts diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5c5d17c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src"] +}