From 83bb25352e0ee92f234b33b0cd609f7b2eb7d469 Mon Sep 17 00:00:00 2001 From: Narayan Prusty Date: Wed, 17 Jul 2024 16:34:39 +0530 Subject: [PATCH 1/3] fix: added script --- deploy/020-prime-update-scores.ts | 76 +++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 deploy/020-prime-update-scores.ts diff --git a/deploy/020-prime-update-scores.ts b/deploy/020-prime-update-scores.ts new file mode 100644 index 000000000..7c864fe06 --- /dev/null +++ b/deploy/020-prime-update-scores.ts @@ -0,0 +1,76 @@ +import { Prime, VToken, VToken__factory } from "../typechain"; + +import { BigNumber, BigNumberish } from "ethers"; +import { parseUnits } from "ethers/lib/utils"; +import { ethers } from "hardhat"; +import { DeployFunction } from "hardhat-deploy/types"; +import { HardhatRuntimeEnvironment } from "hardhat/types"; + +interface ScoreUpdate { + [key: string]: string[]; +} + +const fetchPrimeHolders = async (prime: Prime, fromBlock: number, toBlock: number): Promise => { + const events = await prime.queryFilter(prime.filters.Mint(), fromBlock, toBlock); + const users = []; + + for (const event of events) { + const user = event.args[0]; + users.push(user); + } + + return users; +} + +const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { + const { deployments, getNamedAccounts } = hre; + const { deploy } = deployments; + const { deployer } = await getNamedAccounts(); + + const prime: Prime = await ethers.getContract(`Prime`); + const primeHolders: string[] = []; + const scoreUpdates: ScoreUpdate = {} + + const fromBlock = 20157699; + const toBlock = 20325425; //await ethers.provider.getBlockNumber(); + const chunkSize = 1000; + + let startBlock = fromBlock; + + while (startBlock <= toBlock) { + const endBlock = Math.min(startBlock + chunkSize - 1, toBlock); + const users = await fetchPrimeHolders(prime, startBlock, endBlock); + primeHolders.push(...users); + + console.log(`Fetched events from block ${startBlock} to ${endBlock}`); + startBlock = endBlock + 1; + } + + const markets = await prime.getAllMarkets(); + + for (const market of markets) { + // Ignore WETH market + if (market == markets[markets.length - 1]) { + continue + } + + // if user has balance for the market then update score + const vTokenFactory: VToken__factory = await ethers.getContractFactory("VToken"); + const marketContract: VToken = await vTokenFactory.attach(market).connect(ethers.provider); + + for (const user of primeHolders) { + const balance = await marketContract.balanceOf(user); + if (balance.gt(0)) { + scoreUpdates[user] = scoreUpdates[user] ? [...scoreUpdates[user], market] : [market]; + } + } + } + + console.log("********** Score Updates **********"); + console.log(scoreUpdates) +}; + +func.tags = ["prime-score-updates"]; +func.skip = async (hre: HardhatRuntimeEnvironment) => !hre.network.live; + +export default func; From 45c3085f267e42e5c61a3a3192129752c3decbdc Mon Sep 17 00:00:00 2001 From: Narayan Prusty Date: Wed, 17 Jul 2024 16:40:31 +0530 Subject: [PATCH 2/3] fix: fixed lint --- deploy/020-prime-update-scores.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/deploy/020-prime-update-scores.ts b/deploy/020-prime-update-scores.ts index 7c864fe06..9ddffebeb 100644 --- a/deploy/020-prime-update-scores.ts +++ b/deploy/020-prime-update-scores.ts @@ -1,11 +1,9 @@ -import { Prime, VToken, VToken__factory } from "../typechain"; - -import { BigNumber, BigNumberish } from "ethers"; -import { parseUnits } from "ethers/lib/utils"; import { ethers } from "hardhat"; import { DeployFunction } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; +import { Prime, VToken, VToken__factory } from "../typechain"; + interface ScoreUpdate { [key: string]: string[]; } @@ -20,19 +18,15 @@ const fetchPrimeHolders = async (prime: Prime, fromBlock: number, toBlock: numbe } return users; -} - -const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const { deployments, getNamedAccounts } = hre; - const { deploy } = deployments; - const { deployer } = await getNamedAccounts(); +}; +const func: DeployFunction = async function () { const prime: Prime = await ethers.getContract(`Prime`); const primeHolders: string[] = []; - const scoreUpdates: ScoreUpdate = {} + const scoreUpdates: ScoreUpdate = {}; const fromBlock = 20157699; - const toBlock = 20325425; //await ethers.provider.getBlockNumber(); + const toBlock = await ethers.provider.getBlockNumber(); const chunkSize = 1000; let startBlock = fromBlock; @@ -49,25 +43,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const markets = await prime.getAllMarkets(); for (const market of markets) { - // Ignore WETH market - if (market == markets[markets.length - 1]) { - continue + // Ignore WETH market + if (market == markets[markets.length - 1]) { + continue; } - // if user has balance for the market then update score const vTokenFactory: VToken__factory = await ethers.getContractFactory("VToken"); const marketContract: VToken = await vTokenFactory.attach(market).connect(ethers.provider); for (const user of primeHolders) { const balance = await marketContract.balanceOf(user); if (balance.gt(0)) { - scoreUpdates[user] = scoreUpdates[user] ? [...scoreUpdates[user], market] : [market]; + scoreUpdates[user] = scoreUpdates[user] ? [...scoreUpdates[user], market] : [market]; } } } console.log("********** Score Updates **********"); - console.log(scoreUpdates) + console.log(scoreUpdates); }; func.tags = ["prime-score-updates"]; From 81fe7048803b711ad3e8acfabc39f6e46d2f7737 Mon Sep 17 00:00:00 2001 From: Narayan Prusty Date: Wed, 17 Jul 2024 16:43:51 +0530 Subject: [PATCH 3/3] fix: check skip markets --- deploy/020-prime-update-scores.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deploy/020-prime-update-scores.ts b/deploy/020-prime-update-scores.ts index 9ddffebeb..f2010034e 100644 --- a/deploy/020-prime-update-scores.ts +++ b/deploy/020-prime-update-scores.ts @@ -42,9 +42,11 @@ const func: DeployFunction = async function () { const markets = await prime.getAllMarkets(); + // Ignore WETH market + const skipMarkets = [(await ethers.getContract(`VToken_vWETH_LiquidStakedETH`)).address]; + for (const market of markets) { - // Ignore WETH market - if (market == markets[markets.length - 1]) { + if (skipMarkets.includes(market)) { continue; }