Skip to content

Commit

Permalink
chore: add svg handler for bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarhorse committed Nov 29, 2024
1 parent 399de21 commit 1064b3d
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 129 deletions.
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
222 changes: 119 additions & 103 deletions src/mapping.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
59 changes: 33 additions & 26 deletions subgraph.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1064b3d

Please sign in to comment.