Skip to content

Commit

Permalink
fix: added script
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover committed Jul 17, 2024
1 parent dc9a3e8 commit 83bb253
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions deploy/020-prime-update-scores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Prime, VToken, VToken__factory } from "../typechain";

import { BigNumber, BigNumberish } from "ethers";

Check failure on line 3 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

'BigNumber' is defined but never used. Allowed unused vars must match /_/u

Check failure on line 3 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

'BigNumberish' is defined but never used. Allowed unused vars must match /_/u
import { parseUnits } from "ethers/lib/utils";

Check failure on line 4 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

'parseUnits' is defined but never used. Allowed unused vars must match /_/u
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<string[]> => {
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;

Check failure on line 27 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

'deploy' is assigned a value but never used. Allowed unused vars must match /_/u
const { deployer } = await getNamedAccounts();

Check failure on line 28 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

'deployer' is assigned a value but never used. Allowed unused vars must match /_/u

const prime: Prime = await ethers.getContract(`Prime`);
const primeHolders: string[] = [];
const scoreUpdates: ScoreUpdate = {}

const fromBlock = 20157699;
const toBlock = 20325425; //await ethers.provider.getBlockNumber();

Check failure on line 35 in deploy/020-prime-update-scores.ts

View workflow job for this annotation

GitHub Actions / Lint

Expected exception block, space or tab after '//' in comment
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;

0 comments on commit 83bb253

Please sign in to comment.