Skip to content

Commit

Permalink
happy first throw at subgraphs
Browse files Browse the repository at this point in the history
regnerated ABIs & tested this with a local setup

Signed-off-by: stadolf <[email protected]>
  • Loading branch information
elmariachi111 committed Jul 5, 2024
1 parent b58a912 commit 16a696b
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 89 deletions.
61 changes: 14 additions & 47 deletions subgraph/abis/IPToken.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,6 @@
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "hash",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "increaseAllowance",
Expand Down Expand Up @@ -200,6 +187,11 @@
"type": "function",
"name": "initialize",
"inputs": [
{
"name": "ipnftId",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "name",
"type": "string",
Expand All @@ -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": [],
Expand All @@ -254,19 +234,6 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "issuer",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "metadata",
Expand Down Expand Up @@ -545,7 +512,7 @@
},
{
"type": "error",
"name": "OnlyIssuerOrOwner",
"name": "MustOwnIpnft",
"inputs": []
},
{
Expand Down
5 changes: 0 additions & 5 deletions subgraph/abis/SharedSalesDistributor.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,5 @@
"type": "error",
"name": "OnlyIssuer",
"inputs": []
},
{
"type": "error",
"name": "UncappedToken",
"inputs": []
}
]
125 changes: 117 additions & 8 deletions subgraph/abis/Tokenizer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -79,9 +134,9 @@
"name": "reinit",
"inputs": [
{
"name": "_permissioner",
"name": "_ipTokenImplementation",
"type": "address",
"internalType": "contract IPermissioner"
"internalType": "contract IPToken"
}
],
"outputs": [],
Expand Down Expand Up @@ -315,12 +370,6 @@
"type": "event",
"name": "TokensCreated",
"inputs": [
{
"name": "moleculesId",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
},
{
"name": "ipnftId",
"type": "uint256",
Expand Down Expand Up @@ -384,6 +433,11 @@
"name": "AlreadyTokenized",
"inputs": []
},
{
"type": "error",
"name": "IPTNotControlledByTokenizer",
"inputs": []
},
{
"type": "error",
"name": "MustOwnIpnft",
Expand Down Expand Up @@ -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
}
]
56 changes: 55 additions & 1 deletion subgraph/makeAbis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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
Expand Down
36 changes: 11 additions & 25 deletions subgraph/src/tokenizerMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// }
Loading

0 comments on commit 16a696b

Please sign in to comment.