Skip to content

Commit

Permalink
Merge pull request #792 from morpho-org/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinEgalite committed Jun 23, 2023
2 parents 9b99e65 + 852ad38 commit a315261
Show file tree
Hide file tree
Showing 40 changed files with 2,902 additions and 191 deletions.
11 changes: 0 additions & 11 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.5.2

[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = v4.8.2
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
branch = v4.8.2

[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/Rari-Capital/solmate
Expand All @@ -27,7 +17,6 @@
path = lib/aave-v3-periphery
url = https://github.com/aave/aave-v3-periphery
branch = v2.0.1

[submodule "lib/morpho-data-structures"]
path = lib/morpho-data-structures
url = https://github.com/morpho-dao/morpho-data-structures
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ test-integration:
test-internal:
@FOUNDRY_MATCH_CONTRACT=TestInternal make test

test-prod:
@FOUNDRY_MATCH_CONTRACT=TestProd make test

test-unit:
@FOUNDRY_MATCH_CONTRACT=TestUnit make test

Expand All @@ -39,6 +42,9 @@ test-integration-%:
test-internal-%:
@FOUNDRY_MATCH_TEST=$* make test-internal

test-prod-%:
@FOUNDRY_MATCH_TEST=$* make test-prod

test-unit-%:
@FOUNDRY_MATCH_TEST=$* make test-unit

Expand All @@ -55,6 +61,9 @@ test-integration/%:
test-internal/%:
@FOUNDRY_MATCH_CONTRACT=TestInternal$* make test

test-prod/%:
@FOUNDRY_MATCH_CONTRACT=TestProd$* make test

test-unit/%:
@FOUNDRY_MATCH_CONTRACT=TestUnit$* make test

Expand Down
Binary file added audits/spearbit-rm-bulker-vault-report.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions config/ConfigLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ struct Config {
library ConfigLib {
using stdJson for string;

string internal constant CHAIN_ID_PATH = "$.chainId";
string internal constant RPC_ALIAS_PATH = "$.rpcAlias";
string internal constant FORK_BLOCK_NUMBER_PATH = "$.forkBlockNumber";
string internal constant ADDRESSES_PROVIDER_PATH = "$.addressesProvider";
string internal constant WRAPPED_NATIVE_PATH = "$.wrappedNative";
string internal constant LSD_NATIVES_PATH = "$.lsdNatives";
string internal constant MARKETS_PATH = "$.markets";
string internal constant MORPHO_DAO_PATH = "$.morphoDao";
string internal constant MORPHO_ETH_PATH = "$.morphoEth";

function getAddress(Config storage config, string memory key) internal returns (address) {
return config.json.readAddress(string.concat("$.", key));
Expand All @@ -33,6 +35,10 @@ library ConfigLib {
}
}

function getChainId(Config storage config) internal returns (uint256) {
return config.json.readUint(CHAIN_ID_PATH);
}

function getRpcAlias(Config storage config) internal returns (string memory) {
return config.json.readString(RPC_ALIAS_PATH);
}
Expand All @@ -49,6 +55,10 @@ library ConfigLib {
return config.json.readAddress(MORPHO_DAO_PATH);
}

function getMorphoEth(Config storage config) internal returns (address) {
return config.json.readAddress(MORPHO_ETH_PATH);
}

function getWrappedNative(Config storage config) internal returns (address) {
return getAddress(config, config.json.readString(WRAPPED_NATIVE_PATH));
}
Expand Down
9 changes: 4 additions & 5 deletions config/Configured.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ contract Configured is StdChains {

VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));

Chain internal chain;
Config internal config;

address internal dai;
Expand All @@ -33,6 +32,10 @@ contract Configured is StdChains {
}
}

function _rpcAlias() internal virtual returns (string memory) {
return config.getRpcAlias();
}

function _initConfig() internal returns (Config storage) {
if (bytes(config.json).length == 0) {
string memory root = vm.projectRoot();
Expand All @@ -45,10 +48,6 @@ contract Configured is StdChains {
}

function _loadConfig() internal virtual {
string memory rpcAlias = config.getRpcAlias();

chain = getChain(rpcAlias);

dai = config.getAddress("DAI");
usdc = config.getAddress("USDC");
usdt = config.getAddress("USDT");
Expand Down
1 change: 1 addition & 0 deletions config/avalanche-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"chainId": 43114,
"rpcAlias": "avalanche",
"forkBlockNumber": 24800000,
"addressesProvider": "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb",
Expand Down
2 changes: 2 additions & 0 deletions config/ethereum-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"chainId": 1,
"rpcAlias": "mainnet",
"forkBlockNumber": 16841312,
"addressesProvider": "0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e",
"morphoDao": "0xcBa28b38103307Ec8dA98377ffF9816C164f9AFa",
"morphoEth": "0x33333aea097c193e66081E930c33020272b33333",
"DAI": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"USDC": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"USDT": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
Expand Down
2 changes: 1 addition & 1 deletion lib/morpho-utils
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from d00ace
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts-upgradeable
Submodule openzeppelin-contracts-upgradeable deleted from f6c4c9
5 changes: 2 additions & 3 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ config/=config/
@morpho-utils/=lib/morpho-utils/src/
@morpho-data-structures/=lib/morpho-data-structures/src/

@openzeppelin/=lib/openzeppelin-contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin/=lib/morpho-utils/lib/openzeppelin-contracts/
@openzeppelin-upgradeable/=lib/morpho-utils/lib/openzeppelin-contracts-upgradeable/contracts/

@aave-v3-core/=lib/aave-v3-core/contracts/
@aave-v3-periphery/=lib/aave-v3-periphery/contracts/
Expand Down
43 changes: 0 additions & 43 deletions src/RewardsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ import {Initializable} from "@openzeppelin-upgradeable/proxy/utils/Initializable
contract RewardsManager is IRewardsManager, Initializable {
using SafeCast for uint256;

/* STRUCTS */

struct UserAssetBalance {
address asset; // The rewarded asset (either aToken or debt token).
uint256 scaledBalance; // The user scaled balance of this asset (in asset decimals).
uint256 scaledTotalSupply; // The scaled total supply of this asset.
}

struct UserData {
uint104 index; // The user's index for a specific (asset, reward) pair.
uint128 accrued; // The user's accrued rewards for a specific (asset, reward) pair (in reward token decimals).
}

struct RewardData {
uint104 startingIndex; // The index from which the RewardsManager begins tracking the RewardsController's index.
uint104 index; // The current index for a specific reward token.
uint32 lastUpdateTimestamp; // The last timestamp the index was updated.
mapping(address => UserData) usersData; // Users data. user -> UserData
}

/* IMMUTABLES */

/// @dev The address of Aave's rewards controller.
Expand All @@ -55,29 +35,6 @@ contract RewardsManager is IRewardsManager, Initializable {
/// @dev The local data related to a given asset (either aToken or debt token). asset -> reward -> RewardData
mapping(address => mapping(address => RewardData)) internal _localAssetData;

/* EVENTS */

/// @dev Emitted when rewards of an asset are accrued on behalf of a user.
/// @param asset The address of the incentivized asset.
/// @param reward The address of the reward token.
/// @param user The address of the user that rewards are accrued on behalf of.
/// @param assetIndex The reward index for the asset (same as the user's index for this asset when the event is logged).
/// @param rewardsAccrued The amount of rewards accrued.
event Accrued(
address indexed asset, address indexed reward, address indexed user, uint256 assetIndex, uint256 rewardsAccrued
);

/* ERRORS */

/// @notice Thrown when only the main Morpho contract can call the function.
error OnlyMorpho();

/// @notice Thrown when an invalid asset is passed to accrue rewards.
error InvalidAsset();

/// @notice Thrown when the the zero address is passed as a parameter.
error AddressIsZero();

/* MODIFIERS */

/// @notice Prevents a user to call function allowed for the main Morpho contract only.
Expand Down

0 comments on commit a315261

Please sign in to comment.