This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathIncurDebtSupply.sol
156 lines (125 loc) · 5.35 KB
/
IncurDebtSupply.sol
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.15;
import "modules/SPPLY/SPPLY.v1.sol";
// Example contract: https://etherscan.io/address/0xd9d87586774fb9d036fa95a5991474513ff6c96e#readContract
interface IIncurDebt {
function totalOutstandingGlobalDebt() external view returns (uint256);
}
/// @title IncurDebtSupply
/// @author 0xJem
/// @notice Calculates the amount of OHM in the IncurDebt contract(s)
contract IncurDebtSupply is SupplySubmodule {
// IncurDebt involves gOHM being deposited into the contract, and then being used to mint OHM.
// That OHM is combined with another token to form a liquidity pair.
//
// No OHM is borrowable
// All OHM is collateralized
// No OHM is liquidity
// Therefore:
// Protocol-owned Borrowable OHM = 0
// Collateralized OHM = OHM minted by the contract
// Protocol-owned Liquidity OHM = 0
// ========== ERRORS ========== //
/// @notice Invalid parameters were passed to a function
error IncurDebtSupply_InvalidParams();
// ========== EVENTS ========== //
/// @notice Emitted when the address of the IncurDebt contract is updated
event IncurDebtUpdated(address incurDebt_);
// ========== STATE VARIABLES ========== //
IIncurDebt internal _incurDebt;
// ========== CONSTRUCTOR ========== //
/// @notice Constructor for the IncurDebtSupply submodule
/// @dev Will revert if:
/// @dev - Calling the `Submodule` constructor fails
/// @dev - The `incurDebt_` address is the zero address
///
/// @dev Emits the IncurDebtUpdated event
///
/// @param parent_ The address of the parent SPPLY module
/// @param incurDebt_ The address of the IncurDebt contract
constructor(Module parent_, address incurDebt_) Submodule(parent_) {
// Check for zero address
if (incurDebt_ == address(0)) revert IncurDebtSupply_InvalidParams();
_incurDebt = IIncurDebt(incurDebt_);
emit IncurDebtUpdated(incurDebt_);
}
// ========== SUBMODULE SETUP ========== //
/// @inheritdoc Submodule
function SUBKEYCODE() public pure override returns (SubKeycode) {
return toSubKeycode("SPPLY.INCURDEBT");
}
/// @inheritdoc Submodule
function VERSION() external pure override returns (uint8 major, uint8 minor) {
major = 1;
minor = 0;
}
/// @inheritdoc Submodule
function INIT() external override onlyParent {}
// ========== DATA FUNCTIONS ========== //
/// @inheritdoc SupplySubmodule
/// @dev The value of IncurDebt.totalOutstandingGlobalDebt() is returned, as
/// the OHM minted against gOHM collateral is fully-collateralized.
function getCollateralizedOhm() external view override returns (uint256) {
return _incurDebt.totalOutstandingGlobalDebt();
}
/// @inheritdoc SupplySubmodule
/// @dev Not applicable to IncurDebt
function getProtocolOwnedBorrowableOhm() external pure override returns (uint256) {
return 0;
}
/// @inheritdoc SupplySubmodule
/// @dev Not applicable to IncurDebt
function getProtocolOwnedLiquidityOhm() external pure override returns (uint256) {
return 0;
}
/// @inheritdoc SupplySubmodule
/// @dev Not applicable to IncurDebt
function getProtocolOwnedTreasuryOhm() external pure override returns (uint256) {
return 0;
}
/// @inheritdoc SupplySubmodule
/// @dev Protocol-owned liquidity OHM is always zero for lending facilities.
/// @dev
/// This function returns an array with the same length as `getSourceCount()`, but with empty values.
function getProtocolOwnedLiquidityReserves()
external
view
override
returns (SPPLYv1.Reserves[] memory)
{
SPPLYv1.Reserves[] memory reserves = new SPPLYv1.Reserves[](1);
reserves[0] = SPPLYv1.Reserves({
source: address(_incurDebt),
tokens: new address[](0),
balances: new uint256[](0)
});
return reserves;
}
/// @inheritdoc SupplySubmodule
/// @dev This always returns a value of one, as there is a 1:1 mapping between an IncurDebt contract and the Submodule
function getSourceCount() external pure override returns (uint256) {
return 1;
}
// ========== ADMIN FUNCTIONS ========== //
/// @notice Set the address of the IncurDebt contract
/// @dev Will revert if:
/// @dev - The address is the zero address
/// @dev - The caller is not the parent module
///
/// @dev Emits the IncurDebtUpdated event
///
/// @param incurDebt_ The address of the IncurDebt contract
function setIncurDebt(address incurDebt_) external onlyParent {
// Check for zero address
if (incurDebt_ == address(0)) revert IncurDebtSupply_InvalidParams();
_incurDebt = IIncurDebt(incurDebt_);
emit IncurDebtUpdated(incurDebt_);
}
// ========== VIEWS ========== //
/// @notice Get the address of the IncurDebt contract
///
/// @return The address of the IncurDebt contract
function getIncurDebt() external view returns (address) {
return address(_incurDebt);
}
}