Skip to content

Commit

Permalink
Merge pull request #75 from aavegotchi/fix/missingItemType
Browse files Browse the repository at this point in the history
fix missing item type
  • Loading branch information
cinnabarhorse authored Feb 22, 2023
2 parents 56c2043 + eaa3a83 commit edf5852
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
20 changes: 11 additions & 9 deletions src/mappings/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function handleUseConsumables(event: UseConsumables): void {
let itemTypes = event.params._itemIds;
let quantities = event.params._quantities;
for (let i = 0; i < event.params._itemIds.length; i++) {
let itemType = getOrCreateItemType(itemTypes[i].toString());
let itemType = getOrCreateItemType(itemTypes[i].toString())!;
itemType.consumed = itemType.consumed.plus(quantities[i]);
itemType.save();
}
Expand Down Expand Up @@ -766,7 +766,9 @@ export function handleERC1155ListingRemoved(
//ERC1155 Item Types

export function handleAddItemType(event: AddItemType): void {
let itemType = getOrCreateItemType(event.params._itemType.svgId.toString());
let itemType = getOrCreateItemType(
event.params._itemType.svgId.toString()
)!;

let itemInfo = event.params._itemType;

Expand Down Expand Up @@ -800,7 +802,7 @@ export function handleItemTypeMaxQuantity(event: ItemTypeMaxQuantity): void {
let itemId = itemIds[index];
let maxQuantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.maxQuantity = maxQuantity;
itemType.save();
}
Expand All @@ -816,7 +818,7 @@ export function handlePurchaseItemsWithGhst(
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand All @@ -832,7 +834,7 @@ export function handlePurchaseItemsWithVouchers(
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand All @@ -846,7 +848,7 @@ export function handleMigrateVouchers(event: MigrateVouchers): void {
let itemId = itemIds[index];
let quantity = quantities[index];

let itemType = getOrCreateItemType(itemId.toString());
let itemType = getOrCreateItemType(itemId.toString())!;
itemType.totalQuantity = itemType.totalQuantity.plus(quantity);
itemType.save();
}
Expand Down Expand Up @@ -877,7 +879,7 @@ export function handleUpdateWearableSet(event: UpdateWearableSet): void {
}

export function handleItemModifiersSet(event: ItemModifiersSet): void {
let itemType = getOrCreateItemType(event.params._wearableId.toString());
let itemType = getOrCreateItemType(event.params._wearableId.toString())!;
itemType.traitModifiers = event.params._traitModifiers;
itemType.rarityScoreModifier = event.params._rarityScoreModifier;
itemType.save();
Expand All @@ -886,7 +888,7 @@ export function handleItemModifiersSet(event: ItemModifiersSet): void {
export function handleWearableSlotPositionsSet(
event: WearableSlotPositionsSet
): void {
let itemType = getOrCreateItemType(event.params._wearableId.toString());
let itemType = getOrCreateItemType(event.params._wearableId.toString())!;
itemType.slotPositions = event.params._slotPositions;
itemType.save();
}
Expand Down Expand Up @@ -928,7 +930,7 @@ export function handleERC1155ListingUpdated(event: UpdateERC1155Listing): void {
}

export function handleUpdateItemPrice(event: UpdateItemPrice): void {
let item = getOrCreateItemType(event.params._itemId.toString());
let item = getOrCreateItemType(event.params._itemId.toString())!;
item.ghstPrice = event.params._priceInWei;
item.save();
}
Expand Down
13 changes: 6 additions & 7 deletions src/utils/helpers/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ export function getOrCreateERC1155Purchase(
export function getOrCreateItemType(
id: string,
createIfNotFound: boolean = true
): ItemType {
): ItemType | null {
let itemType = ItemType.load(id);

if (itemType == null && createIfNotFound) {
itemType = new ItemType(id);
itemType.consumed = BIGINT_ZERO;
}

return itemType as ItemType;
return itemType;
}

export function getOrCreateWearableSet(
Expand Down Expand Up @@ -294,18 +294,17 @@ export function updateERC1155ListingInfo(
listing.rarityLevel = rarityLevel;

//items
} else {
} else if (listing.category.toI32() < 3) {
let itemType = getOrCreateItemType(
listingInfo.erc1155TypeId.toString(),
false
);

if (itemType) {
listing.rarityLevel = itemMaxQuantityToRarity(
itemType.maxQuantity
);
if (!itemType) {
return listing;
}

listing.rarityLevel = itemMaxQuantityToRarity(itemType.maxQuantity);
// brs modifier
listing.rarityScoreModifier = BigInt.fromI32(
itemType.rarityScoreModifier
Expand Down
6 changes: 3 additions & 3 deletions subgraph.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
specVersion: 0.0.3
# features:
# - grafting
# - grafting
# graft:
# base: QmdDkULLPVJoy6es7aKd9g6XfkfL2e6DfkNSEoa314HmSi # Subgraph ID of base subgraph
# block: 29354838 # Block number
# base: QmV3LtUtUCiD774HXR3D9SJBNgw2VNcXZM9McyMGTfotBQ # Subgraph ID of base subgraph
# block: 39550000 # Block number
description: Aavegotchi Core Matic
repository:
schema:
Expand Down

0 comments on commit edf5852

Please sign in to comment.