Skip to content

Commit

Permalink
Merge pull request #8 from VaporFi/task/DEV-723
Browse files Browse the repository at this point in the history
fix(vapordex): incorrect startblock and make address lowercase DEV-723
  • Loading branch information
royvardhan committed Jun 28, 2024
2 parents df0778e + 7175e5e commit 0c249ec
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATABASE_URL=
MAX_BLOCK_RANGE=
AVALANCHE_RPC=
AVALANCHE_RPC=
ORACLE_PRIVATE_KEY=
11 changes: 7 additions & 4 deletions ponder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export default createConfig({
abi: DexAggregatorAbi,
network: {
avalanche: {
address: addresses.DexAggregator?.avalanche,
startBlock: 42346292,
address: [
addresses.DexAggregator?.avalanche!,
addresses.DexAggregatorV2?.avalanche!,
],
startBlock: 20308160,
maxBlockRange,
},
},
Expand Down Expand Up @@ -62,7 +65,7 @@ export default createConfig({
network: {
avalanche: {
address: addresses.VapeStaking?.avalanche,
startBlock: 32271032,
startBlock: 33291048,
maxBlockRange,
},
},
Expand All @@ -73,7 +76,7 @@ export default createConfig({
network: {
avalanche: {
address: addresses.RewardsController?.avalanche,
startBlock: 43805790, // TODO: Update this
startBlock: 43508160, // TODO: Update this
maxBlockRange,
},
},
Expand Down
16 changes: 16 additions & 0 deletions ponder.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const generateLMSeasonEnum = (numSeasons: number) => {
*/
const pointsSource = [
"stratosphere_enrollment",
"chain_first_wallet",
"dex_aggregator_swap",
"dex_aggregator_first_swap",
"dex_aggregator_1k_swaps",
"dex_aggregator_10k_swaps",
"dex_aggregator_100k_swaps",
Expand Down Expand Up @@ -85,12 +87,16 @@ export default createSchema((p) => ({
chainId: p.int(),
LMSeasons: p.bigint().list(), // If the array is empty, the user has not participated in any season
depositInVS: p.boolean(),
chainFirstWallet: p.boolean(),
firstWalletInVPNDLM: p.boolean(),
firstWalletInVAPELM: p.boolean(),
LMOneSeasonPointsClaimed: p.boolean(),
LMThreeSeasonsPointsClaimed: p.boolean(),
LMSixSeasonsPointsClaimed: p.boolean(),
LMOneYearPointsClaimed: p.boolean(),
usdValueOfSwaps: p.bigint(),
swaps: p.bigint(),
firstSwap: p.boolean(),
first1kSwaps: p.boolean(),
first10kSwaps: p.boolean(),
first100kSwaps: p.boolean(),
Expand All @@ -104,6 +110,8 @@ export default createSchema((p) => ({
chainId: p.int(),
}),

AllProtocols: p.createTable({ id: p.string(), firstWallet: p.string() }),

// @dev: Id is the seasonId
LiquidMining: p.createTable({
id: p.bigint(),
Expand Down Expand Up @@ -137,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(),
}),
}));
3 changes: 3 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export const addresses: AddressMap = {
DexAggregator: {
[Chains.AVALANCHE]: "0xDef9ee39FD82ee57a1b789Bc877E2Cbd88fd5caE",
},
DexAggregatorV2: {
[Chains.AVALANCHE]: "0x55477d8537ede381784b448876AfAa98aa450E63",
},
LiquidMining: {
[Chains.AVALANCHE]: "0xAe950fdd0CC79DDE64d3Fffd40fabec3f7ba368B",
},
Expand Down
83 changes: 80 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
BIGINT_ONE,
BIGINT_ZERO,
deployedBlockTimestamps,
pointsMap,
} from "./config/constants";
import axios from "axios";

Expand Down Expand Up @@ -57,6 +58,40 @@ export function getMonthlyID(
return monthlyID + 1n;
}

export const handleChainFirstWallet = async (
context: Context,
chainId: number,
userAddressLowerCase: string,
userData: any,
event: any
): Promise<UserHistory> => {
const { AllProtocols, UserHistory, Points } = context.db;
let allProtocols = await AllProtocols.findUnique({ id: "protocols" });
if (!allProtocols) {
allProtocols = await AllProtocols.create({
id: "protocols",
data: { firstWallet: userAddressLowerCase },
});
await Points.create({
id: `${userAddressLowerCase}-chain-first-wallet`,
data: {
userDataId: `${userAddressLowerCase}-${chainId}`,
userHistoryId: `${userAddressLowerCase}-${chainId}`,
pointsSource: "chain_first_wallet",
points: pointsMap.ChainFirstWallet,
chainId: chainId,
timestamp: event?.block?.timestamp,
},
});

userData = await UserHistory.update({
id: `${userAddressLowerCase}-${chainId}`,
data: { chainFirstWallet: true },
});
}
return userData;
};

/**
* Retrieves or creates user data based on the provided parameters.
* @param context - The context object containing the database connection.
Expand Down Expand Up @@ -97,6 +132,10 @@ export async function getOrCreateUserData(
first10kSwaps: false,
first100kSwaps: false,
chainId: chainId,
firstWalletInVPNDLM: false,
firstSwap: false,
firstWalletInVAPELM: false,
chainFirstWallet: false,
},
});

Expand All @@ -122,7 +161,8 @@ export async function getOrCreateUserData(
export async function queryQuote(
quoteParams: QueryWithAmountIn,
context: Context,
blockNumber: bigint
blockNumber: bigint,
aggregatorAddress: `0x${string}`
): Promise<bigint> {
const { client, network, contracts } = context;

Expand All @@ -132,7 +172,7 @@ export async function queryQuote(
try {
quote = await client.readContract({
abi: contracts.DexAggregator.abi,
address: addresses.DexAggregator![network.name] as `0x${string}`,
address: aggregatorAddress,
functionName: "findBestPath",
args: [
quoteParams.amountIn,
Expand Down Expand Up @@ -292,7 +332,10 @@ export async function getOrUpdateTokenIdData(
const { chainId, name } = context.network;

const deployedBlockTimestamp = deployedBlockTimestamps[name].Stratosphere;
const weeklyId = `${tokenId}-${chainId}-${getWeeklyID(timestamp, deployedBlockTimestamp)}`;
const weeklyId = `${tokenId}-${chainId}-${getWeeklyID(
timestamp,
deployedBlockTimestamp
)}`;

let tokenIdData = await TokenIdData.findUnique({
id: `${tokenId}-${chainId}`,
Expand Down Expand Up @@ -349,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;
}
Loading

0 comments on commit 0c249ec

Please sign in to comment.