diff --git a/src/constants.ts b/src/constants.ts index eb4471e..12b4e70 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,3 +2,8 @@ import { BigInt } from "@graphprotocol/graph-ts"; // matic export let BLOCK_SIDEVIEWS_ACTIVATED = BigInt.fromI32(39130900); + +export const AAVEGOTCHI_DIAMOND = "0x6Acc828BbbC6874de40Ca20bfeA7Cd2a2DA8DA8c"; + +export const AAVEGOTCHI_BRIDGE_VAULT = + "0xF1D1d61EEDDa7a10b494aF7af87D932AC910f3C5"; diff --git a/src/mapping.ts b/src/mapping.ts index c560a0e..2a99b72 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -1,117 +1,133 @@ -import { BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { - ClaimAavegotchi, - EquipWearables, + ClaimAavegotchi, + EquipWearables, + Transfer, } from "../generated/Contract/Contract"; -import { BLOCK_SIDEVIEWS_ACTIVATED } from "./constants"; +import { + AAVEGOTCHI_BRIDGE_VAULT, + BLOCK_SIDEVIEWS_ACTIVATED, +} from "./constants"; import { updateSideViews, updateSvg } from "./helper"; export function handleClaimAavegotchi(event: ClaimAavegotchi): void { - let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) - ? updateSideViews(event.params._tokenId) - : updateSvg(event.params._tokenId); - if (gotchi != null) { - gotchi.save(); - } + let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) + ? updateSideViews(event.params._tokenId) + : updateSvg(event.params._tokenId); + if (gotchi != null) { + gotchi.save(); + } } export function handleEquipWearables(event: EquipWearables): void { - let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) - ? updateSideViews(event.params._tokenId) - : updateSvg(event.params._tokenId); - if (gotchi != null) { + let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) + ? updateSideViews(event.params._tokenId) + : updateSvg(event.params._tokenId); + if (gotchi != null) { + gotchi.save(); + } +} + +export function handleBlock(block: ethereum.Block): void { + if (block.number == BLOCK_SIDEVIEWS_ACTIVATED) { + for (let i = 0; i <= 2500; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(1)) + ) { + for (let i = 2500; i <= 5000; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(2)) + ) { + for (let i = 5000; i <= 7500; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(3)) + ) { + for (let i = 7500; i <= 10000; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { gotchi.save(); + } } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(4)) + ) { + for (let i = 10000; i <= 12500; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(5)) + ) { + for (let i = 12500; i <= 15000; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(6)) + ) { + for (let i = 15000; i <= 17500; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(7)) + ) { + for (let i = 17500; i <= 20000; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(8)) + ) { + for (let i = 20000; i <= 22500; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } else if ( + block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(9)) + ) { + for (let i = 22500; i <= 25000; i++) { + let gotchi = updateSideViews(BigInt.fromI32(i)); + if (gotchi != null) { + gotchi.save(); + } + } + } } -export function handleBlock(block: ethereum.Block): void { - if (block.number == BLOCK_SIDEVIEWS_ACTIVATED) { - for (let i = 0; i <= 2500; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(1)) - ) { - for (let i = 2500; i <= 5000; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(2)) - ) { - for (let i = 5000; i <= 7500; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(3)) - ) { - for (let i = 7500; i <= 10000; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(4)) - ) { - for (let i = 10000; i <= 12500; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(5)) - ) { - for (let i = 12500; i <= 15000; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(6)) - ) { - for (let i = 15000; i <= 17500; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(7)) - ) { - for (let i = 17500; i <= 20000; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(8)) - ) { - for (let i = 20000; i <= 22500; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } - } else if ( - block.number == BLOCK_SIDEVIEWS_ACTIVATED.plus(BigInt.fromI32(9)) - ) { - for (let i = 22500; i <= 25000; i++) { - let gotchi = updateSideViews(BigInt.fromI32(i)); - if (gotchi != null) { - gotchi.save(); - } - } +export function handleTransfer(event: Transfer): void { + if (event.params._from == Address.fromString(AAVEGOTCHI_BRIDGE_VAULT)) { + // - if from is bridge vault, update svg because the equipped wearables may have changed + let gotchi = event.block.number.ge(BLOCK_SIDEVIEWS_ACTIVATED) + ? updateSideViews(event.params._tokenId) + : updateSvg(event.params._tokenId); + if (gotchi != null) { + gotchi.save(); } + } } diff --git a/subgraph.yaml b/subgraph.yaml index 623f1bd..3b97327 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -1,29 +1,36 @@ +features: + - grafting +graft: + base: QmeWcqPd2QvWiLsNWRZsiYxwqqBRszTHfsSTXusWf2Z8bA # Subgraph ID of base subgraph + block: 64874170 # Block number specVersion: 0.0.4 schema: - file: ./schema.graphql + file: ./schema.graphql dataSources: - - kind: ethereum/contract - name: Contract - network: matic - source: - address: "0x86935F11C86623deC8a25696E1C19a8659CbF95d" - abi: Contract - startBlock: 39130899 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - ClaimAavegotchi - - EquipWearables - abis: - - name: Contract - file: ./abis/Contract.json - eventHandlers: - - event: EquipWearables(indexed uint256,uint16[16],uint16[16]) - handler: handleEquipWearables - - event: ClaimAavegotchi(indexed uint256) - handler: handleClaimAavegotchi - blockHandlers: - - handler: handleBlock - file: ./src/mapping.ts + - kind: ethereum/contract + name: Contract + network: matic + source: + address: "0x86935F11C86623deC8a25696E1C19a8659CbF95d" + abi: Contract + startBlock: 39130899 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - ClaimAavegotchi + - EquipWearables + abis: + - name: Contract + file: ./abis/Contract.json + eventHandlers: + - event: EquipWearables(indexed uint256,uint16[16],uint16[16]) + handler: handleEquipWearables + - event: ClaimAavegotchi(indexed uint256) + handler: handleClaimAavegotchi + - event: Transfer(indexed address,indexed address,indexed uint256) + handler: handleTransfer + blockHandlers: + - handler: handleBlock + file: ./src/mapping.ts