Skip to content

Commit

Permalink
Merge pull request #160 from moleculeprotocol/fix/subgraph-caps
Browse files Browse the repository at this point in the history
subgraph: adds capped handler
  • Loading branch information
elmariachi111 authored Jul 12, 2024
2 parents 10a42a1 + 713d5a1 commit e1a8fa7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 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.1.0 --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.1.1 --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.0.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
1 change: 1 addition & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type IPT @entity {
# these will be updated by the underlying IPT subgraph template
totalIssued: BigInt! #the highest amount of IPTs issued, this can be raised by the owner
circulatingSupply: BigInt! #the amount of unburnt IPTs
capped: Boolean! #whether the IPT is capped
# paymentToken: Bytes #address ERC20 Token
# paidPrice: BigInt #the price paid for the original ipnft
# claimedShares: BigInt! # the amount of shares that have already been claimed. This needs to have a fulfilledListingId to be set
Expand Down
12 changes: 11 additions & 1 deletion subgraph/src/iptMapping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigInt, log } from '@graphprotocol/graph-ts'
import { IPT, IPTBalance } from '../generated/schema'
import { Transfer as TransferEvent } from '../generated/templates/IPToken/IPToken'
import { Transfer as TransferEvent, Capped as CappedEvent } from '../generated/templates/IPToken/IPToken'

function createOrUpdateBalances(
owner: Address,
Expand All @@ -21,6 +21,16 @@ function createOrUpdateBalances(
balance.save()
}

export function handleCapped(event: CappedEvent): void {
let ipt = IPT.load(event.address.toHexString())
if (!ipt) {
log.error('[IPT] Ipnft not found for id: {}', [event.address.toHexString()])
return
}
ipt.capped = true
ipt.save()
}

export function handleTransfer(event: TransferEvent): void {
let from = event.params.from
let to = event.params.to
Expand Down
1 change: 1 addition & 0 deletions subgraph/src/tokenizerMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function handleIPTsCreated(event: TokensCreatedEvent): void {
//these will be updated by the underlying IPT subgraph template
ipt.totalIssued = BigInt.fromU32(0)
ipt.circulatingSupply = BigInt.fromU32(0)
ipt.capped = false;
IPToken.create(event.params.tokenContract)

ipt.save()
Expand Down

0 comments on commit e1a8fa7

Please sign in to comment.