Skip to content

Commit

Permalink
adds a single ipt address field for easier frontend queries
Browse files Browse the repository at this point in the history
uses strings for the funding amount

Signed-off-by: Stefan Adolf <[email protected]>
  • Loading branch information
elmariachi111 committed Jan 16, 2025
1 parent f747295 commit c38ef8a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 60 deletions.
2 changes: 1 addition & 1 deletion subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build:sepolia": "graph codegen && graph build --network sepolia",
"build:mainnet": "graph codegen && graph build --network mainnet",
"deploy:local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 moleculeprotocol/ipnft-subgraph",
"deploy:sepolia": "env-cmd -x -f ../.env graph deploy ip-nft-sepolia --version-label 1.3.1-dev.1 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
"deploy:sepolia": "env-cmd -x -f ../.env graph deploy ip-nft-sepolia --version-label 1.3.1-dev.8 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
"deploy:mainnet": "env-cmd -x -f ../.env graph deploy ip-nft-mainnet --version-label 1.3.0 --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz --deploy-key \\$SATSUMA_DEPLOY_KEY",
"create:local": "graph create --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",
"remove:local": "graph remove --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",
Expand Down
18 changes: 11 additions & 7 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ type Ipnft @entity {
ipts: [IPT!] @derivedFrom(field: "ipnft")
metadata: IpnftMetadata
updatedAtTimestamp: BigInt

# as of 1.3 the Tokenizer only will create 1 ipt instance, in contrast to the ipts field above.
ipToken: Bytes
}

