Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tlc interface to remove cooldown #818

Merged
merged 7 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pragma solidity ^0.8.17;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/v2/circuitBreaker/ITempleCircuitBreaker.sol)

import { ITempleElevatedAccess } from "contracts/interfaces/v2/access/ITempleElevatedAccess.sol";

/**
* @title Temple Circuit Breaker
*
* @notice A circuit breaker can perform checks and record state for transactions which have
* already happened cumulative totals, totals within a rolling period window,
* sender specific totals, etc.
*/
interface ITempleCircuitBreaker is ITempleElevatedAccess {

/**
* @notice Verify the new amount requested for the sender does not breach the
* cap in this rolling period.
*/
function preCheck(address onBehalfOf, address sender, uint256 amount) external;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pragma solidity ^0.8.17;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/v2/circuitBreaker/ITempleCircuitBreakerProxy.sol)

import { ITempleElevatedAccess } from "contracts/interfaces/v2/access/ITempleElevatedAccess.sol";
import { ITempleCircuitBreaker } from "contracts/interfaces/v2/circuitBreaker/ITempleCircuitBreaker.sol";

/**
* @title Temple Circuit Breaker Proxy
*
* @notice Direct circuit breaker requests to the correct underlying implementation,
* based on a pre-defined bytes32 identifier, and a token.
*/
interface ITempleCircuitBreakerProxy is ITempleElevatedAccess {
event CircuitBreakerSet(bytes32 indexed identifier, address indexed token, address circuitBreaker);

/**
* @notice The mapping of identifier (listed in TempleCircuitBreakerIdentifiers)
* to the underlying circuit breaker contract
*/
function circuitBreakers(
bytes32 identifier,
address token
) external view returns (ITempleCircuitBreaker);

/**
* @notice Set the address of the circuit breaker for a particular identifier and token
*/
function setCircuitBreaker(
bytes32 identifier,
address token,
address circuitBreaker
) external;

/**
* @notice For a given identifier & token, verify the new amount requested for the sender does not breach the
* cap in this rolling period.
*/
function preCheck(
bytes32 identifier,
address token,
address sender,
uint256 amount
) external;

/**
* @notice The set of all identifiers registered
*/
function identifiers() external view returns (bytes32[] memory);
}
17 changes: 17 additions & 0 deletions protocol/contracts/interfaces/v2/strategies/ITlcStrategy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.8.17;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/v2/strategies/ITlcStrategy.sol)

import { ITempleStrategy } from "contracts/interfaces/v2/strategies/ITempleStrategy.sol";

/**
* @title Temple Line of Credit Strategy
* @notice A simple wrapper strategy over TLC, where
* the assets is the current total user debt.
*/
interface ITlcStrategy is ITempleStrategy {
/**
* @notice TLC (only) will call on this to fund user borrows of DAI
*/
function fundFromTrv(uint256 amount, address recipient) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ITlcEventsAndErrors } from "contracts/interfaces/v2/templeLineOfCredit/ITlcEventsAndErrors.sol";
import { ITlcDataTypes } from "contracts/interfaces/v2/templeLineOfCredit/ITlcDataTypes.sol";
import { ITreasuryReservesVault } from "contracts/interfaces/v2/ITreasuryReservesVault.sol";
import { ITlcStrategy } from "contracts/interfaces/v2/templeLineOfCredit/ITlcStrategy.sol";
import { ITlcStrategy } from "contracts/interfaces/v2/strategies/ITlcStrategy.sol";
import { ITempleCircuitBreakerProxy } from "contracts/interfaces/v2/circuitBreaker/ITempleCircuitBreakerProxy.sol";

