Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loot Discoveries + Sepolia Config #32

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion indexer/env-sepolia
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GAME="0x0305f26ad19e0a10715d9f3137573d3a543de7b707967cd85d11234d6ec0fb7e"
GAME="0x05545d79b497a9b924ed3321361520566c90dc1abb0aa1643cc4839b12c73136"
START=68300
MONGO_CONNECTION_STRING="mongodb://mongo:mongo@mongo:27017"
MONGO_DB="mongo"
Expand Down
2 changes: 1 addition & 1 deletion indexer/graphql/src/indexer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def __init__(self):
3: "Item",
}

self.SUB_DISCOVERY_TYPES = {1: "Health", 2: "Gold", 3: "XP"}
self.SUB_DISCOVERY_TYPES = {1: "Health", 2: "Gold", 3: "Loot"}

self.MATERIALS = {
0: "Generic",
Expand Down
24 changes: 6 additions & 18 deletions indexer/src/adventurers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import {
ADVENTURER_UPGRADED,
DISCOVERED_GOLD,
DISCOVERED_HEALTH,
DISCOVERED_XP,
parseAdventurerUpgraded,
parseDiscoveredGold,
parseDiscoveredHealth,
parseDiscoveredXp,
parseStartGame,
START_GAME,
PURCHASED_POTIONS,
PURCHASED_ITEMS,
ATTACKED_BY_BEAST,
ADVENTURER_DIED,
Expand Down Expand Up @@ -43,6 +40,8 @@ import {
parseUpgradesAvailable,
DISCOVERED_BEAST,
parseDiscoveredBeast,
DISCOVERED_LOOT,
parseDiscoveredLoot,
} from "./utils/events.ts";
import { insertAdventurer, updateAdventurer } from "./utils/helpers.ts";
import { MONGO_CONNECTION_STRING } from "./utils/constants.ts";
Expand All @@ -59,11 +58,10 @@ const filter = {
{ fromAddress: GAME, keys: [ADVENTURER_UPGRADED] },
{ fromAddress: GAME, keys: [DISCOVERED_HEALTH] },
{ fromAddress: GAME, keys: [DISCOVERED_GOLD] },
{ fromAddress: GAME, keys: [DISCOVERED_XP] },
{ fromAddress: GAME, keys: [DISCOVERED_LOOT] },
{ fromAddress: GAME, keys: [DODGED_OBSTACLE] },
{ fromAddress: GAME, keys: [HIT_BY_OBSTACLE] },
{ fromAddress: GAME, keys: [DISCOVERED_BEAST] },
{ fromAddress: GAME, keys: [PURCHASED_POTIONS] },
{ fromAddress: GAME, keys: [PURCHASED_ITEMS] },
{ fromAddress: GAME, keys: [EQUIPPED_ITEMS] },
{ fromAddress: GAME, keys: [DROPPED_ITEMS] },
Expand Down Expand Up @@ -167,9 +165,9 @@ export default function transform({ header, events }: Block) {
}),
];
}
case DISCOVERED_XP: {
console.log("DISCOVERED_XP", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredXp(event.data, 0);
case DISCOVERED_LOOT: {
console.log("DISCOVERED_LOOT", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredLoot(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand Down Expand Up @@ -207,16 +205,6 @@ export default function transform({ header, events }: Block) {
}),
];
}
case PURCHASED_POTIONS: {
console.log("PURCHASED_POTIONS", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredXp(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
adventurerState: value.adventurerState,
}),
];
}
case PURCHASED_ITEMS: {
console.log("PURCHASED_ITEMS", "->", "ADVENTURER UPDATES");
const { value } = parsePurchasedItems(event.data, 0);
Expand Down
20 changes: 10 additions & 10 deletions indexer/src/discoveries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
DISCOVERED_BEAST,
DISCOVERED_GOLD,
DISCOVERED_HEALTH,
DISCOVERED_XP,
DISCOVERED_LOOT,
DODGED_OBSTACLE,
HIT_BY_OBSTACLE,
parseAmbushedByBeast,
parseDiscoveredBeast,
parseDiscoveredGold,
parseDiscoveredHealth,
parseDiscoveredXp,
parseDiscoveredLoot,
parseHitByObstacle,
} from "./utils/events.ts";
import { insertDiscovery } from "./utils/helpers.ts";
Expand All @@ -30,7 +30,7 @@ const filter = {
events: [
{ fromAddress: GAME, keys: [DISCOVERED_HEALTH] },
{ fromAddress: GAME, keys: [DISCOVERED_GOLD] },
{ fromAddress: GAME, keys: [DISCOVERED_XP] },
{ fromAddress: GAME, keys: [DISCOVERED_LOOT] },
{ fromAddress: GAME, keys: [HIT_BY_OBSTACLE] },
{ fromAddress: GAME, keys: [DODGED_OBSTACLE] },
{ fromAddress: GAME, keys: [AMBUSHED_BY_BEAST] },
Expand Down Expand Up @@ -92,14 +92,14 @@ export default function transform({ header, events }: Block) {
case DISCOVERED_GOLD: {
const { value } = parseDiscoveredGold(event.data, 0);
const as = value.adventurerState;
console.log("DISCOVERED_HEALTH", "->", "DISCOVERIES UPDATES");
console.log("DISCOVERED_GOLD", "->", "DISCOVERIES UPDATES");
return [
insertDiscovery({
txHash: receipt.transactionHash,
adventurerId: as.adventurerId,
adventurerHealth: as.adventurer.health,
discoveryType: 3,
subDiscoveryType: 1,
subDiscoveryType: 2,
outputAmount: value.goldAmount,
obstacle: 0,
obstacleLevel: 0,
Expand All @@ -121,18 +121,18 @@ export default function transform({ header, events }: Block) {
}),
];
}
case DISCOVERED_XP: {
const { value } = parseDiscoveredXp(event.data, 0);
case DISCOVERED_LOOT: {
const { value } = parseDiscoveredLoot(event.data, 0);
const as = value.adventurerState;
console.log("DISCOVERED_XP", "->", "DISCOVERIES UPDATES");
console.log("DISCOVERED_LOOT", "->", "DISCOVERIES UPDATES");
return [
insertDiscovery({
txHash: receipt.transactionHash,
adventurerId: as.adventurerId,
adventurerHealth: as.adventurer.health,
discoveryType: 3,
subDiscoveryType: 1,
outputAmount: value.xpAmount,
subDiscoveryType: 3,
outputAmount: value.itemId,
obstacle: 0,
obstacleLevel: 0,
dodgedObstacle: false,
Expand Down
59 changes: 59 additions & 0 deletions indexer/src/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import {
PURCHASED_ITEMS,
SLAYED_BEAST,
START_GAME,
DISCOVERED_LOOT,
parseDiscoveredLoot,
EQUIPMENT_CHANGED,
parseEquipmentChanged,
} from "./utils/events.ts";
import { insertItem, updateItemsXP } from "./utils/helpers.ts";
import { checkExistsInt, encodeIntAsBytes } from "./utils/encode.ts";
Expand All @@ -38,6 +42,8 @@ const filter = {
events: [
{ fromAddress: GAME, keys: [START_GAME] },
{ fromAddress: GAME, keys: [PURCHASED_ITEMS] },
{ fromAddress: GAME, keys: [DISCOVERED_LOOT] },
{ fromAddress: GAME, keys: [EQUIPMENT_CHANGED] },
{ fromAddress: GAME, keys: [EQUIPPED_ITEMS] },
{ fromAddress: GAME, keys: [DROPPED_ITEMS] },
{ fromAddress: GAME, keys: [HIT_BY_OBSTACLE] },
Expand Down Expand Up @@ -119,6 +125,59 @@ export default function transform({ header, events }: Block) {
}));
return result;
}
case DISCOVERED_LOOT: {
const { value } = parseDiscoveredLoot(event.data, 0);
const as = value.adventurerState;
console.log("DISCOVERED_LOOT", "->", "ITEMS UPDATES");
return {
entity: {
item: checkExistsInt(BigInt(value.itemId)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
},
update: {
$set: {
item: checkExistsInt(BigInt(value.itemId)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
equipped: false,
timestamp: new Date().toISOString(),
},
},
};
}
case EQUIPMENT_CHANGED: {
const { value } = parseEquipmentChanged(event.data, 0);
const as = value.adventurerStateWithBag.adventurerState;
console.log("EQUIPMENT_CHANGED", "->", "ITEMS UPDATES");
const equippedResult = value.equippedItems.map((item) => ({
entity: {
item: checkExistsInt(BigInt(item)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
},
update: {
$set: {
item: checkExistsInt(BigInt(item)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
equipped: true,
timestamp: new Date().toISOString(),
},
},
}));
const baggedResult = value.baggedItems.map((item) => ({
entity: {
item: checkExistsInt(BigInt(item)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
},
update: {
$set: {
item: checkExistsInt(BigInt(item)),
adventurerId: checkExistsInt(BigInt(as.adventurerId)),
equipped: false,
timestamp: new Date().toISOString(),
},
},
}));
return [...equippedResult, ...baggedResult];
}
case EQUIPPED_ITEMS: {
const { value } = parseEquippedItems(event.data, 0);
const as = value.adventurerStateWithBag.adventurerState;
Expand Down
15 changes: 11 additions & 4 deletions indexer/src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const START_GAME = eventKey("StartGame");
export const ADVENTURER_UPGRADED = eventKey("AdventurerUpgraded");
export const DISCOVERED_HEALTH = eventKey("DiscoveredHealth");
export const DISCOVERED_GOLD = eventKey("DiscoveredGold");
export const DISCOVERED_XP = eventKey("DiscoveredXP");
export const DISCOVERED_LOOT = eventKey("DiscoveredLoot");
export const HIT_BY_OBSTACLE = eventKey("HitByObstacle");
export const DODGED_OBSTACLE = eventKey("DodgedObstacle");

Expand All @@ -37,12 +37,12 @@ export const ADVENTURER_DIED = eventKey("AdventurerDied");
export const FLEE_FAILED = eventKey("FleeFailed");
export const FLEE_SUCCEEDED = eventKey("FleeSucceeded");

export const PURCHASED_POTIONS = eventKey("PurchasedPotions");
export const PURCHASED_ITEMS = eventKey("PurchasedItems");
export const UPGRADES_AVAILABLE = eventKey("UpgradesAvailable");
export const EQUIPPED_ITEMS = eventKey("EquippedItems");
export const DROPPED_ITEMS = eventKey("DroppedItems");
export const ITEMS_LEVELED_UP = eventKey("ItemsLeveledUp");
export const EQUIPMENT_CHANGED = eventKey("EquipmentChanged");

export const NEW_HIGH_SCORE = eventKey("NewHighScore");
export const REWARD_DISTRIBUTION = eventKey("RewardDistribution");
Expand Down Expand Up @@ -230,9 +230,9 @@ export const parseDiscoveredGold = combineParsers({
goldAmount: { index: 1, parser: parseU16 },
});

export const parseDiscoveredXp = combineParsers({
export const parseDiscoveredLoot = combineParsers({
adventurerState: { index: 0, parser: parseAdventurerState },
xpAmount: { index: 1, parser: parseU16 },
itemId: { index: 1, parser: parseU8 },
});

export const parseHitByObstacle = combineParsers({
Expand Down Expand Up @@ -295,6 +295,13 @@ export const parseDroppedItems = combineParsers({
itemIds: { index: 1, parser: parseArray(parseU8) },
});

export const parseEquipmentChanged = combineParsers({
adventurerStateWithBag: { index: 0, parser: parseAdventurerStateWithBag },
equippedItems: { index: 1, parser: parseArray(parseU8) },
baggedItems: { index: 2, parser: parseArray(parseU8) },
droppedItems: { index: 3, parser: parseArray(parseU8) },
});

export const parseUpgradesAvailable = combineParsers({
adventurerState: { index: 0, parser: parseAdventurerState },
items: { index: 1, parser: parseArray(parseU8) },
Expand Down
2 changes: 1 addition & 1 deletion scripts/katana/graphql/indexer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def __init__(self):
3: "Item",
}

self.SUB_DISCOVERY_TYPES = {1: "Health", 2: "Gold", 3: "XP"}
self.SUB_DISCOVERY_TYPES = {1: "Health", 2: "Gold", 3: "Loot"}

self.MATERIALS = {
0: "Generic",
Expand Down
10 changes: 5 additions & 5 deletions scripts/katana/indexer/adventurers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import {
ADVENTURER_UPGRADED,
DISCOVERED_GOLD,
DISCOVERED_HEALTH,
DISCOVERED_XP,
parseAdventurerUpgraded,
parseDiscoveredGold,
parseDiscoveredHealth,
parseDiscoveredXp,
parseStartGame,
START_GAME,
PURCHASED_POTIONS,
Expand Down Expand Up @@ -43,6 +41,8 @@ import {
parseUpgradesAvailable,
DISCOVERED_BEAST,
parseDiscoveredBeast,
DISCOVERED_LOOT,
parseDiscoveredLoot,
} from "./utils/events.ts";
import { insertAdventurer, updateAdventurer } from "./utils/helpers.ts";
import { MONGO_CONNECTION_STRING } from "./utils/constants.ts";
Expand Down Expand Up @@ -167,9 +167,9 @@ export default function transform({ header, events }: Block) {
}),
];
}
case DISCOVERED_XP: {
console.log("DISCOVERED_XP", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredXp(event.data, 0);
case DISCOVERED_LOOT: {
console.log("DISCOVERED_LOOT", "->", "ADVENTURER UPDATES");
const { value } = parseDiscoveredLoot(event.data, 0);
return [
updateAdventurer({
timestamp: new Date().toISOString(),
Expand Down
16 changes: 9 additions & 7 deletions scripts/katana/indexer/discoveries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
DISCOVERED_BEAST,
DISCOVERED_GOLD,
DISCOVERED_HEALTH,
DISCOVERED_LOOT,
DISCOVERED_XP,
DODGED_OBSTACLE,
HIT_BY_OBSTACLE,
parseAmbushedByBeast,
parseDiscoveredBeast,
parseDiscoveredGold,
parseDiscoveredHealth,
parseDiscoveredLoot,
parseDiscoveredXp,
parseHitByObstacle,
} from "./utils/events.ts";
Expand Down Expand Up @@ -92,14 +94,14 @@ export default function transform({ header, events }: Block) {
case DISCOVERED_GOLD: {
const { value } = parseDiscoveredGold(event.data, 0);
const as = value.adventurerState;
console.log("DISCOVERED_HEALTH", "->", "DISCOVERIES UPDATES");
console.log("DISCOVERED_GOLD", "->", "DISCOVERIES UPDATES");
return [
insertDiscovery({
txHash: receipt.transactionHash,
adventurerId: as.adventurerId,
adventurerHealth: as.adventurer.health,
discoveryType: 3,
subDiscoveryType: 1,
subDiscoveryType: 2,
outputAmount: value.goldAmount,
obstacle: 0,
obstacleLevel: 0,
Expand All @@ -121,18 +123,18 @@ export default function transform({ header, events }: Block) {
}),
];
}
case DISCOVERED_XP: {
const { value } = parseDiscoveredXp(event.data, 0);
case DISCOVERED_LOOT: {
const { value } = parseDiscoveredLoot(event.data, 0);
const as = value.adventurerState;
console.log("DISCOVERED_XP", "->", "DISCOVERIES UPDATES");
console.log("DISCOVERED_LOOT", "->", "DISCOVERIES UPDATES");
return [
insertDiscovery({
txHash: receipt.transactionHash,
adventurerId: as.adventurerId,
adventurerHealth: as.adventurer.health,
discoveryType: 3,
subDiscoveryType: 1,
outputAmount: value.xpAmount,
subDiscoveryType: 3,
outputAmount: value.itemId,
obstacle: 0,
obstacleLevel: 0,
dodgedObstacle: false,
Expand Down
Loading
Loading