Skip to content

Commit

Permalink
Merge pull request #87 from aavegotchi/feat/addMumbaiSubgraph
Browse files Browse the repository at this point in the history
feat: add mumbai subgraph
  • Loading branch information
cinnabarhorse authored May 4, 2023
2 parents ec029e0 + ad5096c commit 49e167f
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-satsuma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ jobs:
- name: Deploy to Satsuma
run: |
npx graph deploy --access-token ${{secrets.SATSUMA_ACCESS_TOKEN}} aavegotchi-core-matic subgraph.yaml --node https://app.satsuma.xyz/api/subgraphs/deploy --version-label ${GITHUB_REF#refs/*/}
npx graph deploy --access-token ${{secrets.SATSUMA_ACCESS_TOKEN}} aavegotchi-core-mumbai subgraph.mumbai.yaml --node https://app.satsuma.xyz/api/subgraphs/deploy --version-label ${GITHUB_REF#refs/*/}
shell: bash
46 changes: 24 additions & 22 deletions .github/workflows/graph.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
name: Deploy Graph

on:
push:
branches: main
push:
tags:
- "*"

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install Yarn
run: npm i -g yarn
- name: Install Libs
run: yarn --frozen-lockfile
- name: Codegen
run: yarn codegen
- name: Build
run: yarn build
- name: Deploy to TheGraph Hosted Service
run: |
npx graph deploy --access-token ${{secrets.GRAPH_ACCESS_TOKEN}} aavegotchi/aavegotchi-core-matic subgraph.yaml --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/
shell: bash
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install node
uses: actions/setup-node@v1
with:
node-version: 14
- name: Install Yarn
run: npm i -g yarn
- name: Install Libs
run: yarn --frozen-lockfile
- name: Codegen
run: yarn codegen
- name: Build
run: yarn build
- name: Deploy to TheGraph Hosted Service
run: |
npx graph deploy --access-token ${{secrets.GRAPH_ACCESS_TOKEN}} aavegotchi/aavegotchi-core-matic subgraph.yaml --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/
npx graph deploy --access-token ${{secrets.GRAPH_ACCESS_TOKEN}} aavegotchi/aavegotchi-core-mumbai subgraph.mumbai.yaml --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/
shell: bash
22 changes: 11 additions & 11 deletions src/mappings/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,17 +1007,17 @@ export function handleMintParcel(event: MintParcel): void {

// Whitelist
export function handleWhitelistCreated(event: WhitelistCreated): void {
createOrUpdateWhitelist(event.params.whitelistId);
createOrUpdateWhitelist(event.params.whitelistId, event);
}

export function handleWhitelistUpdated(event: WhitelistUpdated): void {
createOrUpdateWhitelist(event.params.whitelistId);
createOrUpdateWhitelist(event.params.whitelistId, event);
}

export function handleWhitelistOwnershipTransferred(
event: WhitelistOwnershipTransferred
): void {
createOrUpdateWhitelist(event.params.whitelistId);
createOrUpdateWhitelist(event.params.whitelistId, event);
}

export function handleGotchiLendingAdd(event: GotchiLendingAdd): void {
Expand Down Expand Up @@ -1174,7 +1174,7 @@ export function handleGotchiLendingAdded(event: GotchiLendingAdded): void {
lending.cancelled = false;
lending.completed = false;
if (event.params.whitelistId != BIGINT_ZERO) {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ export function handleGotchiLendingClaimed(event: GotchiLendingClaimed): void {
lending.cancelled = false;
lending.completed = false;
if (event.params.whitelistId != BIGINT_ZERO) {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand All @@ -1241,7 +1241,7 @@ export function handleGotchiLendingCanceled(
lending.cancelled = true;
lending.completed = false;
if (event.params.whitelistId != BIGINT_ZERO) {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand Down Expand Up @@ -1270,7 +1270,7 @@ export function handleGotchiLendingExecuted(
lending.completed = false;
lending.borrower = event.params.borrower;
if (event.params.whitelistId != BIGINT_ZERO) {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand Down Expand Up @@ -1322,7 +1322,7 @@ export function handleGotchiLendingEnded(event: GotchiLendingEnded): void {
lending.completed = true;
lending.timeEnded = event.block.timestamp;
if (event.params.whitelistId != BIGINT_ZERO) {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand Down Expand Up @@ -1381,7 +1381,7 @@ export function handleGotchiLendingEnded(event: GotchiLendingEnded): void {
export function handleWhitelistAccessRightSet(
event: WhitelistAccessRightSet
): void {
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (whitelist == null) {
return;
}
Expand Down Expand Up @@ -1418,7 +1418,7 @@ export function handleERC721ListingWhitelistSet(
event: ERC721ListingWhitelistSet
): void {
let listing = getOrCreateERC721Listing(event.params.listingId.toString());
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (!listing || !whitelist) return;
listing.whitelist = whitelist.id;
listing.save();
Expand All @@ -1438,7 +1438,7 @@ export function handleERC1155ListingWhitelistSet(
event: ERC1155ListingWhitelistSet
): void {
let listing = getOrCreateERC1155Listing(event.params.listingId.toString());
let whitelist = getOrCreateWhitelist(event.params.whitelistId);
let whitelist = getOrCreateWhitelist(event.params.whitelistId, event);
if (!listing || !whitelist) return;
listing.whitelist = whitelist.id;
listing.save();
Expand Down
3 changes: 1 addition & 2 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { BigDecimal, BigInt, Address } from "@graphprotocol/graph-ts";
import { BigDecimal, BigInt } from "@graphprotocol/graph-ts";
import { toDecimal } from "./decimals";

export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
export const CORE_DIAMOND = "0x86935F11C86623deC8a25696E1C19a8659CbF95d";

export const PORTAL_STATUS_BOUGHT = "Bought";
export const PORTAL_STATUS_OPENED = "Opened";
Expand Down
24 changes: 15 additions & 9 deletions src/utils/helpers/diamond.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
AavegotchiDiamond,
ERC1155ExecutedListing,
ERC721ExecutedListing,
ERC721ListingAdd,
ERC721ListingCancelled,
} from "../../../generated/AavegotchiDiamond/AavegotchiDiamond";

import { RealmDiamond } from "../../../generated/RealmDiamond/RealmDiamond";
Expand All @@ -24,7 +21,7 @@ import {
Whitelist,
ClaimedToken,
} from "../../../generated/schema";
import { BIGINT_ZERO, CORE_DIAMOND, STATUS_AAVEGOTCHI } from "../constants";
import { BIGINT_ZERO, STATUS_AAVEGOTCHI } from "../constants";
import { Address, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts";

export function getOrCreatePortal(
Expand Down Expand Up @@ -729,8 +726,11 @@ export function calculateBaseRarityScore(numericTraits: Array<i32>): i32 {

// whitelist

export function createOrUpdateWhitelist(id: BigInt): Whitelist | null {
let contract = AavegotchiDiamond.bind(Address.fromString(CORE_DIAMOND));
export function createOrUpdateWhitelist(
id: BigInt,
event: ethereum.Event
): Whitelist | null {
let contract = AavegotchiDiamond.bind(event.address);
let response = contract.try_getWhitelist(id);

if (response.reverted) {
Expand Down Expand Up @@ -826,7 +826,10 @@ export function updateGotchiLending(
lending.originalOwner = listingResult.originalOwner;

if (listingResult.whitelistId != BIGINT_ZERO) {
let whitelist = createOrUpdateWhitelist(listingResult.whitelistId);
let whitelist = createOrUpdateWhitelist(
listingResult.whitelistId,
event
);
if (whitelist !== null) {
lending.whitelist = whitelist.id;
lending.whitelistMembers = whitelist.members;
Expand Down Expand Up @@ -864,11 +867,14 @@ export function getOrCreateClaimedToken(
return ctoken;
}

export function getOrCreateWhitelist(whitelistId: BigInt): Whitelist | null {
export function getOrCreateWhitelist(
whitelistId: BigInt,
event: ethereum.Event
): Whitelist | null {
let id = whitelistId.toString();
let whitelist = Whitelist.load(id);
if (!whitelist) {
whitelist = createOrUpdateWhitelist(whitelistId);
whitelist = createOrUpdateWhitelist(whitelistId, event);
}

return whitelist;
Expand Down
Loading

0 comments on commit 49e167f

Please sign in to comment.