Skip to content

Commit

Permalink
refactor: update getBlockOrTimestampBasedDeploymentInfo() and removed…
Browse files Browse the repository at this point in the history
… redundancy
  • Loading branch information
Debugger022 committed Dec 1, 2023
1 parent 6d43a83 commit 1de2ffb
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion deploy/007-deploy-pool-lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre.network.config);
const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre);

await deploy("PoolLens", {
from: deployer,
Expand Down
2 changes: 1 addition & 1 deletion deploy/009-deploy-vtokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await getNamedAccounts();
const { tokensConfig, poolConfig, preconfiguredAddresses } = await getConfig(hre.network.name);

const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre.network.name);
const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre);

const accessControlManagerAddress = await toAddress(
preconfiguredAddresses.AccessControlManager || "AccessControlManager",
Expand Down
2 changes: 1 addition & 1 deletion deploy/010-deploy-reward-distributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const maxLoopsLimit = 100;

const { tokensConfig, poolConfig, preconfiguredAddresses } = await getConfig(hre.network.name);
const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre.network.name);
const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre);

const accessControlAddress = await toAddress(
preconfiguredAddresses.AccessControlManager || "AccessControlManager",
Expand Down
2 changes: 1 addition & 1 deletion deploy/014-riskfund-protocolshare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { tokensConfig, preconfiguredAddresses } = await getConfig(hre.network.name);
const usdt = await getUnderlyingToken("USDT", tokensConfig);

const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre.network.name);
const { isTimeBased, blocksPerYear } = getBlockOrTimestampBasedDeploymentInfo(hre);