/**
* @title Temple Line of Credit (TLC)
* @notice Users supply Temple as collateral, and can then borrow DAI.
*
* Both borrows and collateral withdraws require two transactions:
* 1/ Request the borrow | collateral withdrawal
* 2/ Wait until the min request time has passed (and before the max time)
* and then do the borrow | collateral withdrawal.
* This is in order to further mitigate money market attack vectors. Requests
* can be cancelled by the user or with elevated access on behalf of users.
*
* Temple is valued at the Temple Treasury Price Index (TPI)
* User debt increases at a continuously compounding rate.
* Liquidations occur when users LTV exceeds the maximum allowed.
Expand All @@ -33,49 +27,21 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
function addCollateral(uint256 collateralAmount, address onBehalfOf) external;

/**
* @notice An account requests to remove Temple collateral.
* @dev After this request is issued, the account must then execute the `removeCollateral()`
* within the `removeCollateralRequestConfig`
* Subsequent requests override previous requests.
* @notice Remove Temple collateral. (active borrow positions are not allowed to go above the max LTV)
* @param amount The amount of collateral to remove
*/
function requestRemoveCollateral(uint256 amount) external;

/**
* @notice An account (or elevated access) cancels an existing Remove Collateral request
* @param account The account to cancel the request for.
*/
function cancelRemoveCollateralRequest(address account) external;

/**
* @notice Execute the remove collateral request, within the window of the prior issued request
* @param recipient Send the Temple collateral to a specified recipient address.
*/
function removeCollateral(address recipient) external;
function removeCollateral(uint256 amount, address recipient) external;

/**
* @notice An account requests to borrow DAI
* @dev After this request is issued, the account must then execute the `borrow()`
* within the valid borrow request window
* Subsequent requests override previous requests.
* @notice Borrow DAI (not allowed to borrow over the max LTV)
* @param amount The amount to borrow
*/
function requestBorrow(uint256 amount) external;

/**
* @notice An account (or elevated access) cancels an existing Borrow request
* @param account The account to cancel the request for.
*/
function cancelBorrowRequest(address account) external;

/**
* @notice Execute the borrow request, within the window of the prior issued request
* @param recipient Send the borrowed token to a specified recipient address.
*/
function borrow(address recipient) external;
function borrow(uint256 amount, address recipient) external;

/**
* @notice An account repays some of its borrowed DAI debt
* @notice An account repays some of its DAI debt
* @param repayAmount The amount to repay. Cannot be more than the current debt.
* @param onBehalfOf Another address can repay the debt on behalf of someone else
*/
Expand All @@ -102,26 +68,17 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
uint256 totalDaiDebtWiped
);

/**
* @notice New borrows of DAI may be paused in an emergency to protect user funds
*/
function setBorrowPaused(bool isPaused) external;

/**
* @notice Update the TLC Strategy contract, and Treasury Reserves Vault (TRV)
* @dev The TRV is granted access to spend DAI, in order to repay debt.
*/
function setTlcStrategy(address _tlcStrategy) external;

/**
* @notice Set the Withdrawal Collateral Request window parameters
* @param minSecs The number of seconds which must elapse between a request and the action
* @param maxSecs The number of seconds until a request expires
*/
function setWithdrawCollateralRequestConfig(uint256 minSecs, uint256 maxSecs) external;

/**
* @notice Set the Borrow Request window parameters
* @param minSecs The number of seconds which must elapse between a request and the action
* @param maxSecs The number of seconds until a request expires
*/
function setBorrowRequestConfig(uint256 minSecs, uint256 maxSecs) external;

/**
* @notice Update the interest rate model contract for DAI borrows
* @param interestRateModel The contract address of the new model
Expand Down Expand Up @@ -172,14 +129,6 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
*/
function tlcStrategy() external view returns (ITlcStrategy);

/**
* @notice Users/accounts must first request to remove collateral.
* The user must wait a period of time after the request before they can action the withdraw.
* The request also has an expiry time.
* If a request expires, a new request will need to be made or the actual withdraw will then revert.
*/
function removeCollateralRequestConfig() external view returns (uint32 minSecs, uint32 maxSecs);

