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

Protocol admin test #42

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions contracts/test/DevTesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ contract DevTesting is BaseTest {
usdcMarket = markets[1];
}

function testModePoolBorrowers() public debuggingOnly fork(MODE_MAINNET) {
emit log_named_array("borrowers", pool.getAllBorrowers());
}

function testModeLiquidationShortfall() public debuggingOnly fork(MODE_MAINNET) {
(
uint256 err,
uint256 collateralValue,
uint256 liquidity,
uint256 shortfall
) = pool.getAccountLiquidity(0xa75F9C8246f7269279bE4c969e7Bc6Eb619cC204);

emit log_named_uint("err", err);
emit log_named_uint("collateralValue", collateralValue);
emit log_named_uint("liquidity", liquidity);
emit log_named_uint("shortfall", shortfall);
}

function testMarketAddress() public debuggingOnly fork(MODE_MAINNET) {
ICErc20[] memory markets = pool.getAllMarkets();
emit log_named_uint("markets total", markets.length);
Expand Down
94 changes: 94 additions & 0 deletions contracts/test/ProtocolAdminTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import { BaseTest } from "./config/BaseTest.t.sol";
import { SafeOwnableUpgradeable } from "../ionic/SafeOwnableUpgradeable.sol";
import { MasterPriceOracle } from "../oracles/MasterPriceOracle.sol";
import { PoolDirectory } from "../PoolDirectory.sol";
import { IonicComptroller } from "../compound/ComptrollerInterface.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

contract ProtocolAdminTest is BaseTest {
address public expectedAdmin;

function afterForkSetUp() internal virtual override {
}

function _checkIfAdmin(address addr) internal {
assertEq(addr, expectedAdmin, "not the same admin address");
}

function _checkSafeOwnableAdmin(string memory contractName) internal {
SafeOwnableUpgradeable ownable = SafeOwnableUpgradeable(ap.getAddress(contractName));
if (address(ownable) != address(0)) {
_checkIfAdmin(ownable.owner());
}
}

function _checkOwnableAdmin(string memory contractName) internal {
Ownable ownable = Ownable(ap.getAddress(contractName));
if (address(ownable) != address(0)) {
_checkIfAdmin(ownable.owner());
}
}

function testModeProtocolAdmin() public fork(MODE_MAINNET) {
expectedAdmin = 0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2; // gnosis safe multisig contract
_testProtocolAdmin();
}

function _testProtocolAdmin() internal {
//expectedAdmin = ap.owner();
address apDeployer = ap.getAddress("deployer");
_checkIfAdmin(apDeployer);

// safe ownable
_checkSafeOwnableAdmin("FeeDistributor");
_checkSafeOwnableAdmin("PoolDirectory");
_checkSafeOwnableAdmin("OptimizedVaultsRegistry");
_checkSafeOwnableAdmin("AnkrCertificateTokenPriceOracle");
_checkSafeOwnableAdmin("BalancerLpLinearPoolPriceOracle");
_checkSafeOwnableAdmin("BalancerLpStablePoolPriceOracle");
_checkSafeOwnableAdmin("BalancerLpTokenPriceOracle");
_checkSafeOwnableAdmin("BalancerLpTokenPriceOracleNTokens");
_checkSafeOwnableAdmin("BalancerRateProviderOracle");
_checkSafeOwnableAdmin("BNBxPriceOracle");
_checkSafeOwnableAdmin("CurveLpTokenPriceOracleNoRegistry");
_checkSafeOwnableAdmin("CurveV2LpTokenPriceOracleNoRegistry");
_checkSafeOwnableAdmin("CurveV2PriceOracle");
_checkSafeOwnableAdmin("ERC4626Oracle");
_checkSafeOwnableAdmin("GammaPoolUniswapV3PriceOracle");
_checkSafeOwnableAdmin("GammaPoolAlgebraPriceOracle");
_checkSafeOwnableAdmin("PythPriceOracle");
_checkSafeOwnableAdmin("SimplePriceOracle");
_checkSafeOwnableAdmin("SolidlyPriceOracle");
_checkSafeOwnableAdmin("StkBNBPriceOracle");
_checkSafeOwnableAdmin("WSTEthPriceOracle");
_checkSafeOwnableAdmin("NativeUSDPriceOracle");

// ownable 2 step
_checkSafeOwnableAdmin("LiquidatorsRegistry");
_checkSafeOwnableAdmin("LeveredPositionFactory");
_checkSafeOwnableAdmin("OptimizedAPRVault");

_checkOwnableAdmin("DefaultProxyAdmin");
_checkOwnableAdmin("DiaPriceOracle");
_checkOwnableAdmin("PoolDirectory");

assertEq(MasterPriceOracle(ap.getAddress("MasterPriceOracle")).admin(), expectedAdmin, "mpo admin incorrect");

// check all the pool admins and the flywheels owners
PoolDirectory poolDir = PoolDirectory(ap.getAddress("PoolDirectory"));
PoolDirectory.Pool[] memory pools = poolDir.getAllPools();
for (uint256 i = 0; i < pools.length; i++) {
IonicComptroller pool = IonicComptroller(pools[i].comptroller);
assertEq(pool.admin(), expectedAdmin, "pool admin does not match");

address[] memory flywheels = pool.getRewardsDistributors();
for (uint256 j = 0; j < flywheels.length; j++) {
assertEq(Ownable(flywheels[j]).owner(), expectedAdmin, "flywheel owner not the admin");
}
}
}
}