diff --git a/ponder.schema.ts b/ponder.schema.ts index 3b5f9e4..4bfc233 100644 --- a/ponder.schema.ts +++ b/ponder.schema.ts @@ -38,7 +38,7 @@ const generateLMSeasonEnum = (numSeasons: number) => { * - "liquid_mining_twelve_seasons": Indexes twelve seasons in Liquid Mining (1000 * 10^6 points) * - ...generateLMSeasonEnum(120): Indexes first wallet in a Liquid Mining new season (500 * 10^6 points) */ -const PointsSource = [ +const pointsSource = [ "stratosphere_enrollment", "dex_aggregator_swap", "dex_aggregator_1k_swaps", @@ -55,7 +55,7 @@ const PointsSource = [ ]; export default createSchema((p) => ({ - PointsSource: p.createEnum(PointsSource), + PointsSource: p.createEnum(pointsSource), Points: p.createTable({ id: p.string(), // Use enum for points source diff --git a/src/config/constants.ts b/src/config/constants.ts index 26d9998..d234b14 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -85,7 +85,7 @@ export const deployedBlockTimestamps = { */ export const addresses: AddressMap = { Stratosphere: { - [Chains.AVALANCHE]: "0x08e287adcf9bf6773a87e1a278aa9042bef44b60", + [Chains.AVALANCHE]: "0x08e287adCf9BF6773a87e1a278aa9042BEF44b60", }, DexAggregator: { diff --git a/src/helpers.ts b/src/helpers.ts index 3931119..07b7717 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -120,13 +120,23 @@ export async function getTokenId( ): Promise { const { client, network } = context; - const tokenId = await client.readContract({ - abi: StratosphereAbi, - address: addresses.Stratosphere![network.name] as `0x${string}`, - functionName: "tokenIdOf", - args: [address], - }); + let tokenId = 0n; + let revertedAddresses = []; + + try { + tokenId = await client.readContract({ + abi: StratosphereAbi, + address: addresses.Stratosphere![network.name] as `0x${string}`, + functionName: "tokenIdOf", + args: [address], + }); + } catch (e) { + revertedAddresses.push(address); + } + if (revertedAddresses.length > 0) { + console.log(revertedAddresses); + } return tokenId; } diff --git a/src/index.ts b/src/index.ts index 1ef08d8..352e470 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,8 +5,10 @@ import { BIGINT_ONE, BIGINT_TEN_THOUSAND, BIGINT_THOUSAND, + BIGINT_ZERO, MINIMUM_POINTS, assets, + chainId, pointsMap, } from "./config/constants"; @@ -14,17 +16,18 @@ ponder.on("Stratosphere:Transfer", async ({ event, context }) => { const { Points } = context.db; const { to: userAddress, tokenId } = event.args; const { hash } = event.transaction; + const { chainId } = context.network; await getOrCreateUserData(context, tokenId, userAddress); await Points.create({ - id: hash, + id: `${hash}-stratosphere-enrollment`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, pointsSource: "stratosphere_enrollment", points: pointsMap.Enrollment, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); @@ -33,9 +36,14 @@ ponder.on("Stratosphere:Transfer", async ({ event, context }) => { ponder.on("LiquidMining:Deposit", async ({ event, context }) => { const { Points, UserHistory, LiquidMining } = context.db; const { hash } = event.transaction; + const { chainId } = context.network; const { seasonId, user: userAddress, amount } = event.args; const tokenId = await getTokenId(userAddress, context); + if (tokenId === BIGINT_ZERO) { + return; + } + let liquidMiningData = await LiquidMining.findUnique({ id: seasonId, }); @@ -49,46 +57,47 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { }); await Points.create({ - id: hash, + id: `${hash}-liquid-mining-first-wallet`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, pointsSource: `liquid_mining_first_wallet_season_${Number(seasonId)}`, points: pointsMap.FirstWalletInVPNDLM, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); } const userData = await getOrCreateUserData(context, tokenId, userAddress); + if (userData.LMSeasons.length === 0) { await Points.create({ - id: hash, + id: `${hash}-liquid-mining-first-deposit`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "liquid-mining_first_deposit", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "liquid_mining_first_deposit", points: pointsMap.FirstDepositInVPNDLM, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await Points.create({ - id: hash, + id: `${hash}-liquid-mining-one-season`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "liquid-mining_one_season", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "liquid_mining_one_season", points: pointsMap.OneSeasonVPNDLMLock, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { LMSeasons: [seasonId], LMOneSeasonPointsClaimed: true, @@ -98,7 +107,7 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { if (!userData.LMSeasons.includes(seasonId)) { await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: ({ current }) => ({ LMSeasons: [...current.LMSeasons, seasonId], }), @@ -110,19 +119,19 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { !userData.LMThreeSeasonsPointsClaimed ) { await Points.create({ - id: hash, + id: `${hash}-liquid-mining-three-seasons`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "liquid-mining_three_seasons", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "liquid_mining_three_seasons", points: pointsMap.ThreeSeasonVPNDLMLock, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { LMThreeSeasonsPointsClaimed: true, }, @@ -131,19 +140,19 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { if (userData.LMSeasons.length === 6 && !userData.LMSixSeasonsPointsClaimed) { await Points.create({ - id: hash, + id: `${hash}-liquid-mining-six-seasons`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "liquid-mining_six_seasons", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "liquid_mining_six_seasons", points: pointsMap.SixSeasonVPNDLMLock, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { LMSixSeasonsPointsClaimed: true, }, @@ -152,19 +161,19 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { if (userData.LMSeasons.length === 12 && !userData.LMOneYearPointsClaimed) { await Points.create({ - id: hash, + id: `${hash}-liquid-mining-twelve-seasons`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "liquid-mining_twelve_seasons", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "liquid_mining_twelve_seasons", points: pointsMap.OneYearVPNDLMLock, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { LMOneYearPointsClaimed: true, }, @@ -175,9 +184,14 @@ ponder.on("LiquidMining:Deposit", async ({ event, context }) => { ponder.on("VapeStaking:Deposit", async ({ event, context }) => { const { Points, UserHistory, VapeStaking } = context.db; const { hash } = event.transaction; + const { chainId } = context.network; const { user: userAddress } = event.args; const tokenId = await getTokenId(userAddress, context); + if (tokenId === BIGINT_ZERO) { + return; + } + let vapeStakingData = await VapeStaking.findUnique({ id: "vape-staking", }); @@ -192,13 +206,13 @@ ponder.on("VapeStaking:Deposit", async ({ event, context }) => { }); await Points.create({ - id: hash, + id: `${hash}-vape-staking-first-wallet`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "vape-staking_first_wallet", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "vape_staking_first_wallet", points: pointsMap.FirstWalletInVAPELM, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); @@ -208,19 +222,19 @@ ponder.on("VapeStaking:Deposit", async ({ event, context }) => { if (!userData.depositInVS) { await Points.create({ - id: hash, + id: `${hash}-liquid-mining-first-deposit`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "vape-staking_first_deposit", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "vape_staking_first_deposit", points: pointsMap.FirstDepositInVAPELM, - chainId: context.network.chainId, + chainId: chainId, timestamp: event.block.timestamp, }, }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { depositInVS: true, }, @@ -237,7 +251,7 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { const tokenId = await getTokenId(userAddress, context); - if (tokenId.toString() === "0") { + if (tokenId === BIGINT_ZERO) { return; } @@ -251,11 +265,11 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { // If we are unable to find a path, usdValueOfTrade is Zero and we don't want to index that if (usdValueOfTrade >= MINIMUM_POINTS) { await Points.create({ - id: hash, + id: `${hash}-dex-aggregator-swap`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "dex-aggregator_swap", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "dex_aggregator_swap", points: usdValueOfTrade, chainId: chainId, timestamp: event.block.timestamp, @@ -281,11 +295,11 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { !userData.first1kSwaps ) { await Points.create({ - id: hash, + id: `${hash}-dex-aggregator-1k-swaps`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "dex-aggregator_1k_swaps", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "dex_aggregator_1k_swaps", points: pointsMap.ThousandSwaps, chainId: chainId, timestamp: event.block.timestamp, @@ -293,7 +307,7 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { first1kSwaps: true, }, @@ -306,11 +320,11 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { !userData.first10kSwaps ) { await Points.create({ - id: hash, + id: `${hash}-dex-aggregator-10k-swaps`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "dex-aggregator_10k_swaps", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "dex_aggregator_10k_swaps", points: pointsMap.TenThousandSwaps, chainId: chainId, timestamp: event.block.timestamp, @@ -318,7 +332,7 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { first10kSwaps: true, }, @@ -331,11 +345,11 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { !userData.first100kSwaps ) { await Points.create({ - id: hash, + id: `${hash}-dex-aggregator-100k-swaps`, data: { - userDataId: `${userAddress}-${context.network.chainId}`, - userHistoryId: `${userAddress}-${context.network.chainId}`, - pointsSource: "dex-aggregator_100k_swaps", + userDataId: `${userAddress}-${chainId}`, + userHistoryId: `${userAddress}-${chainId}`, + pointsSource: "dex_aggregator_100k_swaps", points: pointsMap.HundredThousandSwaps, chainId: chainId, timestamp: event.block.timestamp, @@ -343,7 +357,7 @@ ponder.on("DexAggregator:RouterSwap", async ({ event, context }) => { }); await UserHistory.update({ - id: userAddress, + id: `${userAddress}-${chainId}`, data: { first100kSwaps: true, },