/**
* @notice A record of the total amount of collateral deposited by users/accounts.
*/
Expand All @@ -188,12 +137,9 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
/**
* @notice An view of an accounts current and up to date position as of this block
* @param account The account to get a position for
* @param includePendingRequests Whether to include any pending but not yet executed
* requests for Collateral Withdraw or Borrow.
*/
function accountPosition(
address account,
bool includePendingRequests
address account
) external view returns (
AccountPosition memory position
);
Expand All @@ -210,12 +156,9 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
* @notice Compute the liquidity status for a set of accounts.
* @dev This can be used to verify if accounts can be liquidated or not.
* @param accounts The accounts to get the status for.
* @param includePendingRequests Whether to include any pending but not yet executed
* requests for Collateral Withdraw or Borrow.
*/
function computeLiquidity(
address[] calldata accounts,
bool includePendingRequests
address[] calldata accounts
) external view returns (LiquidationStatus[] memory status);

/**
Expand All @@ -232,4 +175,10 @@ interface ITempleLineOfCredit is ITlcDataTypes, ITlcEventsAndErrors {
DebtTokenConfig memory config,
DebtTokenData memory data
);

/**
* @notice New borrows and collateral withdrawals are checked against a circuit breaker
* to ensure no more than a cap is withdrawn in a given period
*/
function circuitBreakerProxy() external view returns (ITempleCircuitBreakerProxy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ interface ITlcDataTypes {
/// @notice The borrow interest rate model contract
IInterestRateModel interestRateModel;

/// @notice The min/max seconds after a borrow request in which the borrow action
/// can then be performed
FundsRequestConfig borrowRequestConfig;
/// @notice Pause new borrows
bool borrowsPaused;
}

/// @notice The latest checkpoint of Debt Token data
Expand All @@ -34,16 +33,6 @@ interface ITlcDataTypes {
uint256 interestAccumulator;
}

/// @notice The min/max seconds after a borrow or collateral removal request
/// in which the borrow action can then be performed
struct FundsRequestConfig {
/// @notice The minimum numer of seconds after a request has been made before the action can be done
uint32 minSecs;

/// @notice The maximum number of seconds after a request has been made before the request expires.
uint32 maxSecs;
}

/// @notice The record of an account's collateral, requests
/// and DAI debt data
/// @dev Packed slots: (128 + 128), (128 + 128), (128 + 64 + 64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ pragma solidity ^0.8.17;
interface ITlcEventsAndErrors {
error ExceededMaxLtv(uint256 collateralAmount, uint256 collateralValue, uint256 currentDaiDebt);
error ExceededBorrowedAmount(uint256 totalDebtAmount, uint256 repayAmount);
error NotInFundsRequestWindow(uint256 currentTimestamp, uint64 requestedAt, uint32 windowMinSecs, uint32 windowMaxSecs);
error InsufficientAmount(uint256 required, uint256 provided);
error Paused();

event TlcStrategySet(address indexed strategy, address indexed treasuryReservesVault);
event RemoveCollateralRequestConfigSet(uint256 minSecs, uint256 maxSecs);
event BorrowRequestConfigSet(uint256 minSecs, uint256 maxSecs);
event InterestRateModelSet(address indexed interestRateModel);
event MaxLtvRatioSet(uint256 maxLtvRatio);
event CollateralAdded(address indexed fundedBy, address indexed onBehalfOf, uint256 collateralAmount);
event CollateralRemoved(address indexed account, address indexed recipient, uint256 collateralAmount);
event RemoveCollateralRequested(address indexed account, uint256 amount);
event RemoveCollateralRequestCancelled(address indexed account);
event BorrowRequested(address indexed account, uint256 amount);
event BorrowRequestCancelled(address indexed account);
event Borrow(address indexed account, address indexed recipient, uint256 amount);
event Repay(address indexed fundedBy, address indexed onBehalfOf, uint256 repayAmount);
event Liquidated(address indexed account, uint256 collateralSeized, uint256 collateralValue, uint256 daiDebtWiped);
event InterestRateUpdate(uint96 newInterestRate);
event BorrowPausedSet(bool isPaused);
}

This file was deleted.

Loading