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
/
CustomSupply.sol
136 lines (106 loc) · 4.8 KB
/
CustomSupply.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
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.15;
import "modules/SPPLY/SPPLY.v1.sol";
/// @title CustomSupply
/// @author 0xJem
/// @notice Abstract SPPLY submodule with configurable supply values
/// @dev This submodule can be used when there are contract interactions that are
/// @dev unable to be supported by a standard SPPLY submodule.
///
/// @dev For example:
/// @dev - OHM supply in non-Ethereum mainnet lending markets (as cross-chain supply is not categorized)
/// @dev - OHM supply in non-Ethereum mainnet AMMs (as cross-chain supply is not categorized)
///
/// @dev This submodule is intended to be used as a parent contract for a custom submodule. This is mainly
/// @dev due to the value returned by the `SUBKEYCODE()` function needs to be unique for each submodule,
/// @dev but as it is a pure function, it cannot read from the state of the contract.
abstract contract CustomSupply is SupplySubmodule {
// ========== EVENTS ========== //
event CollateralizedValueUpdated(uint256 value);
event ProtocolOwnedBorrowableValueUpdated(uint256 value);
event ProtocolOwnedLiquidityValueUpdated(uint256 value);
event SourceValueUpdated(address value);
// ========== STATE VARIABLES ========== //
/// @notice The custom value for collateralized OHM
uint256 private _collateralizedOhm;
/// @notice The custom value for protocol-owned borrowable OHM
uint256 private _protocolOwnedBorrowableOhm;
/// @notice The custom value for protocol-owned liquidity OHM
uint256 private _protocolOwnedLiquidityOhm;
/// @notice The custom value for protocol-owned treasury OHM
uint256 private _protocolOwnedTreasuryOhm;
/// @notice The custom value for the source
address private _source;
// ========== CONSTRUCTOR ========== //
constructor(
Module parent_,
uint256 collateralizedOhm_,
uint256 protocolOwnedBorrowableOhm_,
uint256 protocolOwnedLiquidityOhm_,
uint256 protocolOwnedTreasuryOhm_,
address source_
) Submodule(parent_) {
_collateralizedOhm = collateralizedOhm_;
_protocolOwnedBorrowableOhm = protocolOwnedBorrowableOhm_;
_protocolOwnedLiquidityOhm = protocolOwnedLiquidityOhm_;
_protocolOwnedTreasuryOhm = protocolOwnedTreasuryOhm_;
_source = source_;
emit CollateralizedValueUpdated(collateralizedOhm_);
emit ProtocolOwnedBorrowableValueUpdated(protocolOwnedBorrowableOhm_);
emit ProtocolOwnedLiquidityValueUpdated(protocolOwnedLiquidityOhm_);
emit SourceValueUpdated(source_);
}
// ========== DATA FUNCTIONS ========== //
/// @inheritdoc SupplySubmodule
function getCollateralizedOhm() external view virtual override returns (uint256) {
return _collateralizedOhm;
}
/// @inheritdoc SupplySubmodule
function getProtocolOwnedBorrowableOhm() external view virtual override returns (uint256) {
return _protocolOwnedBorrowableOhm;
}
/// @inheritdoc SupplySubmodule
function getProtocolOwnedLiquidityOhm() external view virtual override returns (uint256) {
return _protocolOwnedLiquidityOhm;
}
function getProtocolOwnedTreasuryOhm() external view virtual override returns (uint256) {
return _protocolOwnedTreasuryOhm;
}
/// @inheritdoc SupplySubmodule
function getProtocolOwnedLiquidityReserves()
external
view
virtual
override
returns (SPPLYv1.Reserves[] memory)
{
address[] memory tokens = new address[](1);
tokens[0] = address(SPPLYv1(address(parent)).ohm());
uint256[] memory balances = new uint256[](1);
balances[0] = _protocolOwnedLiquidityOhm;
SPPLYv1.Reserves[] memory reserves = new SPPLYv1.Reserves[](1);
reserves[0] = SPPLYv1.Reserves({source: _source, tokens: tokens, balances: balances});
return reserves;
}
/// @inheritdoc SupplySubmodule
function getSourceCount() external pure virtual override returns (uint256) {
return 1;
}
// =========== ADMIN FUNCTIONS =========== //
function setCollateralizedOhm(uint256 value_) external onlyParent {
_collateralizedOhm = value_;
emit CollateralizedValueUpdated(value_);
}
function setProtocolOwnedBorrowableOhm(uint256 value_) external onlyParent {
_protocolOwnedBorrowableOhm = value_;
emit ProtocolOwnedBorrowableValueUpdated(value_);
}
function setProtocolOwnedLiquidityOhm(uint256 value_) external onlyParent {
_protocolOwnedLiquidityOhm = value_;
emit ProtocolOwnedLiquidityValueUpdated(value_);
}
function setSource(address source_) external onlyParent {
_source = source_;
emit SourceValueUpdated(source_);
}
}