|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +// Gearbox Protocol. Generalized leverage for DeFi protocols |
| 3 | +// (c) Gearbox Foundation, 2023. |
| 4 | +pragma solidity ^0.8.17; |
| 5 | + |
| 6 | +import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; |
| 7 | + |
| 8 | +import {DataCompressorV2_10} from "../data/DataCompressor_2_1.sol"; |
| 9 | +import {DataCompressorV3_00} from "../data/DataCompressor_3_0.sol"; |
| 10 | +import {CreditAccountData, CreditManagerData, PoolData, TokenBalance, ContractAdapter} from "../data/Types.sol"; |
| 11 | + |
| 12 | +import "forge-std/console.sol"; |
| 13 | + |
| 14 | +address constant ap = 0x5BcB06c56e8F28da0b038a373199240ca3F5a2f4; |
| 15 | + |
| 16 | +contract DCTest { |
| 17 | + DataCompressorV2_10 public dc2; |
| 18 | + DataCompressorV3_00 public dc3; |
| 19 | + |
| 20 | + function setUp() public { |
| 21 | + dc2 = new DataCompressorV2_10(ap); |
| 22 | + dc3 = new DataCompressorV3_00(ap); |
| 23 | + } |
| 24 | + |
| 25 | + function _printPools(PoolData[] memory pools) internal view { |
| 26 | + uint256 len = pools.length; |
| 27 | + unchecked { |
| 28 | + for (uint256 i; i < len; ++i) { |
| 29 | + PoolData memory pool = pools[i]; |
| 30 | + console.log("\n\n"); |
| 31 | + console.log(IERC20Metadata(pool.underlying).symbol(), pool.addr); |
| 32 | + console.log("-------------------------------"); |
| 33 | + |
| 34 | + console.log("dieselToken: ", pool.dieselToken); |
| 35 | + /// |
| 36 | + console.log("linearCumulativeIndex: ", pool.linearCumulativeIndex); |
| 37 | + console.log("availableLiquidity: ", pool.availableLiquidity); |
| 38 | + console.log("expectedLiquidity: ", pool.expectedLiquidity); |
| 39 | + // |
| 40 | + console.log("totalBorrowed: ", pool.totalBorrowed); |
| 41 | + console.log("totalDebtLimit: ", pool.totalDebtLimit); |
| 42 | + // CreditManagerDebtParams[] creditManagerDebtParams; |
| 43 | + console.log("totalAssets: ", pool.totalAssets); |
| 44 | + console.log("totalSupply: ", pool.totalSupply); |
| 45 | + console.log("supplyRate", pool.supplyRate); |
| 46 | + console.log("baseInterestRate: ", pool.baseInterestRate); |
| 47 | + console.log("dieselRate_RAY: ", pool.dieselRate_RAY); |
| 48 | + console.log("withdrawFee", pool.withdrawFee); |
| 49 | + console.log("cumulativeIndex_RAY:", pool.cumulativeIndex_RAY); |
| 50 | + console.log("baseInterestIndexLU:", pool.baseInterestIndexLU); |
| 51 | + console.log("version: ", pool.version); |
| 52 | + // QuotaInfo[] quotas; |
| 53 | + // LinearModel lirm; |
| 54 | + console.log("isPaused", pool.isPaused); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + function _printCreditManagers(CreditManagerData[] memory cms) internal view { |
| 60 | + uint256 len = cms.length; |
| 61 | + unchecked { |
| 62 | + for (uint256 i; i < len; ++i) { |
| 63 | + CreditManagerData memory cm = cms[i]; |
| 64 | + console.log("\n\n"); |
| 65 | + console.log(IERC20Metadata(cm.underlying).symbol(), cm.addr); |
| 66 | + console.log("-------------------------------"); |
| 67 | + console.log("cfVersion: ", cm.cfVersion); |
| 68 | + console.log("creditFacace: ", cm.creditFacade); // V2 only: address of creditFacade |
| 69 | + console.log("creditConfigurator: ", cm.creditConfigurator); // V2 only: address of creditConfigurator |
| 70 | + console.log("pool: ", cm.pool); |
| 71 | + console.log("totalDebt: ", cm.totalDebt); |
| 72 | + console.log("totalDebtLimit: ", cm.totalDebtLimit); |
| 73 | + console.log("baseBorrowRate: ", cm.baseBorrowRate); |
| 74 | + console.log("minDebt: ", cm.minDebt); |
| 75 | + console.log("maxDebt: ", cm.maxDebt); |
| 76 | + console.log("availableToBorrow: ", cm.availableToBorrow); |
| 77 | + // address[] collateralTokens); |
| 78 | + // ContractAdapter[] adapters); |
| 79 | + // uint256[] liquidationThresholds); |
| 80 | + console.log("isDegenMode: ", cm.isDegenMode); // V2 only: true if contract is in Degen mode |
| 81 | + console.log("degenNFT: ", cm.degenNFT); // V2 only: degenNFT, address(0) if not in degen mode |
| 82 | + console.log("forbiddenTokenMask: ", cm.forbiddenTokenMask); // V2 only: mask which forbids some particular tokens |
| 83 | + console.log("maxEnabledTokensLength: ", cm.maxEnabledTokensLength); // V2 only: in V1 as many tokens as the CM can support (256) |
| 84 | + console.log("feeInterest: ", cm.feeInterest); // Interest fee protocol charges: fee = interest accrues * feeInterest |
| 85 | + console.log("feeLiquidation: ", cm.feeLiquidation); // Liquidation fee protocol charges: fee = totalValue * feeLiquidation |
| 86 | + console.log("liquidationDiscount: ", cm.liquidationDiscount); // Miltiplier to get amount which liquidator should pay: amount = totalValue * liquidationDiscount |
| 87 | + console.log("feeLiquidationExpired: ", cm.feeLiquidationExpired); // Liquidation fee protocol charges on expired accounts |
| 88 | + console.log("liquidationDiscountExpired: ", cm.liquidationDiscountExpired); // Multiplier for the amount the liquidator has to pay when closing an expired account |
| 89 | + // V3 Fileds |
| 90 | + // QuotaInfo[] quotas); |
| 91 | + // LinearModel lirm); |
| 92 | + console.log("sPaused: ", cm.isPaused); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + function test_dc_pools() public view { |
| 98 | + PoolData[] memory pools = dc2.getPoolsV1List(); |
| 99 | + console.log("V1 pools"); |
| 100 | + _printPools(pools); |
| 101 | + |
| 102 | + pools = dc3.getPoolsV3List(); |
| 103 | + console.log("\nV3 pools"); |
| 104 | + _printPools(pools); |
| 105 | + } |
| 106 | + |
| 107 | + function test_dc_credit_managers() public view { |
| 108 | + CreditManagerData[] memory cms = dc2.getCreditManagersV2List(); |
| 109 | + console.log("V2 credit managers"); |
| 110 | + _printCreditManagers(cms); |
| 111 | + |
| 112 | + cms = dc3.getCreditManagersV3List(); |
| 113 | + console.log("\n\nV3 credit managers"); |
| 114 | + _printCreditManagers(cms); |
| 115 | + } |
| 116 | +} |
0 commit comments