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

Commit

Permalink
Merge pull request #79 from ionicprotocol/feat/adrastia-prudentia-caps
Browse files Browse the repository at this point in the history
Feat/adrastia prudentia caps
  • Loading branch information
rhlsthrm authored Aug 7, 2024
2 parents a59a438 + 5bbaaaa commit 4d5421c
Show file tree
Hide file tree
Showing 30 changed files with 9,447 additions and 666 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
[submodule "lib/ops"]
path = lib/ops
url = https://github.com/gelatodigital/ops
[submodule "lib/adrastia-periphery"]
path = lib/adrastia-periphery
url = https://github.com/adrastia-oracle/adrastia-periphery
[submodule "lib/flywheel-v2"]
path = lib/flywheel-v2
url = https://github.com/ionicprotocol/flywheel-v2
59 changes: 55 additions & 4 deletions chainDeploy/helpers/irms.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import { Hash, parseEther } from "viem";
import { Address, Hash, parseEther } from "viem";
import { mode } from "viem/chains";

import { assetSymbols } from "../../../monorepo/packages/types";
import assets from "../../../monorepo/packages/chains/src/mode/assets";
import { IrmDeployFnParams } from "../types";

import { underlying } from "./utils";

const PRUDENTIA_RATE_CONTROLLER_MODE = "0xC40753877CfeF6f50E13695395c58357505719F8";

type PrudentiaConfig = {
blocksPerYear: number;
underlying: Address;
rateController: Address;
symbol: string;
};

const prudentiaParams: Record<number, PrudentiaConfig[]> = {
[mode.id]: [
{
symbol: assetSymbols.USDC,
blocksPerYear: 15768000,
underlying: underlying(assets, assetSymbols.USDC),
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
},
{
symbol: assetSymbols.USDT,
blocksPerYear: 15768000,
underlying: underlying(assets, assetSymbols.USDT),
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
},
{
symbol: assetSymbols.WETH,
blocksPerYear: 15768000,
underlying: underlying(assets, assetSymbols.WETH),
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
}
]
};

