Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm committed Mar 20, 2024
1 parent a7ff5c5 commit 71985f6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 12 deletions.
120 changes: 113 additions & 7 deletions contracts/test/DevTesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import {MasterPriceOracle} from "../oracles/MasterPriceOracle.sol";
import {BasePriceOracle} from "../oracles/BasePriceOracle.sol";
import {PoolLens} from "../PoolLens.sol";
import {PoolLensSecondary} from "../PoolLensSecondary.sol";
import {JumpRateModel} from "../compound/JumpRateModel.sol";

contract DevTesting is BaseTest {
IonicComptroller pool = IonicComptroller(0xFB3323E24743Caf4ADD0fDCCFB268565c0685556);
PoolLensSecondary lens2 = PoolLensSecondary(0x7Ea7BB80F3bBEE9b52e6Ed3775bA06C9C80D4154);
PoolLens lens = PoolLens(0x431C87E08e2636733a945D742d25Ba77577ED480);

address deployer = 0x1155b614971f16758C92c4890eD338C9e3ede6b7;
address multisig = 0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2;

ICErc20 wethMarket;
ICErc20 usdcMarket;
ICErc20 usdtMarket;
Expand Down Expand Up @@ -80,11 +83,28 @@ contract DevTesting is BaseTest {
emit log_named_uint("hf", hf);
}

function testModeMaxBorrow() public debuggingOnly fork(MODE_MAINNET) {
address user = 0x5A9e792143bf2708b4765C144451dCa54f559a19;
uint256 maxBorrow = pool.getMaxRedeemOrBorrow(user, usdcMarket, true);
function testModeUsdcBorrowCaps() public debuggingOnly fork(MODE_MAINNET) {
_testModeBorrowCaps(usdcMarket);
}

function testModeUsdtBorrowCaps() public debuggingOnly fork(MODE_MAINNET) {
_testModeBorrowCaps(usdtMarket);
}

function testModeWethBorrowCaps() public debuggingOnly fork(MODE_MAINNET) {
_testModeBorrowCaps(wethMarket);
wethMarket.accrueInterest();
_testModeBorrowCaps(wethMarket);
}

function _testModeBorrowCaps(ICErc20 market) internal {
uint256 borrowCapUsdc = pool.borrowCaps(address(market));
uint256 totalBorrowsCurrent = market.totalBorrowsCurrent();

emit log_named_uint("max borrow", maxBorrow);
uint256 wethBorrowAmount = 154753148031252;
console.log("borrowCapUsdc %e", borrowCapUsdc);
console.log("totalBorrowsCurrent %e", totalBorrowsCurrent);
console.log("new totalBorrowsCurrent %e", totalBorrowsCurrent + wethBorrowAmount);
}

function testMarketMember() public debuggingOnly fork(MODE_MAINNET) {
Expand Down Expand Up @@ -154,13 +174,45 @@ contract DevTesting is BaseTest {
}

function testAssetAsCollateralCap() public debuggingOnly fork(MODE_MAINNET) {
pool.getAssetAsCollateralValueCap(wethMarket, usdcMarket, false, deployer);
address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5;
address ezEthWhale = 0xd3B02d999C681BD8B75F340FA7e078cE9097bF23;

vm.startPrank(multisig);
uint256 errCode = pool._deployMarket(
1, //delegateType
abi.encode(
MODE_EZETH,
address(pool),
ap.getAddress("FeeDistributor"),
0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode
"Ionic Renzo Restaked ETH",
"ionezETH",
0.1e18,
0.1e18
),
"",
0.7e18
);
vm.stopPrank();
require(errCode == 0, "error deploying market");

ICErc20[] memory markets = pool.getAllMarkets();
ICErc20 ezEthMarket = markets[markets.length - 1];

// uint256 cap = pool.getAssetAsCollateralValueCap(ezEthMarket, usdcMarket, false, deployer);
uint256 cap = pool.supplyCaps(address(ezEthMarket));
require(cap == 0, "non-zero cap");

vm.startPrank(ezEthWhale);
ERC20(MODE_EZETH).approve(address(ezEthMarket), 1e36);
errCode = ezEthMarket.mint(1e18);
require(errCode == 0, "should be unable to supply");
}

function testRegisterSFS() public debuggingOnly fork(MODE_MAINNET) {
emit log_named_address("pool admin", pool.admin());

vm.startPrank(0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2);
vm.startPrank(multisig);
pool.registerInSFS();

ICErc20[] memory markets = pool.getAllMarkets();
Expand All @@ -183,11 +235,29 @@ contract DevTesting is BaseTest {
vm.stopPrank();
}

function testModeBorrowRate() public fork(MODE_MAINNET) {
//ICErc20[] memory markets = pool.getAllMarkets();
ICErc20 ezEthMarket = ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857);

IonicComptroller pool = ezEthMarket.comptroller();
vm.prank(pool.admin());
ezEthMarket._setInterestRateModel(JumpRateModel(0x413aD59b80b1632988d478115a466bdF9B26743a));

JumpRateModel discRateModel = JumpRateModel(ezEthMarket.interestRateModel());

uint256 borrows = 200e18;
uint256 cash = 5000e18 - borrows;
uint256 reserves = 1e18;
uint256 rate = discRateModel.getBorrowRate(cash, borrows, reserves);

emit log_named_uint("rate per year %e", rate * discRateModel.blocksPerYear());
}

function testModeFetchBorrowers() public fork(MODE_MAINNET) {
// address[] memory borrowers = pool.getAllBorrowers();
// emit log_named_uint("borrowers.len", borrowers.length);

upgradePool();
//upgradePool();

(uint256 totalPages, address[] memory borrowersPage) = pool.getPaginatedBorrowers(1, 0);

Expand Down Expand Up @@ -221,6 +291,42 @@ contract DevTesting is BaseTest {
require(usdcMarket.borrow(5e6) == 0, "can't borrow");
}

function testModeDeployMarket() public debuggingOnly fork(MODE_MAINNET) {
address MODE_WEETH = 0x028227c4dd1e5419d11Bb6fa6e661920c519D4F5;
address weEthWhale = 0x6e55a90772B92f17f87Be04F9562f3faafd0cc38;

vm.startPrank(pool.admin());
uint256 errCode = pool._deployMarket(
1, //delegateType
abi.encode(
MODE_WEETH,
address(pool),
ap.getAddress("FeeDistributor"),
0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode
"Ionic Wrapped eETH",
"ionweETH",
0.1e18,
0.1e18
),
"",
0.7e18
);
vm.stopPrank();
require(errCode == 0, "error deploying market");

ICErc20[] memory markets = pool.getAllMarkets();
ICErc20 weEthMarket = markets[markets.length - 1];

// uint256 cap = pool.getAssetAsCollateralValueCap(weEthMarket, usdcMarket, false, deployer);
uint256 cap = pool.supplyCaps(address(weEthMarket));
require(cap == 0, "non-zero cap");

vm.startPrank(weEthWhale);
ERC20(MODE_WEETH).approve(address(weEthMarket), 1e36);
errCode = weEthMarket.mint(0.01e18);
require(errCode == 0, "should be unable to supply");
}

function testModeUpdateOracle() public debuggingOnly fork(MODE_MAINNET) {
BasePriceOracle pyth = BasePriceOracle(0x52Ee6E740C1785412e51A381B0d87fb1692a7b23);
MasterPriceOracle mpo = MasterPriceOracle(ap.getAddress("MasterPriceOracle"));
Expand Down
10 changes: 5 additions & 5 deletions contracts/test/PoolLensTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ contract PoolLensTest is BaseTest {

function testModeFPL() public debuggingOnly fork(MODE_MAINNET) {
IonicComptroller pool = IonicComptroller(0xFB3323E24743Caf4ADD0fDCCFB268565c0685556);
// PoolLens fpl = PoolLens(0x611a68618412c2e15A36e3e59C0b979746d87AB8);
// PoolLens.PoolAsset[] memory datas = fpl.getPoolAssetsWithData(pool);
//
// emit log_named_uint("ionicFee", datas[0].ionicFee);
// emit log_named_uint("adminFee", datas[0].adminFee);
PoolLens fpl = PoolLens(0x611a68618412c2e15A36e3e59C0b979746d87AB8);
PoolLens.PoolAsset[] memory datas = fpl.getPoolAssetsWithData(pool);

emit log_named_uint("ionicFee", datas[0].ionicFee);
emit log_named_uint("adminFee", datas[0].adminFee);

ICErc20[] memory markets = pool.getAllMarkets();

Expand Down
1 change: 1 addition & 0 deletions contracts/test/config/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity >=0.8.0;

import "forge-std/Vm.sol";
import "forge-std/Test.sol";
import "forge-std/console.sol";

import { AddressesProvider } from "../../ionic/AddressesProvider.sol";

Expand Down
9 changes: 9 additions & 0 deletions contracts/test/oracles/RedstoneAdapterOracleTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@ pragma solidity >=0.8.0;

import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import { MasterPriceOracle } from "../../oracles/MasterPriceOracle.sol";
import { RedstoneAdapterPriceOracle } from "../../oracles/default/RedstoneAdapterPriceOracle.sol";

import { BaseTest } from "../config/BaseTest.t.sol";

contract RedstoneAdapterOracleTest is BaseTest {
MasterPriceOracle public mpo;
RedstoneAdapterPriceOracle public oracle;
address public redstoneOracleAddress;
address MODE_USDC = 0xd988097fb8612cc24eeC14542bC03424c656005f;
address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5;
address MODE_WBTC = 0xcDd475325D6F564d27247D1DddBb0DAc6fA0a5CF;
address MODE_WEETH = 0x028227c4dd1e5419d11Bb6fa6e661920c519D4F5;

function afterForkSetUp() internal override {
if (block.chainid == MODE_MAINNET) {
redstoneOracleAddress = 0x7C1DAAE7BB0688C9bfE3A918A4224041c7177256;
}

oracle = new RedstoneAdapterPriceOracle(redstoneOracleAddress);
mpo = MasterPriceOracle(ap.getAddress("MasterPriceOracle"));
}

function testPrintPricesMode() public fork(MODE_MAINNET) {
emit log_named_uint("ezETH price (18 dec)", oracle.price(MODE_EZETH));
emit log_named_uint("WBTC price (8 dec)", oracle.price(MODE_WBTC));
emit log_named_uint("weETH price (18 dec)", oracle.price(MODE_WEETH));
}

function testPrintMpoPricesMode() public fork(MODE_MAINNET) {
emit log_named_uint("weETH price (18 dec)", mpo.price(MODE_WEETH));
}
}

0 comments on commit 71985f6

Please sign in to comment.