Skip to content

Commit c38ef8a

Browse files
committed
adds a single ipt address field for easier frontend queries
uses strings for the funding amount Signed-off-by: Stefan Adolf <[email protected]>
1 parent f747295 commit c38ef8a

File tree

5 files changed

+77
-60
lines changed

5 files changed

+77
-60
lines changed

subgraph/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build:sepolia": "graph codegen && graph build --network sepolia",
99
"build:mainnet": "graph codegen && graph build --network mainnet",
1010
"deploy:local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 moleculeprotocol/ipnft-subgraph",
11-
"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",
11+
"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",
1212
"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",
1313
"create:local": "graph create --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",
1414
"remove:local": "graph remove --node http://localhost:8020/ moleculeprotocol/ipnft-subgraph",

subgraph/schema.graphql

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ type Ipnft @entity {
99
ipts: [IPT!] @derivedFrom(field: "ipnft")
1010
metadata: IpnftMetadata
1111
updatedAtTimestamp: BigInt
12+
13+
# as of 1.3 the Tokenizer only will create 1 ipt instance, in contrast to the ipts field above.
14+
ipToken: Bytes
1215
}
1316

1417
type IpnftMetadata @entity {
@@ -17,17 +20,18 @@ type IpnftMetadata @entity {
1720
image: String!
1821
description: String!
1922
externalURL: String!
20-
initialSymbol: String!
21-
organization: String!
22-
topic: String!
23+
24+
initialSymbol: String
25+
organization: String
26+
topic: String
2327

2428
researchLead_name: String
2529
researchLead_email: String
2630

27-
fundingAmount_value: Int!
28-
fundingAmount_decimals: Int8!
29-
fundingAmount_currency: String!
30-
fundingAmount_currencyType: String!
31+
fundingAmount_value: String
32+
fundingAmount_decimals: Int8
33+
fundingAmount_currency: String
34+
fundingAmount_currencyType: String
3135
}
3236

3337

subgraph/src/ipnftMapping.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ export function handleMint(event: IPNFTMintedEvent): void {
106106
export function handleMetadataUpdated(event: MetadataUpdateEvent): void {
107107
let ipnft = Ipnft.load(event.params._tokenId.toString())
108108
if (!ipnft) {
109-
log.error('ipnft {} not found', [event.params._tokenId.toString()])
109+
log.error('[handleMetadataUpdated] ipnft {} not found', [event.params._tokenId.toString()])
110110
return
111111
}
112112

113113
//erc4906 is not emitting the new url, we must query it ourselves
114114
let _ipnftContract = IPNFTContract.bind(event.params._event.address)
115115
let newUri = _ipnftContract.tokenURI(event.params._tokenId)
116116
if (!newUri || newUri == '') {
117-
log.debug('no new uri found for token, likely just minted {}', [
117+
log.debug('[handleMetadataUpdated] no new uri found for token, likely just minted {}', [
118118
event.params._tokenId.toString()
119119
])
120120
return

subgraph/src/metadataMapping.ts

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { json, Bytes, dataSource, } from '@graphprotocol/graph-ts'
1+
import { json, Bytes, dataSource, log } from '@graphprotocol/graph-ts'
22
import { IpnftMetadata } from '../generated/schema'
33

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

12+
let ipnftMetadata = new IpnftMetadata(dataSource.stringParam())
13+
1214
if (name && image && description && externalURL) {
13-
let ipnftMetadata = new IpnftMetadata(dataSource.stringParam())
1415
ipnftMetadata.name = name.toString()
1516
ipnftMetadata.image = image.toString()
1617
ipnftMetadata.externalURL = externalURL.toString()
1718
ipnftMetadata.description = description.toString()
1819

19-
20-
const _properties = value.get('properties')
21-
if (_properties) {
22-
const properties = _properties.toObject()
23-
const initial_symbol = properties.get('initial_symbol')
24-
if (initial_symbol) {
25-
ipnftMetadata.initialSymbol = initial_symbol.toString()
26-
}
20+
ipnftMetadata.save()
21+
} else {
22+
log.info("[handlemetadata] name, image, description, external_url not found", [])
23+
}
2724

28-
const _project_details = properties.get('project_details')
25+
let _properties = value.get('properties')
26+
if (_properties) {
27+
let properties = _properties.toObject()
28+
let _initial_symbol = properties.get('initial_symbol')
29+
if (_initial_symbol) {
30+
ipnftMetadata.initialSymbol = _initial_symbol.toString()
31+
} else {
32+
ipnftMetadata.initialSymbol = ""
33+
log.info("[handlemetadata] initial_symbol not found", [])
34+
}
2935

30-
if (_project_details) {
31-
let projectDetails = _project_details.toObject()
36+
let _project_details = properties.get('project_details')
3237

33-
let _organization = projectDetails.get('organization')
34-
if (_organization) {
35-
ipnftMetadata.organization = _organization.toString()
36-
}
38+
if (_project_details) {
39+
let projectDetails = _project_details.toObject()
3740

38-
let _topic = projectDetails.get('topic')
39-
if (_topic) {
40-
ipnftMetadata.topic = _topic.toString()
41-
}
41+
let _organization = projectDetails.get('organization')
42+
if (_organization) {
43+
ipnftMetadata.organization = _organization.toString()
44+
}
4245

43-
let _research_lead = projectDetails.get('research_lead')
46+
let _topic = projectDetails.get('topic')
47+
if (_topic) {
48+
ipnftMetadata.topic = _topic.toString()
49+
}
4450

45-
if (_research_lead) {
46-
let researchLead = _research_lead.toObject()
47-
let researchLead_email = researchLead.get('email')
48-
let researchLead_name = researchLead.get('name')
49-
50-
if (researchLead_email && researchLead_name) {
51-
ipnftMetadata.researchLead_email = researchLead_email.toString()
52-
ipnftMetadata.researchLead_name = researchLead_name.toString()
53-
}
54-
}
51+
let _research_lead = projectDetails.get('research_lead')
5552

56-
let _funding_amount = properties.get('funding_amount')
57-
if (_funding_amount) {
58-
let funding_amount = _funding_amount.toObject()
59-
let _fundingAmount_value = funding_amount.get('value')
60-
let _fundingAmount_decimals = funding_amount.get('decimals')
61-
let _fundingAmount_currency = funding_amount.get('currency')
62-
let _fundingAmount_currencyType = funding_amount.get('currency_type')
63-
64-
if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
65-
ipnftMetadata.fundingAmount_value = i32(_fundingAmount_value.toI64())
66-
ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
67-
ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
68-
ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
69-
}
53+
if (_research_lead) {
54+
let researchLead = _research_lead.toObject()
55+
let researchLead_email = researchLead.get('email')
56+
let researchLead_name = researchLead.get('name')
57+
58+
if (researchLead_email && researchLead_name) {
59+
ipnftMetadata.researchLead_email = researchLead_email.toString()
60+
ipnftMetadata.researchLead_name = researchLead_name.toString()
7061
}
7162
}
72-
}
7363

74-
ipnftMetadata.save()
64+
let _funding_amount = properties.get('funding_amount')
65+
if (_funding_amount) {
66+
let funding_amount = _funding_amount.toObject()
67+
let _fundingAmount_value = funding_amount.get('value')
68+
let _fundingAmount_decimals = funding_amount.get('decimals')
69+
let _fundingAmount_currency = funding_amount.get('currency')
70+
let _fundingAmount_currencyType = funding_amount.get('currency_type')
71+
72+
if (_fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType) {
73+
// 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
74+
// https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
75+
ipnftMetadata.fundingAmount_value = _fundingAmount_value.toF64().toString()
76+
ipnftMetadata.fundingAmount_decimals = i8(_fundingAmount_decimals.toI64())
77+
ipnftMetadata.fundingAmount_currency = _fundingAmount_currency.toString()
78+
ipnftMetadata.fundingAmount_currencyType = _fundingAmount_currencyType.toString()
79+
}
80+
}
81+
}
7582
}
76-
83+
ipnftMetadata.save()
7784
}
7885
}

subgraph/src/tokenizerMapping.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TokensCreated as TokensCreatedEvent } from '../generated/Tokenizer/Toke
33

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

6-
import { IPT } from '../generated/schema'
6+
import { IPT, Ipnft } from '../generated/schema'
77

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

2525
ipt.save()
26+
27+
let ipnft = Ipnft.load(event.params.ipnftId.toString());
28+
if (ipnft) {
29+
ipnft.ipToken = event.params.tokenContract
30+
ipnft.save()
31+
}
2632
}

0 commit comments

Comments
 (0)