forked from CMTA/CMTAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebtEngineModule.sol
More file actions
98 lines (88 loc) · 3.73 KB
/
DebtEngineModule.sol
File metadata and controls
98 lines (88 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
/* ==== Engine === */
import {IDebtEngine, ICMTATDebt, ICMTATCreditEvents} from "../../../interfaces/engine/IDebtEngine.sol";
/* ==== Module === */
import {DebtModule} from "./DebtModule.sol";
/**
* @title Debt Engine module
* @dev
*
* Retrieve debt and creditEvents information from a debtEngine
*/
abstract contract DebtEngineModule is DebtModule {
/* ============ Events ============ */
/**
* @notice Emitted when a new DebtEngine is set.
* @dev Indicates that the contract will delegate debt logic to a new external engine.
* @param newDebtEngine The address of the new debt engine contract.
*/
event DebtEngine(IDebtEngine indexed newDebtEngine);
/* ============ Error ============ */
error CMTAT_DebtEngineModule_SameValue();
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/* ============ State Restricted Functions ============ */
/**
* @notice Sets a new external DebtEngine contract to delegate debt logic.
* @dev Only callable by accounts with the `DEBT_ROLE`.
* Emits a {DebtEngine} event upon successful update.
* @param debtEngine_ The address of the new DebtEngine contract.
* @custom:access-control
* - the caller must have the `DEBT_ROLE`.
*/
function setDebtEngine(
IDebtEngine debtEngine_
) public virtual onlyDebtManager {
DebtModuleStorage storage $ = _getDebtModuleStorage();
require($._debtEngine != debtEngine_, CMTAT_DebtEngineModule_SameValue());
_setDebtEngine($, debtEngine_);
}
/* ============ View functions ============ */
/**
* @notice Returns the current credit events information.
* @dev Delegates to the external DebtEngine if set; otherwise returns the base implementation from DebtModule.
* @return creditEvents_ The current credit events structure.
* @inheritdoc ICMTATCreditEvents
*/
function creditEvents() public view virtual override(DebtModule) returns(CreditEvents memory creditEvents_){
DebtModuleStorage storage $ = _getDebtModuleStorage();
if(address($._debtEngine) != address(0)){
creditEvents_ = $._debtEngine.creditEvents();
} else {
creditEvents_= DebtModule.creditEvents();
}
}
/**
* @notice Returns the current debt information.
* @dev Delegates to the external DebtEngine if set; otherwise returns the base implementation from DebtModule.
* @return debtInformation_ The current debt data structure.
* @inheritdoc DebtModule
*/
function debt() public view virtual override(DebtModule) returns(DebtInformation memory debtInformation_){
DebtModuleStorage storage $ = _getDebtModuleStorage();
if(address($._debtEngine) != address(0)){
debtInformation_ = $._debtEngine.debt();
} else {
debtInformation_ = DebtModule.debt();
}
}
/**
* @notice Returns the address of the currently active DebtEngine.
* @return debtEngine_ The contract address of the debt engine in use.
*/
function debtEngine() public view virtual returns (IDebtEngine debtEngine_) {
DebtModuleStorage storage $ = _getDebtModuleStorage();
return $._debtEngine;
}
/*//////////////////////////////////////////////////////////////
INTERNAL/PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
function _setDebtEngine(
DebtModuleStorage storage $, IDebtEngine debtEngine_
) internal {
$._debtEngine = debtEngine_;
emit DebtEngine(debtEngine_);
}
}