Skip to content

Commit

Permalink
Merge pull request #21 from WeAreNewt/feat/subgraph-update-upgradeabl…
Browse files Browse the repository at this point in the history
…ility

feat/subgraph update upgradeablility
  • Loading branch information
defispartan authored Jan 16, 2022
2 parents b692019 + 39d8a02 commit b3f6555
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
25 changes: 15 additions & 10 deletions packages/subgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
## Development

```bash
# copy env and add the access token from TheGraph dashboard
cp .env.test .env

# Generate subgraph.yaml manifest based on contract addresses from config directory
# Step 1: Compile abis from contracts package
cd ../contracts
npm install
npx hardhat compile

# Step 2: In subgraph directory, install dependencies
npm install

# Step 3: Generate subgraph.yaml manifest annd subgraph types based on contract addresses from config directory, generated contract abis, and user defined schema (schema.graphql)
npm run prepare:mumbai
npm run prepare:polygon

# Run a test build
# Step 4: Run a test build of your subgraph mappings
npm run build

# To re-generate contract abis
cd ../contracts
npx hardhat compile

# TheGraph currently breaks when trying to deploy a contract using custom error :/
# To deploy you have to manually remove all abi elements with "type": "error" in ../contracts/artifacts/contracts/TimeCollection.sol/TimeCollection.json
# To deploy you have to manually remove all abi elements with "type": "error" in ../contracts/artifacts/contracts/NonFungibleTimeCollection.sol/NonFungibleTimeCollection.json

# Step 5: copy .env.test to .env and add your subgraph access token from TheGraph dashboard
cp .env.test .env

# Deploy to production, subgraph deployment slug set in package.json (wearenewt/tokenized-time-mumbai)
# Step 6: Deploy to production, subgraph deployment slug set in package.json (wearenewt/tokenized-time-mumbai)
npm run deploy:hosted:mumbai
npm run deploy:hosted:polygon
```
12 changes: 11 additions & 1 deletion packages/subgraph/src/mapping/tokenizedtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Address, log } from '@graphprotocol/graph-ts';
import { ERC721 } from '../../generated/TimeCollection/ERC721';
import { ERC20 } from '../../generated/TimeCollection/ERC20';

export function getTokenURI(event: Transfer): string {
export function getTokenURI(event: Transfer | TokenRedeemed): string {
const erc721 = ERC721.bind(event.address);
const tokenURICallResult = erc721.try_tokenURI(event.params.tokenId);

Expand Down Expand Up @@ -109,6 +109,16 @@ export function handleTokenRedeemed(event: TokenRedeemed): void {
const from = event.transaction.from ? event.transaction.from.toHexString() : '';
redeemed.redeemedBy = from;
redeemed.creator = nftParams.value5.toHexString();
const nft = Nft.load(event.params.tokenId.toString());
if (nft) {
const uri = getTokenURI(event);
nft.tokenURI = uri;
nft.save();
} else {
log.warning('Token redeem for nft unregistered to subgraph {}', [
event.params.tokenId.toString(),
]);
}
redeemed.save();
} else {
log.warning(`Token redeem event for non-existant tokenId {}`, [
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ dataSources:
- PaymentToken
abis:
- name: TimeCollection
file: ../contracts/artifacts/contracts/TimeCollection.sol/TimeCollection.json
file: ../contracts/artifacts/contracts/NonFungibleTimeCollection.sol/NonFungibleTimeCollection.json
- name: ERC721
file: ../contracts/artifacts/@openzeppelin/contracts/token/ERC721/ERC721.sol/ERC721.json
file: ../contracts/artifacts/@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol/ERC721Upgradeable.json
- name: ERC20
file: ../contracts/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json
eventHandlers:
Expand Down

0 comments on commit b3f6555

Please sign in to comment.