Skip to content

Commit 762cdc4

Browse files
author
Lunar Engineering
committed
Update contracts for moonbeam
1 parent e23657c commit 762cdc4

27 files changed

+33221
-68803
lines changed

contracts-public-checksums.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
MD5 (./contracts/core/EIP20NonStandardInterface.sol) = 83952e9bd66b6bd33a46d0c723bb190c
2+
MD5 (./contracts/core/ComptrollerInterface.sol) = 57283357a480c63e43373cd11201eb06
3+
MD5 (./contracts/core/ReentrancyGuard.sol) = 0c04eb0eb9226e58874d556d02763d12
4+
MD5 (./contracts/core/MGlimmer.sol) = a60c01f771237777ee253f7457588f83
5+
MD5 (./contracts/core/Comptroller.sol) = d3623c4f6cd725613e62002a5a9ba878
6+
MD5 (./contracts/core/Exponential.sol) = f2cffb32e57b5b3f80b2718d4bcb9254
7+
MD5 (./contracts/core/MErc20Delegate.sol) = 5c7e1544394376663a2ca7c6ec836e7d
8+
MD5 (./contracts/core/PriceOracle.sol) = 6e8c4ea2ccc05b32464306b0ddfe6c49
9+
MD5 (./contracts/core/LegacyInterestRateModel.sol) = f15b41c2a4cd3b10ab40eb1b2df86486
10+
MD5 (./contracts/core/LegacyJumpRateModelV2.sol) = dae7e5f0a1c5ae09da769dcb90106a9c
11+
MD5 (./contracts/core/ExponentialNoError.sol) = f4e4879d30ddd8d0812469c00d484517
12+
MD5 (./contracts/core/SafeMath.sol) = 2661610016211448de6fa364ccaddb7f
13+
MD5 (./contracts/core/ErrorReporter.sol) = 63d85f4708dfaa3321fc48653d3480d2
14+
MD5 (./contracts/core/Unitroller.sol) = a0098894d7358305a3b298f6b2fa61bd
15+
MD5 (./contracts/core/MDaiDelegate.sol) = 5958852908e610fb109fdb87ca444fef
16+
MD5 (./contracts/core/Migrations.sol) = 8d2e52d29e23268ea3b72b201eeadb12
17+
MD5 (./contracts/core/CarefulMath.sol) = 38ceaf940226da0c34bd075dcc82f319
18+
MD5 (./contracts/core/MErc20Immutable.sol) = c748ea01021f13134cbb8ba04d9b0bb3
19+
MD5 (./contracts/core/JumpRateModel.sol) = 7340b7041d0d8d8a30358df0029558f9
20+
MD5 (./contracts/core/Timelock.sol) = 069b7177a9326c83aebc214afd548dc8
21+
MD5 (./contracts/core/EIP20Interface.sol) = 54bb364849768cc3d063ffa00b611cb8
22+
MD5 (./contracts/core/Chainlink/AggregatorV2V3Interface.sol) = 475ff0a3d2d7b868b40fa362f8287e76
23+
MD5 (./contracts/core/Chainlink/ChainlinkOracle.sol) = e5371d8eb221e15acb1e58a7e4c1f4b6
24+
MD5 (./contracts/core/Chainlink/MockAggregator.sol) = db81c6e4e0c0c430802950165aa3f3c9
25+
MD5 (./contracts/core/InterestRateModel.sol) = 635bb269a2e5c68df1d21cb243ba85ee
26+
MD5 (./contracts/core/JumpRateModelV2.sol) = a0117bf581d7c38c6c6ebb9f1dfc75c4
27+
MD5 (./contracts/core/ComptrollerStorage.sol) = 290fe8c3d042202e0354d7a52506a1bb
28+
MD5 (./contracts/core/WhitePaperInterestRateModel.sol) = b2271de8cfa1710b308d384b6462cbca
29+
MD5 (./contracts/core/Reservoir.sol) = f32b181de1e017e93efa539987f045de
30+
MD5 (./contracts/core/MErc20Delegator.sol) = a09b978b3006d921a51482dd64f7ff69
31+
MD5 (./contracts/core/Governance/GovernorAlpha.sol) = f86ab7bea6ca562638a11f92109b7e58
32+
MD5 (./contracts/core/Governance/Well.sol) = 38fbdd9b89e1aa0cb8c3ec09b4230d15
33+
MD5 (./contracts/core/Governance/Mfam.sol) = fad631b9b9f3b3ba6cc8315369389497
34+
MD5 (./contracts/core/MTokenInterfaces.sol) = df97ca08b6ef9d30e5507642b7100618
35+
MD5 (./contracts/core/MErc20.sol) = acb3472cf9e9aa5b1a3cce5ef9198313
36+
MD5 (./contracts/core/Maximillion.sol) = d93d1274470121a4208be6628d25d870
37+
MD5 (./contracts/core/SimplePriceOracle.sol) = 0cf77b5a96e81cd1177b62cbf31bbd3f
38+
MD5 (./contracts/core/BaseJumpRateModelV2.sol) = e6602635d1ab61ef66bd3e32e27f7d6e
39+
MD5 (./contracts/core/FaucetToken.sol) = 353df1eb5a27f8e94f72525fb53075cb
40+
MD5 (./contracts/core/OpenZeppelin/ReentrancyGuard.sol) = 0c04eb0eb9226e58874d556d02763d12
41+
MD5 (./contracts/core/MLikeDelegate.sol) = f2b05621cab24ccb57bdcdfca29669e5
42+
MD5 (./contracts/core/MToken.sol) = f32bd900601f99f2edfad10439c8a07f
43+
MD5 (./contracts/safety-module/test/FaucetERC20.sol) = 9bd91d5c2f86203219b39faf19b8903c
44+
MD5 (./contracts/safety-module/EcosystemReserve.sol) = 8f04205964d70633f9d5c32adb831f6c
45+
MD5 (./contracts/safety-module/libraries/ERC20.sol) = 55e85e057e499190174352c5cffeb199
46+
MD5 (./contracts/safety-module/libraries/DistributionTypes.sol) = d77d3ab8211b5f0ae0e18b67bf4fedee
47+
MD5 (./contracts/safety-module/libraries/Ownable.sol) = e87f43b311deb9e415c63a1c885c0ec5
48+
MD5 (./contracts/safety-module/libraries/ERC20WithSnapshot.sol) = f404eaf464b0b29e3ef9aadd952e43d9
49+
MD5 (./contracts/safety-module/libraries/SafeERC20.sol) = e662b5d784c280ea6f2f34666ea52beb
50+
MD5 (./contracts/safety-module/libraries/SafeMath.sol) = a1443375998f291eda277e37d807079d
51+
MD5 (./contracts/safety-module/libraries/Address.sol) = 324f72efe372c922a5a7dc6f2fe69377
52+
MD5 (./contracts/safety-module/libraries/Context.sol) = dc250eab909c6959316b4eb816b995e6
53+
MD5 (./contracts/safety-module/utils/Initializable.sol) = 0af9caf67eb6f88565b9b356acb71503
54+
MD5 (./contracts/safety-module/StakedToken.sol) = 86f75d40d4a41e3b528ae74003674114
55+
MD5 (./contracts/safety-module/EcosystemReserveMoonriver.sol) = b830656beeb0ed176010506e217e49dc
56+
MD5 (./contracts/safety-module/DistributionManager.sol) = 3e48a4e875f53b24b29e3b4b8bf9e1f2
57+
MD5 (./contracts/safety-module/StakedWell.sol) = b9ee448a56d1e037cc1e48120933d33e
58+
MD5 (./contracts/safety-module/StakedMfam.sol) = cb523e28fb44cfd8ba93aec5f3ef2c9d
59+
MD5 (./contracts/safety-module/EcosystemReserveController.sol) = b3f3675ce85fc08ad8f4f19ec2af4dc2
60+
MD5 (./contracts/safety-module/OpenZeppelin/ReentrancyGuardUpgradeable.sol) = 4cb88b5aec9afbfab75ceac35868db0a
61+
MD5 (./contracts/safety-module/interfaces/IDistributionManager.sol) = 463b27a9f6fa908f56d549dd59f5eedc
62+
MD5 (./contracts/safety-module/interfaces/IERC20.sol) = 1edda004cfa239b139a9884912977510
63+
MD5 (./contracts/safety-module/interfaces/IERC20Detailed.sol) = 8c7bb52274e239e6fe06ccd8ea8c4d16
64+
MD5 (./contracts/safety-module/interfaces/IEcosystemReserve.sol) = 822d7e686a8ae2df32db89a05c84fbbc
65+
MD5 (./contracts/safety-module/interfaces/ITransferHook.sol) = 9f3d534eb47a681348a25a0b83fe973a
66+
MD5 (./contracts/safety-module/interfaces/IStakedToken.sol) = ae2e947c10c0280002ed1b0dbe9a298d
67+
MD5 (./contracts/tokensale/TokenSaleDistributorProxy.sol) = 157d8afe490bb846d0ad1e73c5e28083
68+
MD5 (./contracts/tokensale/IERC20.sol) = 8de51aa1cc05ecd80cf74136931839da
69+
MD5 (./contracts/tokensale/ReentrancyGuard.sol) = 163a2615ef3237b1cda301e137b7039d
70+
MD5 (./contracts/tokensale/TokenSaleDistributorStorage.sol) = 6e6b9006e51c2f37bc6749df3bb598f0
71+
MD5 (./contracts/tokensale/TokenSaleDistributor.sol) = 196e5c87cbffdee435776a67b38f455c
72+
MD5 (./contracts/tokensale/SafeERC20.sol) = 75945eb9bbc1e1a162f89e392c6235ab
73+
MD5 (./contracts/tokensale/Address.sol) = fb942fd58936e623fa6db71991268799
74+
MD5 (./contracts/tokensale/TokenSaleDistributorProxyStorage.sol) = a5f5e34eb80abd8928a84c5865afa520
75+
MD5 (./contracts/private/ComptrollerRewardViewer.sol) = 78d4351762e73cc8292f41b633368db8

