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

Commit 4d5421c

Browse files
authored
Merge pull request #79 from ionicprotocol/feat/adrastia-prudentia-caps
Feat/adrastia prudentia caps
2 parents a59a438 + 5bbaaaa commit 4d5421c

30 files changed

+9447
-666
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
[submodule "lib/ops"]
2323
path = lib/ops
2424
url = https://github.com/gelatodigital/ops
25+
[submodule "lib/adrastia-periphery"]
26+
path = lib/adrastia-periphery
27+
url = https://github.com/adrastia-oracle/adrastia-periphery
2528
[submodule "lib/flywheel-v2"]
2629
path = lib/flywheel-v2
2730
url = https://github.com/ionicprotocol/flywheel-v2

chainDeploy/helpers/irms.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1-
import { Hash, parseEther } from "viem";
1+
import { Address, Hash, parseEther } from "viem";
2+
import { mode } from "viem/chains";
3+
4+
import { assetSymbols } from "../../../monorepo/packages/types";
5+
import assets from "../../../monorepo/packages/chains/src/mode/assets";
26
import { IrmDeployFnParams } from "../types";
37

8+
import { underlying } from "./utils";
9+
10+
const PRUDENTIA_RATE_CONTROLLER_MODE = "0xC40753877CfeF6f50E13695395c58357505719F8";
11+
12+
type PrudentiaConfig = {
13+
blocksPerYear: number;
14+
underlying: Address;
15+
rateController: Address;
16+
symbol: string;
17+
};
18+
19+
const prudentiaParams: Record<number, PrudentiaConfig[]> = {
20+
[mode.id]: [
21+
{
22+
symbol: assetSymbols.USDC,
23+
blocksPerYear: 15768000,
24+
underlying: underlying(assets, assetSymbols.USDC),
25+
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
26+
},
27+
{
28+
symbol: assetSymbols.USDT,
29+
blocksPerYear: 15768000,
30+
underlying: underlying(assets, assetSymbols.USDT),
31+
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
32+
},
33+
{
34+
symbol: assetSymbols.WETH,
35+
blocksPerYear: 15768000,
36+
underlying: underlying(assets, assetSymbols.WETH),
37+
rateController: PRUDENTIA_RATE_CONTROLLER_MODE
38+
}
39+
]
40+
};
41+
442
export const deployIRMs = async ({
5-
viem,
6-
getNamedAccounts,
43+
deployConfig,
744
deployments,
8-
deployConfig
45+
getNamedAccounts,
46+
viem,
47+
chainId
948
}: IrmDeployFnParams): Promise<void> => {
1049
const publicClient = await viem.getPublicClient();
1150
const { deployer } = await getNamedAccounts();
@@ -23,4 +62,16 @@ export const deployIRMs = async ({
2362
});
2463
if (jrm.transactionHash) await publicClient.waitForTransactionReceipt({ hash: jrm.transactionHash as Hash });
2564
console.log("JumpRateModel: ", jrm.address);
65+
66+
const prudentiaConfig = prudentiaParams[+chainId] ?? [];
67+
for (const config of prudentiaConfig) {
68+
const irm = await deployments.deploy(`PrudentiaInterestRateModel_${config.symbol}`, {
69+
contract: "PrudentiaInterestRateModel",
70+
from: deployer,
71+
args: [config.blocksPerYear, config.underlying, config.rateController],
72+
log: true
73+
});
74+
if (irm.transactionHash) await publicClient.waitForTransactionReceipt({ hash: irm.transactionHash as Hash });
75+
console.log("PrudentiaInterestRateModel: ", config.symbol, irm.address);
76+
}
2677
};