const poolRegistry = await ethers.getContract("PoolRegistry");
const deployerSigner = ethers.provider.getSigner(deployer);
Expand Down
13 changes: 4 additions & 9 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,17 @@ const config: HardhatUserConfig = {
url: process.env.ARCHIVE_NODE_sepolia || "https://ethereum-sepolia.blockpi.network/v1/rpc/public",
chainId: 11155111,
live: true,
timeout: 1200000, // 20 minutes
timeout: 1200000, // 20 minutes,
isTimeBased: false,

Check failure on line 183 in hardhat.config.ts

View workflow job for this annotation

GitHub Actions / Deploy

Type '{ url: string; chainId: number; live: true; timeout: number; isTimeBased: false; accounts: string[]; }' is not assignable to type 'NetworkUserConfig | undefined'.
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [`0x${process.env.DEPLOYER_PRIVATE_KEY}`] : [],
},
ethereum: {
url: process.env.ARCHIVE_NODE_ethereum || "https://ethereum.blockpi.network/v1/rpc/public",
chainId: 1,
live: true,
timeout: 1200000, // 20 minutes
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [`0x${process.env.DEPLOYER_PRIVATE_KEY}`] : [],
},
sepolia: {
url: process.env.ARCHIVE_NODE_sepolia || "https://ethereum-sepolia.blockpi.network/v1/rpc/public",
chainId: 11155111,
live: true,
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [`0x${process.env.DEPLOYER_PRIVATE_KEY}`] : [],
timeout: 1200000, // 20 minutes,
isTimeBased: false,

Check failure on line 191 in hardhat.config.ts

View workflow job for this annotation

GitHub Actions / Deploy

Type '{ url: string; chainId: number; live: true; timeout: number; isTimeBased: false; accounts: string[]; }' is not assignable to type 'NetworkUserConfig | undefined'.
accounts: process.env.DEPLOYER_PRIVATE_KEY ? [`0x${process.env.DEPLOYER_PRIVATE_KEY}`] : [],
},
},
gasReporter: {
Expand Down
8 changes: 5 additions & 3 deletions helpers/deploymentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type DeploymentConfig = {

export type DeploymentInfo = {
isTimeBased: boolean;
blocksPerYear: string;
blocksPerYear: number;
};

export type TokenConfig = {
Expand Down Expand Up @@ -97,8 +97,9 @@ export enum InterestRateModels {

const ANY_CONTRACT = ethers.constants.AddressZero;

const BSC_BLOCKS_PER_YEAR = 10_512_000; // assuming a block is mined every 3 seconds
const ETH_BLOCKS_PER_YEAR = 2_252_571; // assuming a block is mined every 14 seconds
export const BSC_BLOCKS_PER_YEAR = 10_512_000; // assuming a block is mined every 3 seconds
export const ETH_BLOCKS_PER_YEAR = 2_252_571; // assuming a block is mined every 14 seconds
export const SECONDS_PER_YEAR = 31_536_000; // seconds per year

export type BlocksPerYear = {
[key: string]: number;
Expand All @@ -110,6 +111,7 @@ export const blocksPerYear: BlocksPerYear = {
bscmainnet: BSC_BLOCKS_PER_YEAR,
sepolia: ETH_BLOCKS_PER_YEAR,
ethereum: ETH_BLOCKS_PER_YEAR,
isTimeBased: SECONDS_PER_YEAR,
};

export const SEPOLIA_MULTISIG = "0x94fa6078b6b8a26f0b6edffbe6501b22a10470fb";
Expand Down
12 changes: 6 additions & 6 deletions helpers/deploymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
RewardConfig,
TokenConfig,
VTokenConfig,
blocksPerYear,
getTokenConfig,
} from "./deploymentConfig";

Expand Down Expand Up @@ -134,10 +135,9 @@ export const getUnregisteredRewardsDistributors = async (
);
};

export const getBlockOrTimestampBasedDeploymentInfo = (config: any): DeploymentInfo => {
const isTimeBased = config.isTimeBased;
if (isTimeBased) {
return { isTimeBased: true, blocksPerYear: "31536000" };
}
return { isTimeBased: false, blocksPerYear: "10512000" };
export const getBlockOrTimestampBasedDeploymentInfo = (hre: any): DeploymentInfo => {
const isTimeBased = hre.network.config.isTimeBased;
const blocksPerYearKey = isTimeBased ? "isTimeBased" : hre.network.name;

return { isTimeBased: isTimeBased, blocksPerYear: blocksPerYear[blocksPerYearKey] };
};
3 changes: 2 additions & 1 deletion tests/hardhat/JumpRateModelV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BigNumber from "bignumber.js";
import chai from "chai";
import { ethers } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../helpers/deploymentConfig";
import { convertToUnit } from "../../helpers/utils";
import { AccessControlManager, JumpRateModelV2 } from "../../typechain";
import { getDescription } from "./util/descriptionHelpers";
Expand All @@ -26,7 +27,7 @@ for (const isTimeBased of [false, true]) {
const jumpMultiplierPerYear = convertToUnit(2, 18);

const description = getDescription(isTimeBased);
const slotsPerYear = isTimeBased ? 31536000 : 10512000;
const slotsPerYear = isTimeBased ? SECONDS_PER_YEAR : BSC_BLOCKS_PER_YEAR;

describe(`${description}Jump rate model tests`, async () => {
const fixture = async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/hardhat/Lens/PoolLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BigNumberish, Signer } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";

import { blocksPerYear } from "../../../helpers/deploymentConfig";
import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../../helpers/deploymentConfig";
import {
AccessControlManager,
Beacon,
Expand Down Expand Up @@ -48,7 +48,7 @@ const assertVTokenMetadata = (vTokenMetadataActual: any, vTokenMetadataExpected:

for (const isTimeBased of [false, true]) {
const description = getDescription(isTimeBased);
const slotsPerYear = isTimeBased ? 31536000 : 10512000;
const slotsPerYear = isTimeBased ? SECONDS_PER_YEAR : BSC_BLOCKS_PER_YEAR;

describe(`${description}PoolLens`, async () => {
let poolRegistry: PoolRegistry;
Expand Down
5 changes: 3 additions & 2 deletions tests/hardhat/Lens/RewardsSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chai from "chai";
import { BigNumber, Signer } from "ethers";
import { ethers } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../../helpers/deploymentConfig";
import { convertToUnit } from "../../../helpers/utils";
import { Comptroller, MockToken, PoolLens, PoolLens__factory, RewardsDistributor, VToken } from "../../../typechain";
import { getDescription } from "../util/descriptionHelpers";
Expand All @@ -27,7 +28,7 @@ let poolLens: MockContract<PoolLens>;
let account: Signer;
let startBlock: number;
let isTimeBased = false; // for block based contracts
let blocksPerYear = 10512000; // for block based contracts
let blocksPerYear = BSC_BLOCKS_PER_YEAR; // for block based contracts

type RewardsFixtire = {
comptroller: FakeContract<Comptroller>;
Expand Down Expand Up @@ -163,7 +164,7 @@ const timeBasedRewardsFixture = async (): Promise<RewardsFixtire> => {
const poolLensFactory = await smock.mock<PoolLens__factory>("PoolLens");

isTimeBased = true;
blocksPerYear = 31536000;
blocksPerYear = SECONDS_PER_YEAR;
poolLens = await poolLensFactory.deploy(isTimeBased, blocksPerYear);

const startBlock = (await ethers.provider.getBlock("latest")).number;
Expand Down
8 changes: 0 additions & 8 deletions tests/hardhat/PoolRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ describe("PoolRegistry: Tests", function () {
initialExchangeRateMantissa: parseUnits("1", 18),
admin: owner.address,
beacon: vTokenBeacon,
isTimeBased: false,
blocksPerYear: 10512000,
});

await mockWBTC.faucet(INITIAL_SUPPLY);
Expand All @@ -169,8 +167,6 @@ describe("PoolRegistry: Tests", function () {
initialExchangeRateMantissa: parseUnits("1", 18),
admin: owner.address,
beacon: vTokenBeacon,
isTimeBased: false,
blocksPerYear: 10512000,
});

await mockDAI.faucet(INITIAL_SUPPLY);
Expand All @@ -193,8 +189,6 @@ describe("PoolRegistry: Tests", function () {
initialExchangeRateMantissa: parseUnits("1", 28), // underlying.decimals + 18 - vToken.decimals
admin: owner.address,
beacon: vTokenBeacon,
isTimeBased: false,
blocksPerYear: 10512000,
});

// Enter Markets
Expand Down Expand Up @@ -376,8 +370,6 @@ describe("PoolRegistry: Tests", function () {
initialExchangeRateMantissa: parseUnits("1", 28), // underlying.decimals + 18 - vToken.decimals
admin: user.address,
beacon: vTokenBeacon,
isTimeBased: false,
blocksPerYear: 10512000,
});

await feeToken.allocateTo(user.address, INITIAL_SUPPLY);
Expand Down
5 changes: 3 additions & 2 deletions tests/hardhat/Rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { expect } from "chai";
import { parseUnits } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../helpers/deploymentConfig";
import { convertToUnit } from "../../helpers/utils";
import {
AccessControlManager,
Expand Down Expand Up @@ -36,7 +37,7 @@ let xvs: MockToken;
let fakePriceOracle: FakeContract<ResilientOracleInterface>;
let fakeAccessControlManager: FakeContract<AccessControlManager>;
const maxLoopsLimit = 150;
let blocksPerYear = 10512000; // for block based contracts
let blocksPerYear = BSC_BLOCKS_PER_YEAR; // for block based contracts

async function rewardsFixture(isTimeBased: boolean) {
[root] = await ethers.getSigners();
Expand Down Expand Up @@ -98,7 +99,7 @@ async function rewardsFixture(isTimeBased: boolean) {
);

if (isTimeBased) {
blocksPerYear = 31536000;
blocksPerYear = SECONDS_PER_YEAR;
}

// Deploy VTokens
Expand Down
5 changes: 3 additions & 2 deletions tests/hardhat/Shortfall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { constants } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../helpers/deploymentConfig";
import { AddressOne, convertToUnit } from "../../helpers/utils";
import {
AccessControlManager,
Expand Down Expand Up @@ -48,7 +49,7 @@ let fakePriceOracle: FakeContract<ResilientOracleInterface>;
const riskFundBalance = "10000";
const minimumPoolBadDebt = "10000";
let isTimeBased = false; // for block based contracts
let blocksPerYear = 10512000; // for block based contracts
let blocksPerYear = BSC_BLOCKS_PER_YEAR; // for block based contracts
let poolAddress;

/**
Expand Down Expand Up @@ -182,7 +183,7 @@ async function shortfallFixture() {

async function timeBasedhortfallFixture() {
isTimeBased = true;
blocksPerYear = 31536000;
blocksPerYear = SECONDS_PER_YEAR;
const MockBUSD = await ethers.getContractFactory("MockToken");
mockBUSD = await MockBUSD.deploy("BUSD", "BUSD", 18);
await mockBUSD.faucet(convertToUnit(100000, 18));
Expand Down
3 changes: 2 additions & 1 deletion tests/hardhat/UpgradedVToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from "chai";
import { parseUnits } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../helpers/deploymentConfig";
import { convertToUnit } from "../../helpers/utils";
import {
AccessControlManager,
Expand All @@ -27,7 +28,7 @@ let fakeAccessControlManager: FakeContract<AccessControlManager>;

for (const isTimeBased of [false, true]) {
const description = getDescription(isTimeBased);
const slotsPerYear = isTimeBased ? 31536000 : 10512000;
const slotsPerYear = isTimeBased ? SECONDS_PER_YEAR : BSC_BLOCKS_PER_YEAR;

describe(`${description}UpgradedVToken: Tests`, function () {
/**
Expand Down
3 changes: 2 additions & 1 deletion tests/hardhat/WhitePaperInterestRateModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BigNumber from "bignumber.js";
import chai from "chai";
import { ethers } from "hardhat";

import { BSC_BLOCKS_PER_YEAR, SECONDS_PER_YEAR } from "../../helpers/deploymentConfig";
import { convertToUnit } from "../../helpers/utils";
import { WhitePaperInterestRateModel } from "../../typechain";
import { getDescription } from "./util/descriptionHelpers";
Expand All @@ -21,7 +22,7 @@ for (const isTimeBased of [false, true]) {
const baseRatePerYear = convertToUnit(2, 12);
const multiplierPerYear = convertToUnit(4, 14);
const description: string = getDescription(isTimeBased);
const slotsPerYear = isTimeBased ? 31536000 : 10512000;
const slotsPerYear = isTimeBased ? SECONDS_PER_YEAR : BSC_BLOCKS_PER_YEAR;

describe(`${description}White Paper interest rate model tests`, () => {
const fixture = async () => {
Expand Down
7 changes: 4 additions & 3 deletions tests/hardhat/util/TokenTestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BigNumber, BigNumberish, Signer } from "ethers";
import { parseUnits } from "ethers/lib/utils";
import { ethers, upgrades } from "hardhat";

import { BSC_BLOCKS_PER_YEAR } from "../../../helpers/deploymentConfig";
import {
AccessControlManager,
Comptroller,
Expand Down Expand Up @@ -74,7 +75,7 @@ export type AnyVTokenFactory = VTokenHarness__factory | VToken__factory;
export const deployVTokenBeacon = async <VTokenFactory extends AnyVTokenFactory = VToken__factory>(
{ kind }: { kind: string } = { kind: "VToken" },
isTimeBased: boolean = false,
blocksPerYear: BigNumberish = 10512000,
blocksPerYear: BigNumberish = BSC_BLOCKS_PER_YEAR,
): Promise<UpgradeableBeacon> => {
const VToken = await ethers.getContractFactory<VTokenFactory>(kind);
const vTokenBeacon = (await upgrades.deployBeacon(VToken, {
Expand Down Expand Up @@ -110,10 +111,10 @@ const deployVTokenDependencies = async <VTokenFactory extends AnyVTokenFactory =
(await deployVTokenBeacon<VTokenFactory>(
{ kind },
params.isTimeBased || false,
params.blocksPerYear || 10512000,
params.blocksPerYear || BSC_BLOCKS_PER_YEAR,
)),
isTimeBased: params.isTimeBased || false,
blocksPerYear: params.blocksPerYear || 10512000,
blocksPerYear: params.blocksPerYear || BSC_BLOCKS_PER_YEAR,
};
};

Expand Down

0 comments on commit 1de2ffb

Please sign in to comment.