Skip to content

Commit

Permalink
chore: fix parcels
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarhorse committed Dec 3, 2024
1 parent 5aef3d8 commit 0470e34
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 143 deletions.
133 changes: 69 additions & 64 deletions src/mappings/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import {
getOrCreateWearableSet,
getOrCreateERC1155Purchase,
updateERC1155PurchaseInfo,
// getOrCreateParcel,
getOrCreateParcel,
updateAavegotchiWearables,
calculateBaseRarityScore,
getOrCreateGotchiLending,
Expand All @@ -108,7 +108,7 @@ import {
} from "../utils/constants";
import { Address, BigInt, log, Bytes } from "@graphprotocol/graph-ts";

import { /*Parcel,*/ TokenCommitment } from "../../generated/schema";
import { /*Parcel,*/ Parcel, TokenCommitment } from "../../generated/schema";
// import {
// RealmDiamond,
// MintParcel,
Expand All @@ -118,6 +118,12 @@ import { /*Parcel,*/ TokenCommitment } from "../../generated/schema";
import { updatePermissionsFromBitmap } from "../utils/decimals";
import * as erc7589 from "./erc-7589";
import { generateTokenCommitmentId } from "../utils/helpers/erc-7589";
import {
KinshipBurned,
MintParcel,
RealmDiamond,
ResyncParcel,
} from "../../generated/AavegotchiDiamond/RealmDiamond";

export function handleBuyPortals(event: BuyPortals): void {
let contract = AavegotchiDiamond.bind(event.address);
Expand Down Expand Up @@ -748,14 +754,14 @@ export function handleERC721ListingRemoved(event: ERC721ListingRemoved): void {
gotchi.locked = false;
gotchi.save();
} else if (listing.category.equals(BigInt.fromI32(4))) {
// let parcel = getOrCreateParcel(
// listing.tokenId,
// listing.seller,
// Address.fromString(listing.erc721TokenAddress.toHexString()),
// false
// );
// parcel.activeListing = null;
// parcel.save();
let parcel = getOrCreateParcel(
listing.tokenId,
listing.seller,
Address.fromString(listing.erc721TokenAddress.toHexString()),
false
);
parcel.activeListing = null;
parcel.save();
}

listing.cancelled = true;
Expand Down Expand Up @@ -1033,54 +1039,53 @@ export function handleDiamondCut(event: DiamondCut): void {
*/
// export { runTests } from "../tests/aavegotchi.test";

// Realm
// export function handleResyncParcel(event: ResyncParcel): void {
// let parcel = Parcel.load(event.params._tokenId.toString())!;

// let contract = RealmDiamond.bind(event.address);
// let parcelInfo = contract.try_getParcelInfo(event.params._tokenId);

// if (!parcelInfo.reverted) {
// let parcelMetadata = parcelInfo.value;
// parcel.parcelId = parcelMetadata.parcelId;
// parcel.tokenId = event.params._tokenId;
// parcel.coordinateX = parcelMetadata.coordinateX;
// parcel.coordinateY = parcelMetadata.coordinateY;
// parcel.district = parcelMetadata.district;
// parcel.parcelHash = parcelMetadata.parcelAddress;

// parcel.size = parcelMetadata.size;

// let boostArray = parcelMetadata.boost;
// parcel.fudBoost = boostArray[0];
// parcel.fomoBoost = boostArray[1];
// parcel.alphaBoost = boostArray[2];
// parcel.kekBoost = boostArray[3];
// }

// //update auction too

// // Entities can be written to the store with `.save()`
// parcel.save();
// }

// export function handleTransferParcel(event: Transfer): void {
// let user = getOrCreateUser(event.params._to.toHexString());
// user.save();

// let parcel = Parcel.load(event.params._tokenId.toString())!;
// parcel.owner = user.id;
// parcel.save();
// }

// export function handleMintParcel(event: MintParcel): void {
// let parcel = getOrCreateParcel(
// event.params._tokenId,
// event.params._owner,
// event.address
// );
// parcel.save();
// }
export function handleResyncParcel(event: ResyncParcel): void {
let parcel = Parcel.load(event.params._tokenId.toString())!;

let contract = RealmDiamond.bind(event.address);
let parcelInfo = contract.try_getParcelInfo(event.params._tokenId);

if (!parcelInfo.reverted) {
let parcelMetadata = parcelInfo.value;
parcel.parcelId = parcelMetadata.parcelId;
parcel.tokenId = event.params._tokenId;
parcel.coordinateX = parcelMetadata.coordinateX;
parcel.coordinateY = parcelMetadata.coordinateY;
parcel.district = parcelMetadata.district;
parcel.parcelHash = parcelMetadata.parcelAddress;

parcel.size = parcelMetadata.size;

let boostArray = parcelMetadata.boost;
parcel.fudBoost = boostArray[0];
parcel.fomoBoost = boostArray[1];
parcel.alphaBoost = boostArray[2];
parcel.kekBoost = boostArray[3];
}

//update auction too

// Entities can be written to the store with `.save()`
parcel.save();
}

export function handleTransferParcel(event: Transfer): void {
let user = getOrCreateUser(event.params._to.toHexString());
user.save();

let parcel = Parcel.load(event.params._tokenId.toString())!;
parcel.owner = user.id;
parcel.save();
}

export function handleMintParcel(event: MintParcel): void {
let parcel = getOrCreateParcel(
event.params._tokenId,
event.params._owner,
event.address
);
parcel.save();
}

// Whitelist
export function handleWhitelistCreated(event: WhitelistCreated): void {
Expand Down Expand Up @@ -1860,12 +1865,12 @@ export function handleERC721BuyOrderCanceled(
entity.save();
}

// export function handleKinshipBurned(event: any): void {
// let gotchi = getOrCreateAavegotchi(event.params._tokenId.toString(), event);
// if (!gotchi) return;
// gotchi.kinship = event.params._value;
// gotchi.save();
// }
export function handleKinshipBurned(event: KinshipBurned): void {
let gotchi = getOrCreateAavegotchi(event.params._tokenId.toString(), event);
if (!gotchi) return;
gotchi.kinship = event.params._value;
gotchi.save();
}

export function handleRoleGranted(event: RoleGranted): void {
erc7589.handleRoleGranted(event);
Expand Down
134 changes: 67 additions & 67 deletions src/utils/helpers/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
AavegotchiDiamond,
ERC1155ExecutedListing,
} from "../../../generated/AavegotchiDiamond/AavegotchiDiamond";

// import { RealmDiamond } from "../../../generated/RealmDiamond/RealmDiamond";
import { RealmDiamond } from "../../../generated/AavegotchiDiamond/RealmDiamond";

import {
Aavegotchi,
Expand All @@ -23,8 +22,9 @@ import {
ERC721BuyOrder,
ERC1155BuyOrder,
ERC1155BuyOrderExecution,
Parcel,
} from "../../../generated/schema";
// import { getFakeGotchiNFTToken } from "../../fetch/erc721";
import { getFakeGotchiNFTToken } from "../../fetch/erc721";
import { BIGINT_ZERO, PORTAL_STATUS_BOUGHT } from "../constants";
import { Address, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts";

Expand Down Expand Up @@ -216,20 +216,20 @@ export function updateERC721ListingInfo(
listing.blockCreated = event.block.number;
}

// let erc721Token = getFakeGotchiNFTToken(
// listingInfo.erc721TokenAddress,
// listingInfo.erc721TokenId
// );

// if (erc721Token != null) {
// listing.fakeGotchi_name = erc721Token.name;
// listing.fakeGotchi_publisher = erc721Token.publisher;
// listing.fakeGotchi_description = erc721Token.description;
// listing.fakeGotchi_artist = erc721Token.artist;
// listing.fakeGotchi_artistName = erc721Token.artistName;
// listing.fakeGotchi_editions = erc721Token.editions;
// listing.fakeGotchi_publisherName = erc721Token.publisherName;
// }
let erc721Token = getFakeGotchiNFTToken(
listingInfo.erc721TokenAddress,
listingInfo.erc721TokenId
);

if (erc721Token != null) {
listing.fakeGotchi_name = erc721Token.name;
listing.fakeGotchi_publisher = erc721Token.publisher;
listing.fakeGotchi_description = erc721Token.description;
listing.fakeGotchi_artist = erc721Token.artist;
listing.fakeGotchi_artistName = erc721Token.artistName;
listing.fakeGotchi_editions = erc721Token.editions;
listing.fakeGotchi_publisherName = erc721Token.publisherName;
}

if (listing.category.toI32() <= 2) {
let portal = getOrCreatePortal(
Expand Down Expand Up @@ -573,56 +573,56 @@ export function getStatisticEntity(): Statistic {
return stats as Statistic;
}

// export function getOrCreateParcel(
// tokenId: BigInt,
// owner: Bytes,
// tokenAddress: Address,
// updateParcelInfo: boolean = true
// ): Parcel {
// let parcel = Parcel.load(tokenId.toString());

// // Entities only exist after they have been saved to the store;
// // `null` checks allow to create entities on demand
// if (parcel == null) {
// parcel = new Parcel(tokenId.toString());
// parcel.timesTraded = BIGINT_ZERO;
// }

// if (!updateParcelInfo) {
// return parcel;
// }

// log.debug("token address: {}", [tokenAddress.toHexString()]);

// let contract = RealmDiamond.bind(tokenAddress);
// let parcelInfo = contract.try_getParcelInfo(tokenId);

// if (parcelInfo.reverted) {
// } else {
// let parcelMetadata = parcelInfo.value;
// parcel.parcelId = parcelMetadata.parcelId;
// parcel.tokenId = tokenId;

// let user = getOrCreateUser(owner.toHexString());
// user.save();
// parcel.owner = user.id;

// parcel.coordinateX = parcelMetadata.coordinateX;
// parcel.coordinateY = parcelMetadata.coordinateY;
// parcel.district = parcelMetadata.district;
// parcel.parcelHash = parcelMetadata.parcelAddress;

// let boostArray = parcelMetadata.boost;
// parcel.fudBoost = boostArray[0];
// parcel.fomoBoost = boostArray[1];
// parcel.alphaBoost = boostArray[2];
// parcel.kekBoost = boostArray[3];

// parcel.size = parcelMetadata.size;
// }

// return parcel as Parcel;
// }
export function getOrCreateParcel(
tokenId: BigInt,
owner: Bytes,
tokenAddress: Address,
updateParcelInfo: boolean = true
): Parcel {
let parcel = Parcel.load(tokenId.toString());

// Entities only exist after they have been saved to the store;
// `null` checks allow to create entities on demand
if (parcel == null) {
parcel = new Parcel(tokenId.toString());
parcel.timesTraded = BIGINT_ZERO;
}

if (!updateParcelInfo) {
return parcel;
}

log.debug("token address: {}", [tokenAddress.toHexString()]);

let contract = RealmDiamond.bind(tokenAddress);
let parcelInfo = contract.try_getParcelInfo(tokenId);

if (parcelInfo.reverted) {
} else {
let parcelMetadata = parcelInfo.value;
parcel.parcelId = parcelMetadata.parcelId;
parcel.tokenId = tokenId;

let user = getOrCreateUser(owner.toHexString());
user.save();
parcel.owner = user.id;

parcel.coordinateX = parcelMetadata.coordinateX;
parcel.coordinateY = parcelMetadata.coordinateY;
parcel.district = parcelMetadata.district;
parcel.parcelHash = parcelMetadata.parcelAddress;

let boostArray = parcelMetadata.boost;
parcel.fudBoost = boostArray[0];
parcel.fomoBoost = boostArray[1];
parcel.alphaBoost = boostArray[2];
parcel.kekBoost = boostArray[3];

parcel.size = parcelMetadata.size;
}

return parcel as Parcel;
}

export function updateAavegotchiWearables(
gotchi: Aavegotchi,
Expand Down
Loading

0 comments on commit 0470e34

Please sign in to comment.