Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,145 changes: 4,145 additions & 0 deletions simulations/vip-800/abi/Comptroller.json

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions simulations/vip-800/bscmainnet-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers } from "hardhat";
import { NETWORK_ADDRESSES } from "src/networkAddresses";
import {
expectEvents,
setMaxStalePeriodInBinanceOracle,
setMaxStalePeriodInChainlinkOracle,
setRedstonePrice,
} from "src/utils";
import { forking, testVip } from "src/vip-framework";

import { CORE_MARKETS } from "../../vips/vip-547/bscmainnet";
import { vip800 } from "../../vips/vip-800/bscmainnet";
import { EMODE_POOLS, vip800 as vip800_2 } from "../../vips/vip-800/bscmainnet-2";
import COMPTROLLER_ABI from "./abi/Comptroller.json";

const { bscmainnet } = NETWORK_ADDRESSES;

forking(76766086, async () => {
let comptroller: Contract;

before(async () => {
const provider = ethers.provider;
comptroller = new ethers.Contract(bscmainnet.UNITROLLER, COMPTROLLER_ABI, provider);

for (const market of CORE_MARKETS) {
// Call function with default feed = AddressZero (so it fetches from oracle.tokenConfigs)
await setMaxStalePeriodInChainlinkOracle(
bscmainnet.CHAINLINK_ORACLE,
market.underlying,
ethers.constants.AddressZero,
bscmainnet.NORMAL_TIMELOCK,
3153600000,
);

await setMaxStalePeriodInChainlinkOracle(
bscmainnet.REDSTONE_ORACLE,
market.underlying,
ethers.constants.AddressZero,
bscmainnet.NORMAL_TIMELOCK,
3153600000,
);

await setMaxStalePeriodInBinanceOracle(bscmainnet.BINANCE_ORACLE, market.symbol.slice(1), 315360000);
}

const THE = "0xF4C8E32EaDEC4BFe97E0F595AdD0f4450a863a11";
const THE_REDSTONE_FEED = "0xFB1267A29C0aa19daae4a483ea895862A69e4AA5";
await setRedstonePrice(bscmainnet.REDSTONE_ORACLE, THE, THE_REDSTONE_FEED, bscmainnet.NORMAL_TIMELOCK);

const TRX = "0xCE7de646e7208a4Ef112cb6ed5038FA6cC6b12e3";
const TRX_REDSTONE_FEED = "0xa17362dd9AD6d0aF646D7C8f8578fddbfc90B916";
await setRedstonePrice(bscmainnet.REDSTONE_ORACLE, TRX, TRX_REDSTONE_FEED, bscmainnet.NORMAL_TIMELOCK, 3153600000, {
tokenDecimals: 6,
});
});

describe("Pre-VIP behavior", async () => {
it("check new Emode PoolId does not exist", async () => {
expect(await comptroller.lastPoolId()).to.be.lessThan(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});
});

testVip("VIP-800 Part-1", await vip800(), {
callbackAfterExecution: async txResponse => {
await expectEvents(
txResponse,
[COMPTROLLER_ABI],
[
"NewCollateralFactor",
"NewLiquidationThreshold",
"NewLiquidationIncentive",
"BorrowAllowedUpdated",
"PoolCreated",
"PoolMarketInitialized",
"PoolFallbackStatusUpdated",
],
[21, 21, 21, 21, 7, 21, 7],
);
},
});

testVip("VIP-800 Part-2", await vip800_2(), {
callbackAfterExecution: async txResponse => {
await expectEvents(
txResponse,
[COMPTROLLER_ABI],
[
"NewCollateralFactor", // vMatic has 0 collateral factor, so no event for it
"NewLiquidationThreshold",
"NewLiquidationIncentive",
"BorrowAllowedUpdated",
"PoolCreated",
"PoolMarketInitialized",
"PoolFallbackStatusUpdated",
],
[17, 18, 18, 18, 6, 18, 6],
);
},
});

describe("Post-VIP behavior", async () => {
it("should update lastPoolId to the new pool", async () => {
expect(await comptroller.lastPoolId()).to.equals(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});

for (const EMODE_POOL of EMODE_POOLS) {
describe(`Emode Pool ${EMODE_POOL.label}`, async () => {
it("should set the newly created pool as active with correct label", async () => {
const newPool = await comptroller.pools(EMODE_POOL.id);
expect(newPool.label).to.equals(EMODE_POOL.label);
expect(newPool.isActive).to.equals(true);
expect(newPool.allowCorePoolFallback).to.equal(EMODE_POOL.allowCorePoolFallback);
});

it("should set the correct risk parameters to all pool markets", async () => {
for (const config of Object.values(EMODE_POOL.marketsConfig)) {
const marketData = await comptroller.poolMarkets(EMODE_POOL.id, config.address);
expect(marketData.marketPoolId).to.be.equal(EMODE_POOL.id);
expect(marketData.isListed).to.be.equal(true);
expect(marketData.collateralFactorMantissa).to.be.equal(config.collateralFactor);
expect(marketData.liquidationThresholdMantissa).to.be.equal(config.liquidationThreshold);
expect(marketData.liquidationIncentiveMantissa).to.be.equal(config.liquidationIncentive);
expect(marketData.isBorrowAllowed).to.be.equal(config.borrowAllowed);
}
});
});
}
});
});
96 changes: 96 additions & 0 deletions simulations/vip-800/bscmainnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers } from "hardhat";
import { NETWORK_ADDRESSES } from "src/networkAddresses";
import { expectEvents, setMaxStalePeriodInBinanceOracle, setMaxStalePeriodInChainlinkOracle } from "src/utils";
import { forking, testVip } from "src/vip-framework";

import { CORE_MARKETS } from "../../vips/vip-547/bscmainnet";
import { EMODE_POOLS, vip800 } from "../../vips/vip-800/bscmainnet";
import COMPTROLLER_ABI from "./abi/Comptroller.json";

const { bscmainnet } = NETWORK_ADDRESSES;

forking(76766086, async () => {
let comptroller: Contract;

before(async () => {
const provider = ethers.provider;
comptroller = new ethers.Contract(bscmainnet.UNITROLLER, COMPTROLLER_ABI, provider);

for (const market of CORE_MARKETS) {
// Call function with default feed = AddressZero (so it fetches from oracle.tokenConfigs)
await setMaxStalePeriodInChainlinkOracle(
bscmainnet.CHAINLINK_ORACLE,
market.underlying,
ethers.constants.AddressZero,
bscmainnet.NORMAL_TIMELOCK,
3153600000,
);

await setMaxStalePeriodInChainlinkOracle(
bscmainnet.REDSTONE_ORACLE,
market.underlying,
ethers.constants.AddressZero,
bscmainnet.NORMAL_TIMELOCK,
3153600000,
);

await setMaxStalePeriodInBinanceOracle(bscmainnet.BINANCE_ORACLE, market.symbol.slice(1), 315360000);
}
});

describe("Pre-VIP behavior", async () => {
it("check new Emode PoolId does not exist", async () => {
expect(await comptroller.lastPoolId()).to.be.lessThan(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});
});

testVip("VIP-800", await vip800(), {
callbackAfterExecution: async txResponse => {
await expectEvents(
txResponse,
[COMPTROLLER_ABI],
[
"NewCollateralFactor",
"NewLiquidationThreshold",
"NewLiquidationIncentive",
"BorrowAllowedUpdated",
"PoolCreated",
"PoolMarketInitialized",
"PoolFallbackStatusUpdated",
],
[21, 21, 21, 21, 7, 21, 7],
);
},
});

describe("Post-VIP behavior", async () => {
it("should update lastPoolId to the new pool", async () => {
expect(await comptroller.lastPoolId()).to.equals(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});

for (const EMODE_POOL of EMODE_POOLS) {
describe(`Emode Pool ${EMODE_POOL.label}`, async () => {
it("should set the newly created pool as active with correct label", async () => {
const newPool = await comptroller.pools(EMODE_POOL.id);
expect(newPool.label).to.equals(EMODE_POOL.label);
expect(newPool.isActive).to.equals(true);
expect(newPool.allowCorePoolFallback).to.equal(EMODE_POOL.allowCorePoolFallback);
});

it("should set the correct risk parameters to all pool markets", async () => {
for (const config of Object.values(EMODE_POOL.marketsConfig)) {
const marketData = await comptroller.poolMarkets(EMODE_POOL.id, config.address);
expect(marketData.marketPoolId).to.be.equal(EMODE_POOL.id);
expect(marketData.isListed).to.be.equal(true);
expect(marketData.collateralFactorMantissa).to.be.equal(config.collateralFactor);
expect(marketData.liquidationThresholdMantissa).to.be.equal(config.liquidationThreshold);
expect(marketData.liquidationIncentiveMantissa).to.be.equal(config.liquidationIncentive);
expect(marketData.isBorrowAllowed).to.be.equal(config.borrowAllowed);
}
});
});
}
});
});
117 changes: 117 additions & 0 deletions simulations/vip-800/bsctestnet-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers } from "hardhat";
import { NETWORK_ADDRESSES } from "src/networkAddresses";
import { expectEvents, setMaxStalePeriodInBinanceOracle, setMaxStalePeriodInChainlinkOracle } from "src/utils";
import { forking, testVip } from "src/vip-framework";

import { CORE_MARKETS } from "../../vips/vip-547/bsctestnet";
import { vip800 } from "../../vips/vip-800/bsctestnet";
import { EMODE_POOLS, vip800 as vip800Bsctestnet2 } from "../../vips/vip-800/bsctestnet-2";
import COMPTROLLER_ABI from "./abi/Comptroller.json";

const { bsctestnet } = NETWORK_ADDRESSES;

forking(85524987, async () => {
let comptroller: Contract;

before(async () => {
const provider = ethers.provider;
comptroller = new ethers.Contract(bsctestnet.UNITROLLER, COMPTROLLER_ABI, provider);

for (const market of CORE_MARKETS) {
// Call function with default feed = AddressZero (so it fetches from oracle.tokenConfigs)
await setMaxStalePeriodInChainlinkOracle(
NETWORK_ADDRESSES.bsctestnet.CHAINLINK_ORACLE,
market.asset,
ethers.constants.AddressZero,
NETWORK_ADDRESSES.bsctestnet.NORMAL_TIMELOCK,
315360000,
);

await setMaxStalePeriodInChainlinkOracle(
NETWORK_ADDRESSES.bsctestnet.REDSTONE_ORACLE,
market.asset,
ethers.constants.AddressZero,
NETWORK_ADDRESSES.bsctestnet.NORMAL_TIMELOCK,
315360000,
);
}
await setMaxStalePeriodInBinanceOracle(NETWORK_ADDRESSES.bsctestnet.BINANCE_ORACLE, "WBETH", 315360000);
await setMaxStalePeriodInBinanceOracle(NETWORK_ADDRESSES.bsctestnet.BINANCE_ORACLE, "TWT", 315360000);
await setMaxStalePeriodInBinanceOracle(NETWORK_ADDRESSES.bsctestnet.BINANCE_ORACLE, "lisUSD", 315360000);
});

describe("Pre-VIP behavior", async () => {
it("check new Emode PoolId does not exist", async () => {
expect(await comptroller.lastPoolId()).to.be.lessThan(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});
});

testVip("VIP-800 Part-1", await vip800(), {
callbackAfterExecution: async txResponse => {
await expectEvents(
txResponse,
[COMPTROLLER_ABI],
[
"NewCollateralFactor",
"NewLiquidationThreshold",
"NewLiquidationIncentive",
"BorrowAllowedUpdated",
"PoolCreated",
"PoolMarketInitialized",
"PoolFallbackStatusUpdated",
],
[18, 18, 18, 18, 6, 18, 6],
);
},
});

testVip("VIP-800 Part-2", await vip800Bsctestnet2(), {
callbackAfterExecution: async txResponse => {
await expectEvents(
txResponse,
[COMPTROLLER_ABI],
[
"NewCollateralFactor",
"NewLiquidationThreshold",
"NewLiquidationIncentive",
"BorrowAllowedUpdated",
"PoolCreated",
"PoolMarketInitialized",
"PoolFallbackStatusUpdated",
],
[6, 6, 6, 6, 2, 6, 2],
);
},
});

describe("Post-VIP behavior", async () => {
it("should update lastPoolId to the new pool", async () => {
expect(await comptroller.lastPoolId()).to.equals(EMODE_POOLS[EMODE_POOLS.length - 1].id);
});

for (const EMODE_POOL of EMODE_POOLS) {
describe(`Emode Pool ${EMODE_POOL.label}`, async () => {
it("should set the newly created pool as active with correct label", async () => {
const newPool = await comptroller.pools(EMODE_POOL.id);
expect(newPool.label).to.equals(EMODE_POOL.label);
expect(newPool.isActive).to.equals(true);
expect(newPool.allowCorePoolFallback).to.equal(EMODE_POOL.allowCorePoolFallback);
});

it("should set the correct risk parameters to all pool markets", async () => {
for (const config of Object.values(EMODE_POOL.marketsConfig)) {
const marketData = await comptroller.poolMarkets(EMODE_POOL.id, config.address);
expect(marketData.marketPoolId).to.be.equal(EMODE_POOL.id);
expect(marketData.isListed).to.be.equal(true);
expect(marketData.collateralFactorMantissa).to.be.equal(config.collateralFactor);
expect(marketData.liquidationThresholdMantissa).to.be.equal(config.liquidationThreshold);
expect(marketData.liquidationIncentiveMantissa).to.be.equal(config.liquidationIncentive);
expect(marketData.isBorrowAllowed).to.be.equal(config.borrowAllowed);
}
});
});
}
});
});
Loading