Skip to content

Commit 3639aa1

Browse files
committed
feat: handle claimedAt blocks
1 parent e255646 commit 3639aa1

File tree

6 files changed

+60
-80
lines changed

6 files changed

+60
-80
lines changed

abis/AavegotchiDiamond.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12460,5 +12460,24 @@
1246012460
],
1246112461
"name": "ResyncAavegotchis",
1246212462
"type": "event"
12463+
},
12464+
{
12465+
"anonymous": false,
12466+
"inputs": [
12467+
{
12468+
"indexed": false,
12469+
"internalType": "uint256",
12470+
"name": "_tokenId",
12471+
"type": "uint256"
12472+
},
12473+
{
12474+
"indexed": false,
12475+
"internalType": "uint256",
12476+
"name": "_claimedAt",
12477+
"type": "uint256"
12478+
}
12479+
],
12480+
"name": "ClaimedAt",
12481+
"type": "event"
1246312482
}
1246412483
]

schema.graphql

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ type Aavegotchi @entity {
8282

8383
listings: [ERC721Listing!]! @derivedFrom(field: "gotchi")
8484

85-
"Block in which the Aavegotchi entity was created"
85+
"Block in which the Aavegotchi entity was created on Base"
8686
createdAt: BigInt
8787

88-
"Block in which the Aavegotchi was claimed. Should coincide with createdAt"
88+
"Block in which the Aavegotchi was created on Polygon"
89+
createdAtPolygon: BigInt
90+
91+
"Block in which the Aavegotchi was claimed on Base. Should coincide with createdAt"
8992
claimedAt: BigInt
93+
94+
"Block in which the Aavegotchi was claimed on Polygon (if migrated). Should coincide with createdAtPolygon"
95+
claimedAtPolygon: BigInt
96+
9097
claimedTime: BigInt
9198

9299
timesTraded: BigInt!
@@ -138,6 +145,9 @@ type Portal @entity {
138145
openedAt: BigInt
139146

140147
claimedAt: BigInt
148+
149+
claimedAtPolygon: BigInt
150+
141151
claimedTime: BigInt
142152

143153
timesTraded: BigInt!

src/helper/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { BigInt } from "@graphprotocol/graph-ts";
2+
3+
// Block at which the migration from Polygon to Base started
4+
export const MIGRATION_BLOCK = BigInt.fromI32(26636383);

src/mappings/baseDiamond.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
AavegotchiHistory,
7575
PortalData,
7676
ResyncAavegotchis,
77+
ClaimedAt,
7778
} from "../../generated/AavegotchiDiamond/AavegotchiDiamond";
7879
import {
7980
getOrCreateUser,
@@ -127,6 +128,7 @@ import {
127128
RealmDiamond,
128129
ResyncParcel,
129130
} from "../../generated/AavegotchiDiamond/RealmDiamond";
131+
import { MIGRATION_BLOCK } from "../helper";
130132

131133
export function handleBuyPortals(event: BuyPortals): void {
132134
let contract = AavegotchiDiamond.bind(event.address);
@@ -2004,8 +2006,8 @@ export function handleAavegotchiHistory(event: AavegotchiHistory): void {
20042006

20052007
// Update basic info
20062008
gotchi.name = data.name;
2007-
gotchi.createdAt = data.createdAtBlock;
20082009
gotchi.timesTraded = data.timesTraded;
2010+
20092011
if (data.activeListing != BIGINT_ZERO) {
20102012
gotchi.activeListing = data.activeListing;
20112013
}
@@ -2036,7 +2038,6 @@ export function handlePortalData(event: PortalData): void {
20362038
// Update timestamps
20372039
portal.boughtAt = data.boughtAtBlock;
20382040
portal.openedAt = data.openedAtBlock;
2039-
portal.claimedAt = data.claimedAtBlock;
20402041
portal.claimedTime = data.claimedTimestamp;
20412042

20422043
// Update trading info
@@ -2072,3 +2073,23 @@ export function handleResyncAavegotchis(event: ResyncAavegotchis): void {
20722073
gotchi = updateAavegotchiInfo(gotchi, event.params._tokenId, event, false);
20732074
gotchi.save();
20742075
}
2076+
2077+
export function handleClaimedAt(event: ClaimedAt): void {
2078+
if (event.params._claimedAt !== BIGINT_ZERO) {
2079+
let gotchi = getOrCreateAavegotchi(event.params._tokenId.toString(), event);
2080+
if (!gotchi) return;
2081+
gotchi.claimedAtPolygon = event.params._claimedAt;
2082+
gotchi.createdAtPolygon = event.params._claimedAt;
2083+
2084+
gotchi.createdAt = MIGRATION_BLOCK;
2085+
gotchi.claimedAt = MIGRATION_BLOCK;
2086+
2087+
gotchi.save();
2088+
2089+
let portal = getOrCreatePortal(gotchi.id);
2090+
portal.claimedAtPolygon = event.params._claimedAt;
2091+
portal.claimedAt = MIGRATION_BLOCK;
2092+
2093+
portal.save();
2094+
}
2095+
}

src/mappings/diamond.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,79 +1998,3 @@ export function handleERC1155BuyOrderCancel(
19981998
entity.canceled = true;
19991999
entity.save();
20002000
}
2001-
2002-
export function handleAavegotchiHistory(event: AavegotchiHistory): void {
2003-
const data = event.params.data;
2004-
let gotchi = getOrCreateAavegotchi(data.gotchiId.toString(), event);
2005-
if (!gotchi) return;
2006-
2007-
// Update basic info
2008-
gotchi.name = data.name;
2009-
gotchi.createdAt = data.createdAtBlock;
2010-
gotchi.timesTraded = data.timesTraded;
2011-
if (data.activeListing != BIGINT_ZERO) {
2012-
gotchi.activeListing = data.activeListing;
2013-
}
2014-
2015-
// Update historical prices array
2016-
let historicalPrices = data.historicalPrices;
2017-
if (historicalPrices.length > 0) {
2018-
gotchi.historicalPrices = historicalPrices;
2019-
}
2020-
2021-
gotchi.save();
2022-
}
2023-
2024-
export function handlePortalData(event: PortalData): void {
2025-
const data = event.params.data;
2026-
let portal = getOrCreatePortal(data.gotchiId.toString());
2027-
2028-
let owner = getOrCreateUser(data.owner.toHexString());
2029-
owner.save();
2030-
portal.owner = owner.id;
2031-
2032-
// Update basic portal info
2033-
portal.gotchiId = data.gotchiId;
2034-
portal.buyer = data.buyer.toHexString();
2035-
portal.hauntId = data.hauntId;
2036-
portal.status = data.status;
2037-
2038-
// Update timestamps
2039-
portal.boughtAt = data.boughtAtBlock;
2040-
portal.openedAt = data.openedAtBlock;
2041-
portal.claimedAt = data.claimedAtBlock;
2042-
portal.claimedTime = data.claimedTimestamp;
2043-
2044-
// Update trading info
2045-
portal.timesTraded = data.timesTraded;
2046-
portal.historicalPrices = data.historicalPrices;
2047-
if (data.activeListingId != BIGINT_ZERO) {
2048-
portal.activeListing = data.activeListingId;
2049-
}
2050-
2051-
// Handle portal options
2052-
let options = data.options;
2053-
2054-
for (let i = 0; i < options.length; i++) {
2055-
let option = getOrCreateAavegotchiOption(portal.id, i);
2056-
option.portal = portal.id;
2057-
option.owner = portal.owner;
2058-
option.portalOptionId = options[i].portalOptionId;
2059-
option.randomNumber = options[i].randomNumber;
2060-
option.numericTraits = options[i].numericTraits;
2061-
option.collateralType = options[i].collateralType;
2062-
option.minimumStake = options[i].minimumStake;
2063-
option.baseRarityScore = options[i].baseRarityScore;
2064-
2065-
option.save();
2066-
}
2067-
2068-
portal.save();
2069-
}
2070-
2071-
export function handleResyncAavegotchis(event: ResyncAavegotchis): void {
2072-
let gotchi = getOrCreateAavegotchi(event.params._tokenId.toString(), event);
2073-
if (!gotchi) return;
2074-
gotchi = updateAavegotchiInfo(gotchi, event.params._tokenId, event, false);
2075-
gotchi.save();
2076-
}

subgraph.sepolia.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ dataSources:
180180
handler: handlePortalData
181181
- event: ResyncAavegotchis(uint256)
182182
handler: handleResyncAavegotchis
183+
- event: ClaimedAt(uint256,uint256)
184+
handler: handleClaimedAt
183185

184186
- kind: ethereum/contract
185187
name: RealmDiamond

0 commit comments

Comments
 (0)