Skip to content

Commit

Permalink
Tlc delegatecall (#808)
Browse files Browse the repository at this point in the history
* delegatecall

* Reworked to fit size - strategy split out

* added storage to interfaces
  • Loading branch information
frontier159 authored May 29, 2023
1 parent 70c06ca commit f2f478b
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ pragma solidity ^0.8.17;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/v2/templeLineOfCredit/ITempleLineOfCredit.sol)

import { ITlcDataTypes } from "contracts/interfaces/v2/templeLineOfCredit/ITlcDataTypes.sol";
import { ITlcStorage } from "contracts/interfaces/v2/templeLineOfCredit/ITlcStorage.sol";
import { ITlcEventsAndErrors } from "contracts/interfaces/v2/templeLineOfCredit/ITlcEventsAndErrors.sol";

interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
interface ITempleLineOfCredit is ITlcStorage, ITlcEventsAndErrors {
/** Add Collateral */
function addCollateral(uint256 collateralAmount, address onBehalfOf) external;

Expand All @@ -26,17 +26,22 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
/** Position views */
function userPosition(address account) external view returns (UserPosition memory position);
function totalPosition() external view returns (TotalPosition[2] memory positions);
function getUserData(address account) external view returns (UserData memory);
function getReserveToken(TokenType tokenType) external view returns (ReserveToken memory);
function getReserveCache(TokenType tokenType) external view returns (ReserveCache memory);

/** Liquidations */
function computeLiquidity(
address[] memory accounts,
bool includePendingRequests
) external view returns (LiquidityStatus[] memory status);
function batchLiquidate(address[] memory accounts) external;
/** Liquidations */
function computeLiquidity(
address[] memory accounts,
bool includePendingRequests
) external view returns (LiquidityStatus[] memory status);
function batchLiquidate(address[] memory accounts) external;

// Manually checkpoint debt to adjust interest rate based on latest utillization ratio
function refreshInterestRates(TokenType tokenType) external;
// Manually checkpoint debt to adjust interest rate based on latest utillization ratio
function refreshInterestRates(TokenType tokenType) external;

Expand All @@ -47,4 +52,11 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
function setInterestRateModel(TokenType tokenType, address interestRateModel) external;
function setMaxLtvRatio(TokenType tokenType, uint256 maxLtvRatio) external;
function recoverToken(address token, address to, uint256 amount) external;
/** EXECUTORS/RESCUERS ONLY */
function setTlcStrategy(address _tlcStrategy) external;
function setWithdrawCollateralCooldownSecs(uint256 cooldownSecs) external;
function setBorrowCooldownSecs(TokenType tokenType, uint256 cooldownSecs) external;
function setInterestRateModel(TokenType tokenType, address interestRateModel) external;
function setMaxLtvRatio(TokenType tokenType, uint256 maxLtvRatio) external;
function recoverToken(address token, address to, uint256 amount) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,11 @@ import { IInterestRateModel } from "contracts/interfaces/v2/interestRate/IIntere
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface ITlcDataTypes {
struct UserDebtPosition {
uint256 debt;
uint256 maxBorrow;
uint256 healthFactor;
uint256 loanToValueRatio;
}

struct UserPosition {
uint256 collateralPosted;
UserDebtPosition[2] debtPositions;
}

struct TotalPosition {
/// @notice The DAI utilization rate as of the last checkpoint
uint256 utilizationRatio;

// @notice The DAI borrow interest rate as of the last checkpoint
int256 borrowRate;

// @notice The DAI total debt across all users as of this block
uint256 totalDebt;
}






enum ModuleKind {
LIQUIDATION,
POSITION
}

enum TokenType {
DAI,
OUD
}

// enum FundsRequestType {
// BORROW_DAI,
// BORROW_OUD,
// WITHDRAW_COLLATERAL
// }

struct WithdrawFundsRequest {
uint128 amount;
uint32 requestedAt;
}

enum TokenPriceType {
/// @notice equal to 1 USD
STABLE,
Expand All @@ -74,6 +30,8 @@ interface ITlcDataTypes {
struct ReserveTokenConfig {
address tokenAddress;

address tokenAddress;

/// @notice The type of how to lookup the price of the token
TokenPriceType tokenPriceType;

Expand All @@ -86,6 +44,9 @@ interface ITlcDataTypes {
/// @notice Maximum Loan To Value (LTV) ratio to prevent liquidation
uint128 maxLtvRatio;

uint32 borrowCooldownSecs;
uint128 maxLtvRatio;

uint32 borrowCooldownSecs;
}

Expand All @@ -109,9 +70,15 @@ interface ITlcDataTypes {
ReserveTokenTotals totals;
}

struct WithdrawFundsRequest {
uint128 amount;
uint32 requestedAt;
}

struct UserTokenDebt {
uint128 debt;
WithdrawFundsRequest borrowRequest;
WithdrawFundsRequest borrowRequest;
uint128 interestAccumulator;
}

Expand All @@ -128,26 +95,27 @@ interface ITlcDataTypes {
uint256 collateral;
uint256[2] debt;
}

struct UserDebtPosition {
uint256 debt;
uint256 maxBorrow;
uint256 healthFactor;
uint256 loanToValueRatio;
}

// @todo check if all of these are actually used
struct ReserveCache {
ReserveTokenConfig config;

/// @notice The last time the debt was updated for this token
// uint32 interestAccumulatorUpdatedAt;

/// @notice Total amount that has already been borrowed, which increases as interest accrues
uint128 totalDebt;
struct UserPosition {
uint256 collateralPosted;
UserDebtPosition[2] debtPositions;
}

/// @notice The interest rate as of the last borrow/repay/
int96 interestRate;
struct TotalPosition {
/// @notice The DAI utilization rate as of the last checkpoint
uint256 utilizationRatio;

uint128 interestAccumulator;
// @notice The DAI borrow interest rate as of the last checkpoint
int256 borrowRate;

uint256 price;

/// @notice The max allowed to be borrowed from the TRV
/// @dev Used as the denominator in the Utilisation Ratio
uint256 trvDebtCeiling;
// @notice The DAI total debt across all users as of this block
uint256 totalDebt;
}
}
Loading

0 comments on commit f2f478b

Please sign in to comment.