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

TLC pre-requisites #804

Merged
merged 3 commits into from
May 18, 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
7 changes: 0 additions & 7 deletions protocol/contracts/common/CommonEventsAndErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ pragma solidity ^0.8.17;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (common/CommonEventsAndErrors.sol)

// @todo check which ones we've used.

/// @notice A collection of common errors thrown within the Temple contracts
library CommonEventsAndErrors {
error InsufficientBalance(address token, uint256 required, uint256 balance);
error InvalidToken(address token);
error InvalidParam();
error InvalidAddress(address addr);
error InvalidAmount(address token, uint256 amount);
error InvalidAccess();
error ExpectedNonZero();
error Slippage(uint256 minAmountExpected, uint256 acutalAmount);
error IsPaused();
error UnknownExecuteError(bytes returndata);
event TokenRecovered(address indexed to, address indexed token, uint256 amount);
}
54 changes: 40 additions & 14 deletions protocol/contracts/interfaces/v2/ITreasuryReservesVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ interface ITreasuryReservesVault is ITempleElevatedAccess {
event StrategyShutdown(address indexed strategy, uint256 stablesRecovered, uint256 debtBurned);
event BaseStrategySet(address indexed baseStrategy);

event Borrow(address indexed strategy, uint256 stablesAmount);
event Repay(address indexed strategy, uint256 stablesAmount);
event Borrow(address indexed strategy, address indexed recipient, uint256 stablesAmount);
event Repay(address indexed strategy, address indexed from, uint256 stablesAmount);
event RealisedGain(address indexed strategy, uint256 amount);
event RealisedLoss(address indexed strategy, uint256 amount);
event TreasuryPriceIndexSet(uint256 oldTpi, uint256 newTpi);

error NotEnabled();
error AlreadyEnabled();
Expand Down Expand Up @@ -113,6 +114,22 @@ interface ITreasuryReservesVault is ITempleElevatedAccess {
*/
function setBaseStrategy(address _baseStrategy) external;

/**
* @notice The Treasury Price Index, used within strategies.
*/
function treasuryPriceIndex() external view returns (uint256);

/**
* @notice The decimal precision of 'tpi'/Temple Price index
* @dev Decimal precision for 'tpi', 9880 == $0.988, precision = 4
*/
function TPI_DECIMALS() external view returns (uint256);

/**
* @notice Set the Treasury Price Index (TPI)
*/
function setTreasuryPriceIndex(uint256 value) external;

/**
* API version to help with future integrations/migrations
*/
Expand Down Expand Up @@ -151,21 +168,30 @@ interface ITreasuryReservesVault is ITempleElevatedAccess {
);

/**
* @notice The total available stables, both as a balance in this contract and
* any available to withdraw from the baseStrategy
* @notice The current max debt ceiling that a strategy is allowed to borrow up to.
*/
function totalAvailableStables() external view returns (uint256);
function strategyDebtCeiling(address strategy) external view returns (uint256);

/**
* @notice The current dUSD debt of this strategy
* @notice The total available stables, both as a balance in this contract and
* any available to withdraw from the baseStrategy
*/
function currentStrategyDebt(address strategy) external view returns (uint256);
function totalAvailableStables() external view returns (uint256);

/**
* @notice How much a given strategy is free to borrow
* @dev availableToBorrow = max(debtCeiling - debtBalance, 0);
* @notice A strategy's current amount borrowed, and how much remaining is free to borrow
* @dev The remaining amount free to borrow is bound by:
* 1/ How much stables is globally available (in this contract + in the base strategy)
* 2/ The amount each individual strategy is whitelisted to borrow.
* @return currentDebt The current debt position for the strategy,
* @return availableToBorrow The remaining amount which the strategy can borrow
* @return debtCeiling The debt ceiling of the stratgy
*/
function availableToBorrow(address strategy) external view returns (uint256);
function strategyBorrowPosition(address strategy) external view returns (
uint256 currentDebt,
uint256 availableToBorrow,
uint256 debtCeiling
);

/**
* Pause all strategy borrow and repays
Expand Down Expand Up @@ -209,26 +235,26 @@ interface ITreasuryReservesVault is ITempleElevatedAccess {
* @dev This will revert if the strategy requests more stables than it's able to borrow.
* `dUSD` will be minted 1:1 for the amount of stables borrowed
*/
function borrow(uint256 borrowAmount) external;
function borrow(uint256 borrowAmount, address recipient) external;

/**
* @notice A strategy calls to request the most funding it can.
* @dev This will revert if the strategy requests more stables than it's able to borrow.
* `dUSD` will be minted 1:1 for the amount of stables borrowed
*/
function borrowMax() external returns (uint256);
function borrowMax(address recipient) external returns (uint256);

/**
* @notice A strategy calls to paydown it's debt
* This will pull the stables, and will burn the equivalent amount of dUSD from the strategy.
*/
function repay(uint256 repayAmount) external;
function repay(uint256 repayAmount, address strategy) external;

/**
* @notice A strategy calls to paydown all of it's debt
* This will pull the stables for the entire dUSD balance of the strategy, and burn the dUSD.
*/
function repayAll() external returns (uint256 amountRepaid);
function repayAll(address strategy) external returns (uint256 amountRepaid);

/**
* @notice The second step in a two-phase shutdown. A strategy (automated) or executor (manual) calls
Expand Down
19 changes: 13 additions & 6 deletions protocol/contracts/interfaces/v2/strategies/ITempleStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,19 @@ interface ITempleStrategy is ITempleElevatedAccess {
function currentDebt() external view returns (uint256);

/**
* @notice How much this strategy is free to borrow from the Treasury Reserves Vault
* @dev This is bound by:
* 1/ How much stables is globally available (in the TRV + in the TRV base strategy)
* 2/ The amount this individual strategy is whitelisted to borrow.
*/
function availableToBorrow() external view returns (uint256);
* @notice A strategy's current amount borrowed from the TRV, and how much remaining is free to borrow
* @dev The remaining amount free to borrow is bound by:
* 1/ How much stables is globally available (in this contract + in the base strategy)
* 2/ The amount each individual strategy is whitelisted to borrow.
* @return currentDebt The current debt position for the strategy,
* @return availableToBorrow The remaining amount which the strategy can borrow
* @return debtCeiling The debt ceiling of the stratgy
*/
function trvBorrowPosition() external view returns (
uint256 currentDebt,
uint256 availableToBorrow,
uint256 debtCeiling
);

/**
* @notice The Strategy Executor may set manual updates to asset balances
Expand Down
14 changes: 7 additions & 7 deletions protocol/contracts/v2/TempleDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mulDiv } from "@prb/math/src/Common.sol";

import { ITempleDebtToken } from "contracts/interfaces/v2/ITempleDebtToken.sol";
import { CommonEventsAndErrors } from "contracts/common/CommonEventsAndErrors.sol";
import { CompoundedInterest } from "contracts/interestRate/CompoundedInterest.sol";
import { CompoundedInterest } from "contracts/v2/interestRate/CompoundedInterest.sol";
import { TempleElevatedAccess } from "contracts/v2/access/TempleElevatedAccess.sol";

/**
Expand All @@ -25,7 +25,7 @@ import { TempleElevatedAccess } from "contracts/v2/access/TempleElevatedAccess.s
* (eg DAI's DSR at 1% APR).
* It is implemented using a share based implementation such that this base rate can be updated for all debtors
* 3/ 'risk premium' interest, where the interest rate is set per borrower.
* This represents a governance set premium for that individual borrower depending on its purpose.
* This represents a premium for that individual borrower depending on its purpose.
* For example a higher risk / higher return borrower would have a higher risk premium.
*
* On a repayment, the interest accruing at the higher rate is paid down first. When there is no more `base rate` or
Expand Down Expand Up @@ -55,7 +55,7 @@ contract TempleDebtToken is ITempleDebtToken, TempleElevatedAccess {
uint8 public constant override decimals = 18;

/**
* @notice The current (base rate) interest common for all users. This can be updated by governance
* @notice The current (base rate) interest common for all users. This can be updated by the DAO
* @dev 1e18 format, where 0.01e18 = 1%
*/
uint256 public override baseRate;
Expand Down Expand Up @@ -113,7 +113,7 @@ contract TempleDebtToken is ITempleDebtToken, TempleElevatedAccess {
}

/**
* @notice Governance can add an address which is able to mint or burn debt
* @notice Add an address which is able to mint or burn debt
* positions on behalf of users.
*/
function addMinter(address account) external override onlyElevatedAccess {
Expand All @@ -122,7 +122,7 @@ contract TempleDebtToken is ITempleDebtToken, TempleElevatedAccess {
}

/**
* @notice Governance can remove an address which is able to mint or burn debt
* @notice Remove an address which is able to mint or burn debt
* positions on behalf of users.
*/
function removeMinter(address account) external override onlyElevatedAccess {
Expand All @@ -138,7 +138,7 @@ contract TempleDebtToken is ITempleDebtToken, TempleElevatedAccess {
}

/**
* @notice Governance can update the continuously compounding (base) interest rate of all debtors, from this block onwards.
* @notice Update the continuously compounding (base) interest rate of all debtors, from this block onwards.
*/
function setBaseInterestRate(uint256 _rate) external override onlyElevatedAccess {
_checkpointBase(_compoundedBaseInterest());
Expand All @@ -147,7 +147,7 @@ contract TempleDebtToken is ITempleDebtToken, TempleElevatedAccess {
}

/**
* @notice Governance can update the continuously compounding (risk premium) interest rate for a given debtor, from this block onwards
* @notice Update the continuously compounding (risk premium) interest rate for a given debtor, from this block onwards
*/
function setRiskPremiumInterestRate(address _debtor, uint256 _rate) external override onlyElevatedAccess {
Debtor storage debtor = debtors[_debtor];
Expand Down
Loading