contracts/core/Comptroller.sol

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ contract Comptroller is ComptrollerVXStorage, ComptrollerInterface, ComptrollerE
5656
event DistributedBorrowerReward(uint8 indexed tokenType, MToken indexed mToken, address indexed borrower, uint wellDelta, uint wellBorrowIndex);
5757

5858
/// @notice Emitted when WELL or GLMR is distributed to a supplier
59-
event DistributedSupplierReward(uint8 indexed tokenType, MToken indexed mToken, address indexed borrower, uint wellDelta, uint wellBorrowIndex);
59+
event DistributedSupplierReward(uint8 indexed tokenType, MToken indexed mToken, address indexed supplier, uint wellDelta, uint wellSupplyIndex);
6060

6161
/// @notice Emitted when borrow cap for a mToken is changed
6262
event NewBorrowCap(MToken indexed mToken, uint newBorrowCap);
@@ -83,6 +83,12 @@ contract Comptroller is ComptrollerVXStorage, ComptrollerInterface, ComptrollerE
8383
uint8 public constant rewardWell = 0;
8484
uint8 public constant rewardGlmr = 1;
8585

86+
// The amount of gas to use when making a native asset transfer.
87+
uint16 public gasAmount = 2300;
88+
89+
/// @notice Emitted when the admin changes the gas amount.
90+
event NewGasAmount(uint16 oldGasAmount, uint16 newGasAmount);
91+
8692
constructor() public {
8793
admin = msg.sender;
8894
}
@@ -1000,6 +1006,29 @@ contract Comptroller is ComptrollerVXStorage, ComptrollerInterface, ComptrollerE
10001006
return uint(Error.NO_ERROR);
10011007
}
10021008

