Skip to content

Commit aa45a68

Browse files
committed
feat: handle gotchi and portal metadata migration
1 parent 54ae33b commit aa45a68

File tree

4 files changed

+228
-0
lines changed

4 files changed

+228
-0
lines changed

abis/AavegotchiDiamond.json

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12290,5 +12290,162 @@
1229012290
],
1229112291
"stateMutability": "view",
1229212292
"type": "function"
12293+
},
12294+
{
12295+
"anonymous": false,
12296+
"inputs": [
12297+
{
12298+
"components": [
12299+
{
12300+
"internalType": "uint256",
12301+
"name": "gotchiId",
12302+
"type": "uint256"
12303+
},
12304+
{
12305+
"internalType": "string",
12306+
"name": "name",
12307+
"type": "string"
12308+
},
12309+
{
12310+
"internalType": "uint256",
12311+
"name": "createdAtBlock",
12312+
"type": "uint256"
12313+
},
12314+
{
12315+
"internalType": "uint256[]",
12316+
"name": "historicalPrices",
12317+
"type": "uint256[]"
12318+
},
12319+
{
12320+
"internalType": "uint256",
12321+
"name": "timesTraded",
12322+
"type": "uint256"
12323+
},
12324+
{
12325+
"internalType": "uint256",
12326+
"name": "activeListing",
12327+
"type": "uint256"
12328+
}
12329+
],
12330+
"indexed": false,
12331+
"internalType": "struct AavegotchiBridgeFacet.AavegotchiHistoricalRecord",
12332+
"name": "data",
12333+
"type": "tuple"
12334+
}
12335+
],
12336+
"name": "AavegotchiHistory",
12337+
"type": "event"
12338+
},
12339+
{
12340+
"anonymous": false,
12341+
"inputs": [
12342+
{
12343+
"components": [
12344+
{
12345+
"internalType": "uint256",
12346+
"name": "gotchiId",
12347+
"type": "uint256"
12348+
},
12349+
{
12350+
"internalType": "address",
12351+
"name": "buyer",
12352+
"type": "address"
12353+
},
12354+
{
12355+
"internalType": "uint256",
12356+
"name": "hauntId",
12357+
"type": "uint256"
12358+
},
12359+
{
12360+
"internalType": "address",
12361+
"name": "owner",
12362+
"type": "address"
12363+
},
12364+
{
12365+
"components": [
12366+
{
12367+
"internalType": "uint8",
12368+
"name": "portalOptionId",
12369+
"type": "uint8"
12370+
},
12371+
{
12372+
"internalType": "uint256",
12373+
"name": "randomNumber",
12374+
"type": "uint256"
12375+
},
12376+
{
12377+
"internalType": "int16[6]",
12378+
"name": "numericTraits",
12379+
"type": "int16[6]"
12380+
},
12381+
{
12382+
"internalType": "address",
12383+
"name": "collateralType",
12384+
"type": "address"
12385+
},
12386+
{
12387+
"internalType": "uint256",
12388+
"name": "minimumStake",
12389+
"type": "uint256"
12390+
},
12391+
{
12392+
"internalType": "uint16",
12393+
"name": "baseRarityScore",
12394+
"type": "uint16"
12395+
}
12396+
],
12397+
"internalType": "struct AavegotchiBridgeFacet.PortalOption[]",
12398+
"name": "options",
12399+
"type": "tuple[]"
12400+
},
12401+
{
12402+
"internalType": "string",
12403+
"name": "status",
12404+
"type": "string"
12405+
},
12406+
{
12407+
"internalType": "uint256",
12408+
"name": "boughtAtBlock",
12409+
"type": "uint256"
12410+
},
12411+
{
12412+
"internalType": "uint256",
12413+
"name": "openedAtBlock",
12414+
"type": "uint256"
12415+
},
12416+
{
12417+
"internalType": "uint256",
12418+
"name": "claimedAtBlock",
12419+
"type": "uint256"
12420+
},
12421+
{
12422+
"internalType": "uint256",
12423+
"name": "claimedTimestamp",
12424+
"type": "uint256"
12425+
},
12426+
{
12427+
"internalType": "uint256",
12428+
"name": "timesTraded",
12429+
"type": "uint256"
12430+
},
12431+
{
12432+
"internalType": "uint256[]",
12433+
"name": "historicalPrices",
12434+
"type": "uint256[]"
12435+
},
12436+
{
12437+
"internalType": "uint256",
12438+
"name": "activeListingId",
12439+
"type": "uint256"
12440+
}
12441+
],
12442+
"indexed": false,
12443+
"internalType": "struct AavegotchiBridgeFacet.AavegotchiSubgraphPortalData",
12444+
"name": "data",
12445+
"type": "tuple"
12446+
}
12447+
],
12448+
"name": "PortalData",
12449+
"type": "event"
1229312450
}
1229412451
]