type IpnftMetadata @entity {
Expand All @@ -17,17 +20,18 @@ type IpnftMetadata @entity {
image: String!
description: String!
externalURL: String!
initialSymbol: String!
organization: String!
topic: String!

initialSymbol: String
organization: String
topic: String

researchLead_name: String
researchLead_email: String

fundingAmount_value: Int!
fundingAmount_decimals: Int8!
fundingAmount_currency: String!
fundingAmount_currencyType: String!
fundingAmount_value: String
fundingAmount_decimals: Int8
fundingAmount_currency: String
fundingAmount_currencyType: String
}


Expand Down
4 changes: 2 additions & 2 deletions subgraph/src/ipnftMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ export function handleMint(event: IPNFTMintedEvent): void {
export function handleMetadataUpdated(event: MetadataUpdateEvent): void {
let ipnft = Ipnft.load(event.params._tokenId.toString())
if (!ipnft) {
log.error('ipnft {} not found', [event.params._tokenId.toString()])
log.error('[handleMetadataUpdated] ipnft {} not found', [event.params._tokenId.toString()])
return
}

//erc4906 is not emitting the new url, we must query it ourselves
let _ipnftContract = IPNFTContract.bind(event.params._event.address)
let newUri = _ipnftContract.tokenURI(event.params._tokenId)
if (!newUri || newUri == '') {
log.debug('no new uri found for token, likely just minted {}', [
log.debug('[handleMetadataUpdated] no new uri found for token, likely just minted {}', [
event.params._tokenId.toString()
])
return
Expand Down
105 changes: 56 additions & 49 deletions subgraph/src/metadataMapping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, Bytes, dataSource, } from '@graphprotocol/graph-ts'
import { json, Bytes, dataSource, log } from '@graphprotocol/graph-ts'
import { IpnftMetadata } from '../generated/schema'

export function handleMetadata(content: Bytes): void {
Expand All @@ -9,70 +9,77 @@ export function handleMetadata(content: Bytes): void {
const description = value.get('description')
const externalURL = value.get('external_url')

let ipnftMetadata = new IpnftMetadata(dataSource.stringParam())

if (name && image && description && externalURL) {
let ipnftMetadata = new IpnftMetadata(dataSource.stringParam())
ipnftMetadata.name = name.toString()
ipnftMetadata.image = image.toString()
ipnftMetadata.externalURL = externalURL.toString()
ipnftMetadata.description = description.toString()


const _properties = value.get('properties')
if (_properties) {
const properties = _properties.toObject()
const initial_symbol = properties.get('initial_symbol')
if (initial_symbol) {
ipnftMetadata.initialSymbol = initial_symbol.toString()
}
ipnftMetadata.save()
} else {
log.info("[handlemetadata] name, image, description, external_url not found", [])
}

const _project_details = properties.get('project_details')
let _properties = value.get('properties')
if (_properties) {
let properties = _properties.toObject()
let _initial_symbol = properties.get('initial_symbol')
if (_initial_symbol) {
ipnftMetadata.initialSymbol = _initial_symbol.toString()
} else {
ipnftMetadata.initialSymbol = ""
log.info("[handlemetadata] initial_symbol not found", [])
}

if (_project_details) {
let projectDetails = _project_details.toObject()
let _project_details = properties.get('project_details')

let _organization = projectDetails.get('organization')
if (_organization) {
ipnftMetadata.organization = _organization.toString()
}
if (_project_details) {
let projectDetails = _project_details.toObject()

let _topic = projectDetails.get('topic')
if (_topic) {
ipnftMetadata.topic = _topic.toString()
}
let _organization = projectDetails.get('organization')
if (_organization) {
ipnftMetadata.organization = _organization.toString()
}

let _research_lead = projectDetails.get('research_lead')
let _topic = projectDetails.get('topic')
if (_topic) {
ipnftMetadata.topic = _topic.toString()
}

if (_research_lead) {
let researchLead = _research_lead.toObject()
let researchLead_email = researchLead.get('email')
let researchLead_name = researchLead.get('name')

if (researchLead_email && researchLead_name) {
ipnftMetadata.researchLead_email = researchLead_email.toString()
ipnftMetadata.researchLead_name = researchLead_name.toString()
}
}
let _research_lead = projectDetails.get('research_lead')

let _funding_amount = properties.get('funding_amount')
if (_funding_amount) {
let funding_amount = _funding_amount.toObject()
let _fundingAmount_value = funding_amount.get('value')
let _fundingAmount_decimals = funding_amount.get('decimals')
let _fundingAmount_currency = funding_amount.get('currency')
let _fundingAmount_currencyType = funding_amount.get('currency_type')

if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
ipnftMetadata.fundingAmount_value = i32(_fundingAmount_value.toI64())
ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
}
if (_research_lead) {
let researchLead = _research_lead.toObject()
let researchLead_email = researchLead.get('email')
let researchLead_name = researchLead.get('name')

if (researchLead_email && researchLead_name) {
ipnftMetadata.researchLead_email = researchLead_email.toString()
ipnftMetadata.researchLead_name = researchLead_name.toString()
}
}
}

ipnftMetadata.save()
let _funding_amount = properties.get('funding_amount')
if (_funding_amount) {
let funding_amount = _funding_amount.toObject()
let _fundingAmount_value = funding_amount.get('value')
let _fundingAmount_decimals = funding_amount.get('decimals')
let _fundingAmount_currency = funding_amount.get('currency')
let _fundingAmount_currencyType = funding_amount.get('currency_type')

if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
// on json metadata this can be a decimal value. I'm using a string to store as there's imo no f64 compatible decimal type on the schema scalar types
// https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
ipnftMetadata.fundingAmount_value = _fundingAmount_value.toF64().toString()
ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
}
}
}
}

ipnftMetadata.save()
}
}
8 changes: 7 additions & 1 deletion subgraph/src/tokenizerMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TokensCreated as TokensCreatedEvent } from '../generated/Tokenizer/Toke

import { IPToken } from '../generated/templates'

import { IPT } from '../generated/schema'
import { IPT, Ipnft } from '../generated/schema'

export function handleIPTsCreated(event: TokensCreatedEvent): void {
let ipt = new IPT(event.params.tokenContract.toHexString())
Expand All @@ -23,4 +23,10 @@ export function handleIPTsCreated(event: TokensCreatedEvent): void {
IPToken.create(event.params.tokenContract)

ipt.save()

let ipnft = Ipnft.load(event.params.ipnftId.toString());
if (ipnft) {
ipnft.ipToken = event.params.tokenContract
ipnft.save()
}
}

0 comments on commit c38ef8a

Please sign in to comment.