From 16a696be341fe75a520ec1fa69e2828d33bbe26a Mon Sep 17 00:00:00 2001 From: stadolf Date: Fri, 5 Jul 2024 14:48:53 +0200 Subject: [PATCH] happy first throw at subgraphs regnerated ABIs & tested this with a local setup Signed-off-by: stadolf --- subgraph/abis/IPToken.json | 61 +++-------- subgraph/abis/SharedSalesDistributor.json | 5 - subgraph/abis/Tokenizer.json | 125 ++++++++++++++++++++-- subgraph/makeAbis.sh | 56 +++++++++- subgraph/src/tokenizerMapping.ts | 36 ++----- subgraph/subgraph.template.yaml | 6 +- 6 files changed, 200 insertions(+), 89 deletions(-) diff --git a/subgraph/abis/IPToken.json b/subgraph/abis/IPToken.json index a3300de1..17730b81 100644 --- a/subgraph/abis/IPToken.json +++ b/subgraph/abis/IPToken.json @@ -159,19 +159,6 @@ ], "stateMutability": "nonpayable" }, - { - "type": "function", - "name": "hash", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "uint256", - "internalType": "uint256" - } - ], - "stateMutability": "view" - }, { "type": "function", "name": "increaseAllowance", @@ -200,6 +187,11 @@ "type": "function", "name": "initialize", "inputs": [ + { + "name": "ipnftId", + "type": "uint256", + "internalType": "uint256" + }, { "name": "name", "type": "string", @@ -211,26 +203,14 @@ "internalType": "string" }, { - "name": "metadata_", - "type": "tuple", - "internalType": "struct Metadata", - "components": [ - { - "name": "ipnftId", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "originalOwner", - "type": "address", - "internalType": "address" - }, - { - "name": "agreementCid", - "type": "string", - "internalType": "string" - } - ] + "name": "originalOwner", + "type": "address", + "internalType": "address" + }, + { + "name": "agreementCid", + "type": "string", + "internalType": "string" } ], "outputs": [], @@ -254,19 +234,6 @@ "outputs": [], "stateMutability": "nonpayable" }, - { - "type": "function", - "name": "issuer", - "inputs": [], - "outputs": [ - { - "name": "", - "type": "address", - "internalType": "address" - } - ], - "stateMutability": "view" - }, { "type": "function", "name": "metadata", @@ -545,7 +512,7 @@ }, { "type": "error", - "name": "OnlyIssuerOrOwner", + "name": "MustOwnIpnft", "inputs": [] }, { diff --git a/subgraph/abis/SharedSalesDistributor.json b/subgraph/abis/SharedSalesDistributor.json index 82976d74..8291dfd0 100644 --- a/subgraph/abis/SharedSalesDistributor.json +++ b/subgraph/abis/SharedSalesDistributor.json @@ -372,10 +372,5 @@ "type": "error", "name": "OnlyIssuer", "inputs": [] - }, - { - "type": "error", - "name": "UncappedToken", - "inputs": [] } ] diff --git a/subgraph/abis/Tokenizer.json b/subgraph/abis/Tokenizer.json index 47b09165..ec86c282 100644 --- a/subgraph/abis/Tokenizer.json +++ b/subgraph/abis/Tokenizer.json @@ -4,6 +4,19 @@ "inputs": [], "stateMutability": "nonpayable" }, + { + "type": "function", + "name": "cap", + "inputs": [ + { + "name": "ipToken", + "type": "address", + "internalType": "contract IPToken" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, { "type": "function", "name": "initialize", @@ -35,6 +48,29 @@ ], "stateMutability": "view" }, + { + "type": "function", + "name": "issue", + "inputs": [ + { + "name": "ipToken", + "type": "address", + "internalType": "contract IPToken" + }, + { + "name": "amount", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "receiver", + "type": "address", + "internalType": "address" + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, { "type": "function", "name": "owner", @@ -48,6 +84,25 @@ ], "stateMutability": "view" }, + { + "type": "function", + "name": "ownerOf", + "inputs": [ + { + "name": "ipnftId", + "type": "uint256", + "internalType": "uint256" + } + ], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, { "type": "function", "name": "permissioner", @@ -79,9 +134,9 @@ "name": "reinit", "inputs": [ { - "name": "_permissioner", + "name": "_ipTokenImplementation", "type": "address", - "internalType": "contract IPermissioner" + "internalType": "contract IPToken" } ], "outputs": [], @@ -315,12 +370,6 @@ "type": "event", "name": "TokensCreated", "inputs": [ - { - "name": "moleculesId", - "type": "uint256", - "indexed": true, - "internalType": "uint256" - }, { "name": "ipnftId", "type": "uint256", @@ -384,6 +433,11 @@ "name": "AlreadyTokenized", "inputs": [] }, + { + "type": "error", + "name": "IPTNotControlledByTokenizer", + "inputs": [] + }, { "type": "error", "name": "MustOwnIpnft", @@ -448,5 +502,60 @@ ], "name": "MoleculesCreated", "type": "event" + }, + { + "type": "event", + "name": "TokensCreated", + "inputs": [ + { + "name": "moleculesId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "ipnftId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "tokenContract", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "emitter", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "agreementCid", + "type": "string", + "indexed": false, + "internalType": "string" + }, + { + "name": "name", + "type": "string", + "indexed": false, + "internalType": "string" + }, + { + "name": "symbol", + "type": "string", + "indexed": false, + "internalType": "string" + } + ], + "anonymous": false } ] diff --git a/subgraph/makeAbis.sh b/subgraph/makeAbis.sh index f701bb67..c46e627d 100755 --- a/subgraph/makeAbis.sh +++ b/subgraph/makeAbis.sh @@ -13,7 +13,7 @@ cat ../out/CrowdSale.sol/CrowdSale.json | jq .abi > ./abis/CrowdSale.json cat ../out/Tokenizer.sol/Tokenizer.json | jq .abi > ./abis/_Tokenizer.json -# add the old Synthesizer's `MoleculesCreated` event to the Tokenizer abi so the subgraph can index them +# add the old Synthesizer's `MoleculesCreated` and `TokensCreated` event to the Tokenizer abi so the subgraph can index them jq '. += [{ "anonymous": false, "inputs": [ @@ -68,6 +68,60 @@ jq '. += [{ ], "name": "MoleculesCreated", "type": "event" + },{ + "type": "event", + "name": "TokensCreated", + "inputs": [ + { + "name": "moleculesId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "ipnftId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + }, + { + "name": "tokenContract", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "emitter", + "type": "address", + "indexed": false, + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "indexed": false, + "internalType": "uint256" + }, + { + "name": "agreementCid", + "type": "string", + "indexed": false, + "internalType": "string" + }, + { + "name": "name", + "type": "string", + "indexed": false, + "internalType": "string" + }, + { + "name": "symbol", + "type": "string", + "indexed": false, + "internalType": "string" + } + ], + "anonymous": false }]' ./abis/_Tokenizer.json > ./abis/Tokenizer.json rm ./abis/_Tokenizer.json diff --git a/subgraph/src/tokenizerMapping.ts b/subgraph/src/tokenizerMapping.ts index 91fb5c87..bb8c2223 100644 --- a/subgraph/src/tokenizerMapping.ts +++ b/subgraph/src/tokenizerMapping.ts @@ -6,34 +6,20 @@ import { IPToken } from '../generated/templates' import { IPT } from '../generated/schema' export function handleIPTsCreated(event: TokensCreatedEvent): void { - let reacted = new IPT(event.params.tokenContract.toHexString()) + let ipt = new IPT(event.params.tokenContract.toHexString()) - reacted.createdAt = event.block.timestamp - reacted.ipnft = event.params.ipnftId.toString() - reacted.agreementCid = event.params.agreementCid - reacted.originalOwner = event.params.emitter - reacted.symbol = event.params.symbol - reacted.name = event.params.name - reacted.decimals = BigInt.fromU32(18) + ipt.createdAt = event.block.timestamp + ipt.ipnft = event.params.ipnftId.toString() + ipt.agreementCid = event.params.agreementCid + ipt.originalOwner = event.params.emitter + ipt.symbol = event.params.symbol + ipt.name = event.params.name + ipt.decimals = BigInt.fromU32(18) //these will be updated by the underlying IPT subgraph template - reacted.totalIssued = BigInt.fromU32(0) - reacted.circulatingSupply = BigInt.fromU32(0) + ipt.totalIssued = BigInt.fromU32(0) + ipt.circulatingSupply = BigInt.fromU32(0) IPToken.create(event.params.tokenContract) - reacted.save() + ipt.save() } - -// export function handleSalesActivated(event: SalesActivatedEvent): void { -// let reacted = ReactedIpnft.load(event.params.moleculesId.toString()); -// if (!reacted) { -// log.error('ReactedIpnft not found for id: {}', [ -// event.params.moleculesId.toString() -// ]); -// return; -// } -// reacted.paymentToken = event.params.paymentToken; -// reacted.paidPrice = event.params.paidPrice; -// reacted.claimedShares = BigInt.fromI32(0); -// reacted.save(); -// } diff --git a/subgraph/subgraph.template.yaml b/subgraph/subgraph.template.yaml index 5636c0d8..7fb7ca67 100644 --- a/subgraph/subgraph.template.yaml +++ b/subgraph/subgraph.template.yaml @@ -72,13 +72,13 @@ dataSources: - name: Tokenizer file: ./abis/Tokenizer.json eventHandlers: + - event: TokensCreated(indexed uint256,indexed address,address,uint256,string,string,string) + handler: handleIPTsCreated + # legacy events, used to index mainnet - event: TokensCreated(indexed uint256,indexed uint256,indexed address,address,uint256,string,string,string) handler: handleIPTsCreated - # the legacy event - event: MoleculesCreated(indexed uint256,indexed uint256,indexed address,address,uint256,string,string,string) handler: handleIPTsCreated - # - event: SalesActivated(uint256,address,uint256) - # handler: handleSalesActivated # - event: TermsAccepted(indexed uint256,indexed address,bytes) # handler: handleTermsAccepted file: ./src/tokenizerMapping.ts