chainDeploy/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export type LiquidatorsRegistryConfigFnParams = {
161161

162162
export type IrmDeployFnParams = ChainDeployFnParams & {
163163
deployConfig: ChainDeployConfig;
164+
chainId: number;
164165
};
165166

166167
export type ChainlinkDeployFnParams = ChainDeployFnParams & {

contracts/PoolLens.sol

Lines changed: 36 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ contract PoolLens is Initializable {
110110
*/
111111
function getPublicPoolsWithData()
112112
external
113-
returns (
114-
uint256[] memory,
115-
PoolDirectory.Pool[] memory,
116-
IonicPoolData[] memory,
117-
bool[] memory
118-
)
113+
returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory)
119114
{
120115
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPools();
121116
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(publicPools);
@@ -127,15 +122,9 @@ contract PoolLens is Initializable {
127122
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
128123
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
129124
*/
130-
function getPublicPoolsByVerificationWithData(bool whitelistedAdmin)
131-
external
132-
returns (
133-
uint256[] memory,
134-
PoolDirectory.Pool[] memory,
135-
IonicPoolData[] memory,
136-
bool[] memory
137-
)
138-
{
125+
function getPublicPoolsByVerificationWithData(
126+
bool whitelistedAdmin
127+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
139128
(uint256[] memory indexes, PoolDirectory.Pool[] memory publicPools) = directory.getPublicPoolsByVerification(
140129
whitelistedAdmin
141130
);
@@ -148,15 +137,9 @@ contract PoolLens is Initializable {
148137
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
149138
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
150139
*/
151-
function getPoolsByAccountWithData(address account)
152-
external
153-
returns (
154-
uint256[] memory,
155-
PoolDirectory.Pool[] memory,
156-
IonicPoolData[] memory,
157-
bool[] memory
158-
)
159-
{
140+
function getPoolsByAccountWithData(
141+
address account
142+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
160143
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = directory.getPoolsByAccount(account);
161144
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
162145
return (indexes, accountPools, data, errored);
@@ -167,15 +150,9 @@ contract PoolLens is Initializable {
167150
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
168151
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
169152
*/
170-
function getPoolsOIonicrWithData(address user)
171-
external
172-
returns (
173-
uint256[] memory,
174-
PoolDirectory.Pool[] memory,
175-
IonicPoolData[] memory,
176-
bool[] memory
177-
)
178-
{
153+
function getPoolsOIonicrWithData(
154+
address user
155+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
179156
(uint256[] memory indexes, PoolDirectory.Pool[] memory userPools) = directory.getPoolsOfUser(user);
180157
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(userPools);
181158
return (indexes, userPools, data, errored);
@@ -210,16 +187,9 @@ contract PoolLens is Initializable {
210187
/**
211188
* @notice Returns total supply balance (in ETH), total borrow balance (in ETH), underlying token addresses, and underlying token symbols of a Ionic pool.
212189
*/
213-
function getPoolSummary(IonicComptroller comptroller)
214-
external
215-
returns (
216-
uint256,
217-
uint256,
218-
address[] memory,
219-
string[] memory,
220-
bool
221-
)
222-
{
190+
function getPoolSummary(
191+
IonicComptroller comptroller
192+
) external returns (uint256, uint256, address[] memory, string[] memory, bool) {
223193
uint256 totalBorrow = 0;
224194
uint256 totalSupply = 0;
225195
ICErc20[] memory cTokens = comptroller.getAllMarkets();
@@ -359,7 +329,10 @@ contract PoolLens is Initializable {
359329
return (detailedAssets);
360330
}
361331

362-
function getBorrowCapsPerCollateral(ICErc20 borrowedAsset, IonicComptroller comptroller)
332+
function getBorrowCapsPerCollateral(
333+
ICErc20 borrowedAsset,
334+
IonicComptroller comptroller
335+
)
363336
internal
364337
view
365338
returns (
@@ -448,7 +421,7 @@ contract PoolLens is Initializable {
448421
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
449422
for (uint256 i = 0; i < poolMarkets.length; i++) {
450423
assets[i] = address(poolMarkets[i]);
451-
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
424+
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
452425
}
453426

454427
return (assets, supplyCapsPerAsset);
@@ -458,23 +431,17 @@ contract PoolLens is Initializable {
458431
* @notice returns the total supply cap for each asset in the pool and the total non-whitelist supplied assets
459432
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
460433
*/
461-
function getSupplyCapsDataForPool(IonicComptroller comptroller)
462-
public
463-
view
464-
returns (
465-
address[] memory,
466-
uint256[] memory,
467-
uint256[] memory
468-
)
469-
{
434+
function getSupplyCapsDataForPool(
435+
IonicComptroller comptroller
436+
) public view returns (address[] memory, uint256[] memory, uint256[] memory) {
470437
ICErc20[] memory poolMarkets = comptroller.getAllMarkets();
471438

472439
address[] memory assets = new address[](poolMarkets.length);
473440
uint256[] memory supplyCapsPerAsset = new uint256[](poolMarkets.length);
474441
uint256[] memory nonWhitelistedTotalSupply = new uint256[](poolMarkets.length);
475442
for (uint256 i = 0; i < poolMarkets.length; i++) {
476443
assets[i] = address(poolMarkets[i]);
477-
supplyCapsPerAsset[i] = comptroller.supplyCaps(assets[i]);
444+
supplyCapsPerAsset[i] = comptroller.effectiveSupplyCaps(assets[i]);
478445
uint256 assetTotalSupplied = poolMarkets[i].getTotalUnderlyingSupplied();
479446
uint256 whitelistedSuppliersSupply = comptroller.getWhitelistedSuppliersSupply(assets[i]);
480447
if (whitelistedSuppliersSupply >= assetTotalSupplied) nonWhitelistedTotalSupply[i] = 0;
@@ -488,7 +455,9 @@ contract PoolLens is Initializable {
488455
* @notice returns the total borrow cap and the per collateral borrowing cap/blacklist for the asset
489456
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
490457
*/
491-
function getBorrowCapsForAsset(ICErc20 asset)
458+
function getBorrowCapsForAsset(
459+
ICErc20 asset
460+
)
492461
public
493462
view
494463
returns (
@@ -500,14 +469,16 @@ contract PoolLens is Initializable {
500469
{
501470
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
502471
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
503-
totalBorrowCap = comptroller.borrowCaps(address(asset));
472+
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
504473
}
505474

506475
/**
507476
* @notice returns the total borrow cap, the per collateral borrowing cap/blacklist for the asset and the total non-whitelist borrows
508477
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
509478
*/
510-
function getBorrowCapsDataForAsset(ICErc20 asset)
479+
function getBorrowCapsDataForAsset(
480+
ICErc20 asset
481+
)
511482
public
512483
view
513484
returns (
@@ -520,7 +491,7 @@ contract PoolLens is Initializable {
520491
{
521492
IonicComptroller comptroller = IonicComptroller(asset.comptroller());
522493
(collateral, borrowCapsPerCollateral, collateralBlacklisted) = getBorrowCapsPerCollateral(asset, comptroller);
523-
totalBorrowCap = comptroller.borrowCaps(address(asset));
494+
totalBorrowCap = comptroller.effectiveBorrowCaps(address(asset));
524495
uint256 totalBorrows = asset.totalBorrowsCurrent();
525496
uint256 whitelistedBorrowersBorrows = comptroller.getWhitelistedBorrowersBorrows(address(asset));
526497
if (whitelistedBorrowersBorrows >= totalBorrows) nonWhitelistedTotalBorrows = 0;
@@ -532,11 +503,9 @@ contract PoolLens is Initializable {
532503
* Note that the whitelist does not have to be enforced.
533504
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
534505
*/
535-
function getWhitelistedPoolsByAccount(address account)
536-
public
537-
view
538-
returns (uint256[] memory, PoolDirectory.Pool[] memory)
539-
{
506+
function getWhitelistedPoolsByAccount(
507+
address account
508+
) public view returns (uint256[] memory, PoolDirectory.Pool[] memory) {
540509
(, PoolDirectory.Pool[] memory pools) = directory.getActivePools();
541510
uint256 arrayLength = 0;
542511

@@ -569,15 +538,9 @@ contract PoolLens is Initializable {
569538
* @dev This function is not designed to be called in a transaction: it is too gas-intensive.
570539
* Ideally, we can add the `view` modifier, but many cToken functions potentially modify the state.
571540
*/
572-
function getWhitelistedPoolsByAccountWithData(address account)
573-
external
574-
returns (
575-
uint256[] memory,
576-
PoolDirectory.Pool[] memory,
577-
IonicPoolData[] memory,
578-
bool[] memory
579-
)
580-
{
541+
function getWhitelistedPoolsByAccountWithData(
542+
address account
543+
) external returns (uint256[] memory, PoolDirectory.Pool[] memory, IonicPoolData[] memory, bool[] memory) {
581544
(uint256[] memory indexes, PoolDirectory.Pool[] memory accountPools) = getWhitelistedPoolsByAccount(account);
582545
(IonicPoolData[] memory data, bool[] memory errored) = getPoolsData(accountPools);
583546
return (indexes, accountPools, data, errored);

contracts/adrastia/PrudentiaLib.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.8.0;
3+
4+
library PrudentiaLib {
5+
struct PrudentiaConfig {
6+
address controller; // Adrastia Prudentia controller address
7+
uint8 offset; // Offset for delayed rate activation
8+
int8 decimalShift; // Positive values scale the rate up (in powers of 10), negative values scale the rate down
9+
}
10+
}

0 commit comments

Comments
 (0)