export const deployIRMs = async ({
viem,
getNamedAccounts,
deployConfig,
deployments,
deployConfig
getNamedAccounts,
viem,
chainId
}: IrmDeployFnParams): Promise<void> => {
const publicClient = await viem.getPublicClient();
const { deployer } = await getNamedAccounts();
Expand All @@ -23,4 +62,16 @@ export const deployIRMs = async ({
});
if (jrm.transactionHash) await publicClient.waitForTransactionReceipt({ hash: jrm.transactionHash as Hash });
console.log("JumpRateModel: ", jrm.address);

const prudentiaConfig = prudentiaParams[+chainId] ?? [];
for (const config of prudentiaConfig) {
const irm = await deployments.deploy(`PrudentiaInterestRateModel_${config.symbol}`, {
contract: "PrudentiaInterestRateModel",
from: deployer,
args: [config.blocksPerYear, config.underlying, config.rateController],
log: true
});
if (irm.transactionHash) await publicClient.waitForTransactionReceipt({ hash: irm.transactionHash as Hash });
console.log("PrudentiaInterestRateModel: ", config.symbol, irm.address);
}
};
1 change: 1 addition & 0 deletions chainDeploy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export type LiquidatorsRegistryConfigFnParams = {

export type IrmDeployFnParams = ChainDeployFnParams & {
deployConfig: ChainDeployConfig;
chainId: number;
};

export type ChainlinkDeployFnParams = ChainDeployFnParams & {
Expand Down
109 changes: 36 additions & 73 deletions contracts/PoolLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ contract PoolLens is Initializable {
*/
function getPublicPoolsWithData()
external
returns (
uint256[] memory,
PoolDirectory.Pool[] memory,
IonicPoolData[] memory,
bool[] memory
)
returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory)
{
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPools();
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(publicPools);
Expand All @@ -127,15 +122,9 @@ contract PoolLens is Initializable {
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
*/
function getPublicPoolsByVerificationWithData(bool whitelistedAdmin)
external
returns (
uint256[] memory,
PoolDirectory.Pool[] memory,
IonicPoolData[] memory,
bool[] memory
)
{
function getPublicPoolsByVerificationWithData(
bool whitelistedAdmin
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPoolsByVerification(
whitelistedAdmin
);
Expand All @@ -148,15 +137,9 @@ contract PoolLens is Initializable {
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
*/
function getPoolsByAccountWithData(address account)
external
returns (
uint256[] memory,
PoolDirectory.Pool[] memory,
IonicPoolData[] memory,
bool[] memory
)
{
function getPoolsByAccountWithData(
address account
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = directory.getPoolsByAccount(account);
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
return (indexes, accountPools, data, errored);
Expand All @@ -167,15 +150,9 @@ contract PoolLens is Initializable {
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
*/
function getPoolsOIonicrWithData(address user)
external
returns (
uint256[] memory,
PoolDirectory.Pool[] memory,
IonicPoolData[] memory,
bool[] memory
)
{
function getPoolsOIonicrWithData(
address user
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
(uint256[] memory indexes, PoolDirectory.Pool[] memory userPools) = directory.getPoolsOfUser(user);
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(userPools);
return (indexes, userPools, data, errored);
Expand Down Expand Up @@ -210,16 +187,9 @@ contract PoolLens is Initializable {
/**
* @notice Returns total supply balance (in ETH), total borrow balance (in ETH), underlying token addresses, and underlying token symbols of a Ionic pool.
*/
function getPoolSummary(IonicComptroller comptroller)
external
returns (
uint256,
uint256,
address[] memory,
string[] memory,
bool
)
{
function getPoolSummary(
IonicComptroller comptroller
) external returns (uint256, uint256, address[] memory, string[] memory, bool) {
uint256 totalBorrow = 0;
uint256 totalSupply = 0;
ICErc20[] memory cTokens = comptroller.getAllMarkets();
Expand Down Expand Up @@ -359,7 +329,10 @@ contract PoolLens is Initializable {
return (detailedAssets);
}

function getBorrowCapsPerCollateral(ICErc20 borrowedAsset, IonicComptroller comptroller)
function getBorrowCapsPerCollateral(
ICErc20 borrowedAsset,
IonicComptroller comptroller
)
internal
view
returns (
Expand Down Expand Up @@ -448,7 +421,7 @@ contract PoolLens is Initializable {
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
for (uint256 i = 0; i < poolMarkets.length; i++) {
assets[i] = address(poolMarkets[i]);
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
}

return (assets, supplyCapsPerAsset);
Expand All @@ -458,23 +431,17 @@ contract PoolLens is Initializable {
* @notice returns the total supply cap for each asset in the pool and the total non-whitelist supplied assets
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
*/
function getSupplyCapsDataForPool(IonicComptroller comptroller)
public
view
returns (
address[] memory,
uint256[] memory,
uint256[] memory
)
{
function getSupplyCapsDataForPool(
IonicComptroller comptroller
) public view returns (address[] memory, uint256[] memory, uint256[] memory) {
ICErc20[] memory poolMarkets = comptroller.getAllMarkets();

address[] memory assets = new address[](poolMarkets.length);
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
uint256[] memory nonWhitelistedTotalSupply = new uint256[](poolMarkets.length);
for (uint256 i = 0; i < poolMarkets.length; i++) {
assets[i] = address(poolMarkets[i]);
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
uint256 assetTotalSupplied = poolMarkets[i].getTotalUnderlyingSupplied();
uint256 whitelistedSuppliersSupply = comptroller.getWhitelistedSuppliersSupply(assets[i]);
if (whitelistedSuppliersSupply >= assetTotalSupplied) nonWhitelistedTotalSupply[i] = 0;
Expand All @@ -488,7 +455,9 @@ contract PoolLens is Initializable {
* @notice returns the total borrow cap and the per collateral borrowing cap/blacklist for the asset
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
*/
function getBorrowCapsForAsset(ICErc20 asset)
function getBorrowCapsForAsset(
ICErc20 asset
)
public
view
returns (
Expand All @@ -500,14 +469,16 @@ contract PoolLens is Initializable {
{
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
totalBorrowCap = comptroller.borrowCaps(address(asset));
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
}

/**
* @notice returns the total borrow cap, the per collateral borrowing cap/blacklist for the asset and the total non-whitelist borrows
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
*/
function getBorrowCapsDataForAsset(ICErc20 asset)
function getBorrowCapsDataForAsset(
ICErc20 asset
)
public
view
returns (
Expand All @@ -520,7 +491,7 @@ contract PoolLens is Initializable {
{
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
totalBorrowCap = comptroller.borrowCaps(address(asset));
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
uint256 totalBorrows = asset.totalBorrowsCurrent();
uint256 whitelistedBorrowersBorrows = comptroller.getWhitelistedBorrowersBorrows(address(asset));
if (whitelistedBorrowersBorrows >= totalBorrows) nonWhitelistedTotalBorrows = 0;
Expand All @@ -532,11 +503,9 @@ contract PoolLens is Initializable {
* Note that the whitelist does not have to be enforced.
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
*/
function getWhitelistedPoolsByAccount(address account)
public
view
returns (uint256[] memory, PoolDirectory.Pool[] memory)
{
function getWhitelistedPoolsByAccount(
address account
) public view returns (uint256[] memory, PoolDirectory.Pool[] memory) {
(, PoolDirectory.Pool[] memory pools) = directory.getActivePools();
uint256 arrayLength = 0;

Expand Down Expand Up @@ -569,15 +538,9 @@ contract PoolLens is Initializable {
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
*/
function getWhitelistedPoolsByAccountWithData(address account)
external
returns (
uint256[] memory,
PoolDirectory.Pool[] memory,
IonicPoolData[] memory,
bool[] memory
)
{
function getWhitelistedPoolsByAccountWithData(
address account
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = getWhitelistedPoolsByAccount(account);
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
return (indexes, accountPools, data, errored);
Expand Down
10 changes: 10 additions & 0 deletions contracts/adrastia/PrudentiaLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;

library PrudentiaLib {
struct PrudentiaConfig {
address controller; // Adrastia Prudentia controller address
uint8 offset; // Offset for delayed rate activation
int8 decimalShift; // Positive values scale the rate up (in powers of 10), negative values scale the rate down
}
}
Loading

0 comments on commit 4d5421c

Please sign in to comment.