src/mappings/diamond.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ import {
7171
ERC1155BuyOrderAdd,
7272
ERC1155BuyOrderExecute,
7373
ERC1155BuyOrderCancel,
74+
AavegotchiHistory,
75+
PortalData,
7476
} from "../../generated/AavegotchiDiamond/AavegotchiDiamond";
7577
import {
7678
getOrCreateUser,
@@ -1993,3 +1995,62 @@ export function handleERC1155BuyOrderCancel(
19931995
entity.canceled = true;
19941996
entity.save();
19951997
}
1998+
1999+
export function handleAavegotchiHistory(event: AavegotchiHistory): void {
2000+
const data = event.params.data;
2001+
let gotchi = getOrCreateAavegotchi(data.gotchiId.toString(), event);
2002+
if (!gotchi) return;
2003+
2004+
// Update basic info
2005+
gotchi.name = data.name;
2006+
gotchi.createdAt = data.createdAtBlock;
2007+
gotchi.timesTraded = data.timesTraded;
2008+
gotchi.activeListing = data.activeListing;
2009+
2010+
// Update historical prices array
2011+
let historicalPrices = data.historicalPrices;
2012+
if (historicalPrices.length > 0) {
2013+
gotchi.historicalPrices = historicalPrices;
2014+
}
2015+
2016+
gotchi.save();
2017+
}
2018+
2019+
export function handlePortalData(event: PortalData): void {
2020+
const data = event.params.data;
2021+
let portal = getOrCreatePortal(data.gotchiId.toString());
2022+
2023+
// Update basic portal info
2024+
portal.gotchiId = data.gotchiId;
2025+
portal.buyer = data.buyer.toHexString();
2026+
portal.hauntId = data.hauntId;
2027+
portal.owner = data.owner.toHexString();
2028+
portal.status = data.status;
2029+
2030+
// Update timestamps
2031+
portal.boughtAt = data.boughtAtBlock;
2032+
portal.openedAt = data.openedAtBlock;
2033+
portal.claimedAt = data.claimedAtBlock;
2034+
portal.claimedTime = data.claimedTimestamp;
2035+
2036+
// Update trading info
2037+
portal.timesTraded = data.timesTraded;
2038+
portal.historicalPrices = data.historicalPrices;
2039+
portal.activeListing = data.activeListingId;
2040+
2041+
// Handle portal options
2042+
let options = data.options;
2043+
for (let i = 0; i < options.length; i++) {
2044+
let option = getOrCreateAavegotchiOption(portal.id, i);
2045+
option.portal = portal.id;
2046+
option.owner = portal.owner;
2047+
option.randomNumber = options[i].randomNumber;
2048+
option.numericTraits = options[i].numericTraits;
2049+
option.collateralType = options[i].collateralType;
2050+
option.minimumStake = options[i].minimumStake;
2051+
option.baseRarityScore = calculateBaseRarityScore(option.numericTraits);
2052+
option.save();
2053+
}
2054+
2055+
portal.save();
2056+
}

subgraph.sepolia.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ dataSources:
173173
handler: handleWearablesConfigCreated
174174
- event: WearablesConfigUpdated(indexed address,indexed uint256,indexed uint16,uint16[16])
175175
handler: handleWearablesConfigUpdated
176+
177+
- event: AavegotchiHistory((uint256,string,uint256,uint256[],uint256,uint256))
178+
handler: handleAavegotchiHistory
179+
- event: PortalData((uint256,address,uint256,address,(uint8,uint256,int16[6],address,uint256,uint16)[],string,uint256,uint256,uint256,uint256,uint256,uint256[],uint256))
180+
handler: handlePortalData
176181

177182
- kind: ethereum/contract
178183
name: RealmDiamond

subgraph.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ dataSources:
173173
handler: handleWearablesConfigCreated
174174
- event: WearablesConfigUpdated(indexed address,indexed uint256,indexed uint16,uint16[16])
175175
handler: handleWearablesConfigUpdated
176+
177+
- event: AavegotchiHistory((uint256,string,uint256,uint256[],uint256,uint256))
178+
handler: handleAavegotchiHistory
179+
- event: PortalData((uint256,address,uint256,address,(uint8,uint256,int16[6],address,uint256,uint16)[],string,uint256,uint256,uint256,uint256,uint256,uint256[],uint256))
180+
handler: handlePortalData
176181

177182
- kind: ethereum/contract
178183
name: RealmDiamond

0 commit comments

Comments
 (0)