Skip to content

Commit

Permalink
feat: update for token registry v4 stable (#11)
Browse files Browse the repository at this point in the history
* feat: update to token registry v4.1.6

* feat: replace goerli with mumbai

* docs: update readme
  • Loading branch information
superical authored Aug 3, 2023
1 parent 77008c6 commit d1a2c8d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

The subgraph for the OpenAttestation [Token Registry](https://github.com/Open-Attestation/token-registry) contracts.

> ⚠️ Note that this subgraph is currently implemented to work only with the latest [beta](https://github.com/Open-Attestation/token-registry/tree/beta) version of the Token Registry contracts.
This subgraph allows anyone to easily query the network for information about the records from and create opportunities for applications to build on top of your Token Registry contracts.

## Table of Contents
Expand All @@ -22,7 +20,7 @@ Configure your Token Registry contract addresses in the `config.json` file.

```json
{
"network": "goerli",
"network": "mumbai",
"dataSources": [
{
"address": "0xabc",
Expand All @@ -33,7 +31,7 @@ Configure your Token Registry contract addresses in the `config.json` file.
}
```

* The `network` field can be any one of the many network names supported by the Graph protocol, for eg, `mainnet` for Ethereum mainnet, `matic` for Polygon, `mumbai` for Polygon Mumbai, etc.
* The `network` field can be any one of the many network names supported by the Graph protocol, for eg, `mainnet` for Ethereum mainnet, `goerli` for Ethereum Goerli, `matic` for Polygon, `mumbai` for Polygon Mumbai, etc.
* The `address` is the address of your Token Registry contract and `startBlock` is the start block of your contract.
* You can index multiple Token Registry contracts by adding to the `dataSources` array

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "goerli",
"network": "mumbai",
"dataSources": [
{
"address": "0xabc",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 token-registry-subgraph"
},
"devDependencies": {
"@govtechsg/token-registry": "^4.0.0-beta.18",
"@govtechsg/token-registry": "^4.1.6",
"@graphprotocol/graph-cli": "0.26.0",
"@graphprotocol/graph-ts": "0.24.1",
"handlebars": "^4.7.7"
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address } from "@graphprotocol/graph-ts";
import { Transfer as TransferEvent } from "../generated/TradeTrustERC721/TradeTrustERC721";
import { Transfer as TransferEvent } from "../generated/TradeTrustToken/TradeTrustToken";
import { TitleEscrow as TitleEscrowTemplate } from "../generated/templates";

export function handleTransfer(event: TransferEvent): void {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/fetchers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Address, BigInt, ethereum, log } from "@graphprotocol/graph-ts";
import { Account, TitleEscrow, Token, TokenRegistry, Transaction } from "../../generated/schema";
import { TradeTrustERC721 } from "../../generated/TradeTrustERC721/TradeTrustERC721";
import { TradeTrustToken } from "../../generated/TradeTrustToken/TradeTrustToken";
import {
TitleEscrow as TitleEscrowContract,
TokenReceived as TokenReceivedEvent,
Expand Down Expand Up @@ -33,7 +33,7 @@ export function fetchTokenRegistry(tokenRegistryAddress: Address): TokenRegistry
let registry = TokenRegistry.load(tokenRegistryAddress.toHex());

if (registry == null) {
const tokenRegistry = TradeTrustERC721.bind(tokenRegistryAddress);
const tokenRegistry = TradeTrustToken.bind(tokenRegistryAddress);
registry = new TokenRegistry(tokenRegistryAddress.toHex());
const tryRegistryName = tokenRegistry.try_name();
const tryRegistrySymbol = tokenRegistry.try_symbol();
Expand All @@ -50,7 +50,7 @@ export function fetchToken(registry: TokenRegistry, tokenId: BigInt): Token {
let token = Token.load(id);

if (token == null) {
const tokenRegistry = TradeTrustERC721.bind(Address.fromString(registry.id));
const tokenRegistry = TradeTrustToken.bind(Address.fromString(registry.id));
const tryOwnerOfToken = tokenRegistry.try_ownerOf(tokenId);

const tokenOwner: Address | null = tryOwnerOfToken.reverted ? null : tryOwnerOfToken.value;
Expand Down
18 changes: 9 additions & 9 deletions templates/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ schema:
dataSources:
# {{#each dataSources}}
- kind: ethereum
name: TradeTrustERC721
name: TradeTrustToken
network: {{network}}
source:
abi: TradeTrustERC721
abi: TradeTrustToken
address: "{{address}}"
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- TradeTrustERC721
- TradeTrustToken
- TitleEscrow
abis:
- name: TradeTrustERC721
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TradeTrustERC721Base.sol/TradeTrustERC721Base.json
- name: TradeTrustToken
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TradeTrustToken.sol/TradeTrustToken.json
- name: TitleEscrowFactory
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TitleEscrowFactory.sol/TitleEscrowFactory.json
- name: TitleEscrow
Expand All @@ -42,15 +42,15 @@ templates:
language: wasm/assemblyscript
file: ./src/escrow.ts
entities:
- TitleEscrowCloneable
- TradeTrustERC721
- TitleEscrow
- TradeTrustToken
abis:
- name: TitleEscrow
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TitleEscrow.sol/TitleEscrow.json
- name: TitleEscrowFactory
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TitleEscrowFactory.sol/TitleEscrowFactory.json
- name: TradeTrustERC721
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TradeTrustERC721Base.sol/TradeTrustERC721Base.json
- name: TradeTrustToken
file: ./node_modules/@govtechsg/token-registry/dist/artifacts/TradeTrustToken.sol/TradeTrustToken.json
eventHandlers:
- event: Surrender(indexed address,address,uint256)
handler: handleSurrender
Expand Down

0 comments on commit d1a2c8d

Please sign in to comment.