Skip to content

Commit

Permalink
feat: add tier tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
royvardhan committed Jun 10, 2024
1 parent 3fb13b7 commit 606701b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,12 @@ export default createSchema((p) => ({
pointsSpent: p.bigint(),
lastUpdated: p.bigint(),
}),

// @dev: Id is the tierId + chainId
// @dev: The tierId is the tier number
// @dev: wallets is the number of wallets in the tier
WalletsPerTier: p.createTable({
id: p.string(),
wallets: p.string().list(),
}),
}));
34 changes: 34 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,37 @@ export async function getOrUpdateTokenIdData(

return tokenIdData;
}

export async function getOrUpdateWalletsPerTier(
context: Context,
tierId: bigint,
userAddress: string
): Promise<any> {
const { WalletsPerTier } = context.db;
const { chainId } = context.network;

const id = `${tierId}-${chainId}`;

let walletsPerTier = await WalletsPerTier.findUnique({ id });

if (!walletsPerTier) {
walletsPerTier = await WalletsPerTier.create({
id,
data: {
wallets: [userAddress],
},
});
}

if (!walletsPerTier.wallets.includes(userAddress)) {
walletsPerTier.wallets.push(userAddress);
walletsPerTier = await WalletsPerTier.update({
id,
data: {
wallets: walletsPerTier.wallets,
},
});
}

return walletsPerTier;
}
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getTokenId,
getOrUpdateTokenIdData,
handleChainFirstWallet,
getOrUpdateWalletsPerTier,
} from "./helpers";
import {
BIGINT_HUNDRED_THOUSAND,
Expand Down Expand Up @@ -43,6 +44,8 @@ ponder.on("Stratosphere:Transfer", async ({ event, context }) => {
await getOrUpdateTokenIdData(context, tokenId, timestamp, {
pointsEarned: pointsMap.Enrollment,
});

await getOrUpdateWalletsPerTier(context, 0n, userAddressLowerCase);
});

ponder.on("LiquidMining:Deposit", async ({ event, context }) => {
Expand Down Expand Up @@ -493,4 +496,13 @@ ponder.on("RewardsController:ClaimPoints", async ({ event, context }) => {
await getOrUpdateTokenIdData(context, tokenId, timestamp, {
pointsClaimed: points,
});

const tier = await context.client.readContract({
abi: context.contracts.RewardsController.abi,
address: context.contracts.RewardsController.address as `0x${string}`,
functionName: "tierOf",
args: [tokenId],
});

await getOrUpdateWalletsPerTier(context, tier, event.args.member);
});

0 comments on commit 606701b

Please sign in to comment.