1009+
/**
1010+
* @notice Admin function to change the amount of gas sent with native token transfers
1011+
* @param newGasAmount The new gas amount to use on native asset transfers.
1012+
* @return uint 0=success, otherwise a failure. (See enum Error for details)
1013+
*/
1014+
function _setGasAmount(uint16 newGasAmount) public returns (uint) {
1015+
if (msg.sender != admin) {
1016+
return fail(Error.UNAUTHORIZED, FailureInfo.SET_GAS_AMOUNT_OWNER_CHECK);
1017+
}
1018+
require(newGasAmount >= 2300);
1019+
1020+
// Save current value for inclusion in log
1021+
uint16 oldGasAmount = gasAmount;
1022+
1023+
// Store gasAmount with value gasAmount
1024+
gasAmount = newGasAmount;
1025+
1026+
// Emit NewGasAmount(oldGasAmount, newGasAmount)
1027+
emit NewGasAmount(oldGasAmount, newGasAmount);
1028+
1029+
return uint(Error.NO_ERROR);
1030+
}
1031+
10031032
function _setMintPaused(MToken mToken, bool state) public returns (bool) {
10041033
require(markets[address(mToken)].isListed, "cannot pause a market that is not listed");
10051034
require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause");
@@ -1297,7 +1326,7 @@ contract Comptroller is ComptrollerVXStorage, ComptrollerInterface, ComptrollerE
12971326
} else if (rewardType == 1) {
12981327
uint glmrRemaining = address(this).balance;
12991328
if (amount > 0 && amount <= glmrRemaining) {
1300-
(bool success, ) = user.call.value(amount)("");
1329+
(bool success, ) = user.call.value(amount).gas(gasAmount)("");
13011330
require(success, "Transfer failed");
13021331
return 0;
13031332
}

contracts/core/ComptrollerInterface.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ contract ComptrollerInterface {
44
/// @notice Indicator that this is a Comptroller contract (for inspection)
55
bool public constant isComptroller = true;
66

7+
/// @notice The amount of gas to use when making a native asset transfer.
8+
uint16 public gasAmount;
9+
710
/*** Assets You Are In ***/
811

912
function enterMarkets(address[] calldata mTokens) external returns (uint[] memory);

contracts/core/ErrorReporter.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ contract ComptrollerErrorReporter {
4242
SET_PRICE_ORACLE_OWNER_CHECK,
4343
SUPPORT_MARKET_EXISTS,
4444
SUPPORT_MARKET_OWNER_CHECK,
45-
SET_PAUSE_GUARDIAN_OWNER_CHECK
45+
SET_PAUSE_GUARDIAN_OWNER_CHECK,
46+
SET_GAS_AMOUNT_OWNER_CHECK
4647
}
4748

4849
/**

contracts/core/MGlimmer.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ contract MGlimmer is MToken {
149149
}
150150

151151
function doTransferOut(address payable to, uint amount) internal {
152-
/* Send the Glimmer, with minimal gas and revert on failure */
153-
(bool success, ) = to.call.value(amount)("");
152+
/* Send the Glimmer, with the gas limit configured in the comptroller. */
153+
uint16 gasAmount = comptroller.gasAmount();
154+
(bool success, ) = to.call.value(amount).gas(gasAmount)("");
154155
require(success, "Transfer failed");
155156
}
156157

contracts/tokensale/Address.sol

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.10;
3+
4+
/**
5+
* @dev Collection of functions related to the address type
6+
*/
7+
library Address {
8+
/**
9+
* @dev Returns true if `account` is a contract.
10+
*
11+
* [IMPORTANT]
12+
* ====
13+
* It is unsafe to assume that an address for which this function returns
14+
* false is an externally-owned account (EOA) and not a contract.
15+
*
16+
* Among others, `isContract` will return false for the following
17+
* types of addresses:
18+
*
19+
* - an externally-owned account
20+
* - a contract in construction
21+
* - an address where a contract will be created
22+
* - an address where a contract lived, but was destroyed
23+
* ====
24+
*
25+
* [IMPORTANT]
26+
* ====
27+
* You shouldn't rely on `isContract` to protect against flash loan attacks!
28+
*
29+
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
30+
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
31+
* constructor.
32+
* ====
33+
*/
34+
function isContract(address account) internal view returns (bool) {
35+
// This method relies on extcodesize/address.code.length, which returns 0
36+
// for contracts in construction, since the code is only stored at the end
37+
// of the constructor execution.
38+
39+
uint256 size;
40+
// solhint-disable-next-line no-inline-assembly
41+
assembly { size := extcodesize(account) }
42+
return size > 0;
43+
}
44+
45+
/**
46+
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
47+
* `recipient`, forwarding all available gas and reverting on errors.
48+
*
49+
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
50+
* of certain opcodes, possibly making contracts go over the 2300 gas limit
51+
* imposed by `transfer`, making them unable to receive funds via
52+
* `transfer`. {sendValue} removes this limitation.
53+
*
54+
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
55+
*
56+
* IMPORTANT: because control is transferred to `recipient`, care must be
57+
* taken to not create reentrancy vulnerabilities. Consider using
58+
* {ReentrancyGuard} or the
59+
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
60+
*/
61+
function sendValue(address payable recipient, uint256 amount) internal {
62+
require(address(this).balance >= amount, "Address: insufficient balance");
63+
64+
(bool success, ) = recipient.call{value: amount}("");
65+
require(success, "Address: unable to send value, recipient may have reverted");
66+
}
67+
68+
/**
69+
* @dev Performs a Solidity function call using a low level `call`. A
70+
* plain `call` is an unsafe replacement for a function call: use this
71+
* function instead.
72+
*
73+
* If `target` reverts with a revert reason, it is bubbled up by this
74+
* function (like regular Solidity function calls).
75+
*
76+
* Returns the raw returned data. To convert to the expected return value,
77+
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
78+
*
79+
* Requirements:
80+
*
81+
* - `target` must be a contract.
82+
* - calling `target` with `data` must not revert.
83+
*
84+
* _Available since v3.1._
85+
*/
86+
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
87+
return functionCall(target, data, "Address: low-level call failed");
88+
}
89+
90+
/**
91+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
92+
* `errorMessage` as a fallback revert reason when `target` reverts.
93+
*
94+
* _Available since v3.1._
95+
*/
96+
function functionCall(
97+
address target,
98+
bytes memory data,
99+
string memory errorMessage
100+
) internal returns (bytes memory) {
101+
return functionCallWithValue(target, data, 0, errorMessage);
102+
}
103+
104+
/**
105+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
106+
* but also transferring `value` wei to `target`.
107+
*
108+
* Requirements:
109+
*
110+
* - the calling contract must have an ETH balance of at least `value`.
111+
* - the called Solidity function must be `payable`.
112+
*
113+
* _Available since v3.1._
114+
*/
115+
function functionCallWithValue(
116+
address target,
117+
bytes memory data,
118+
uint256 value
119+
) internal returns (bytes memory) {
120+
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
121+
}
122+
123+
/**
124+
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
125+
* with `errorMessage` as a fallback revert reason when `target` reverts.
126+
*
127+
* _Available since v3.1._
128+
*/
129+
function functionCallWithValue(
130+
address target,
131+
bytes memory data,
132+
uint256 value,
133+
string memory errorMessage
134+
) internal returns (bytes memory) {
135+
require(address(this).balance >= value, "Address: insufficient balance for call");
136+
require(isContract(target), "Address: call to non-contract");
137+
138+
(bool success, bytes memory returndata) = target.call{value: value}(data);
139+
return verifyCallResult(success, returndata, errorMessage);
140+
}
141+
142+
/**
143+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
144+
* but performing a static call.
145+
*
146+
* _Available since v3.3._
147+
*/
148+
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
149+
return functionStaticCall(target, data, "Address: low-level static call failed");
150+
}
151+
152+
/**
153+
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
154+
* but performing a static call.
155+
*
156+
* _Available since v3.3._
157+
*/
158+
function functionStaticCall(
159+
address target,
160+
bytes memory data,
161+
string memory errorMessage
162+
) internal view returns (bytes memory) {
163+
require(isContract(target), "Address: static call to non-contract");
164+
165+
(bool success, bytes memory returndata) = target.staticcall(data);
166+
return verifyCallResult(success, returndata, errorMessage);
167+
}
168+
169+
/**
170+
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
171+
* but performing a delegate call.
172+
*
173+
* _Available since v3.4._
174+
*/
175+
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
176+
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
177+
}
178+
179+
/**
180+
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
181+
* but performing a delegate call.
182+
*
183+
* _Available since v3.4._
184+
*/
185+
function functionDelegateCall(
186+
address target,
187+
bytes memory data,
188+
string memory errorMessage
189+
) internal returns (bytes memory) {
190+
require(isContract(target), "Address: delegate call to non-contract");
191+
192+
(bool success, bytes memory returndata) = target.delegatecall(data);
193+
return verifyCallResult(success, returndata, errorMessage);
194+
}
195+
196+
/**
197+
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
198+
* revert reason using the provided one.
199+
*
200+
* _Available since v4.3._
201+
*/
202+
function verifyCallResult(
203+
bool success,
204+
bytes memory returndata,
205+
string memory errorMessage
206+
) internal pure returns (bytes memory) {
207+
if (success) {
208+
return returndata;
209+
} else {
210+
// Look for revert reason and bubble it up if present
211+
if (returndata.length > 0) {
212+
// The easiest way to bubble the revert reason is using memory via assembly
213+
214+
assembly {
215+
let returndata_size := mload(returndata)
216+
revert(add(32, returndata), returndata_size)
217+
}
218+
} else {
219+
revert(errorMessage);
220+
}
221+
}
222+
}
223+
}

0 commit comments

Comments
 (0)