Skip to content

Commit 63caec0

Browse files
authored
chore: rename to reinvestmentController, math utils tests (#637)
* fix: cleanup, math utils tests * fix: rename reinvestmentStrategy -> reinvestmentController * feat: position manager event naming consistency
1 parent 397c690 commit 63caec0

25 files changed

+240
-572
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ git-diff :
1919
gas-report :; forge test --mp 'tests/gas/**'
2020

2121
# Coverage
22-
coverage-base :; forge coverage --fuzz-runs 50 --report lcov --no-match-coverage "(scripts|tests|deployments|mocks|dependencies)"
22+
coverage-base :; forge coverage --fuzz-runs 50 --report lcov --no-match-coverage "(scripts|tests|deployments|mocks|dependencies|UnitPriceFeed)"
2323
coverage-clean :; lcov --rc derive_function_end_line=0 --remove ./lcov.info -o ./lcov.info.p --ignore-errors inconsistent
2424
coverage-report :; genhtml ./lcov.info.p -o report --branch-coverage --rc derive_function_end_line=0
2525
coverage-badge :; coverage=$$(awk -F '[<>]' '/headerCovTableEntryHi/{print $3}' ./report/index.html | sed 's/[^0-9.]//g' | head -n 1); \

src/contracts/Hub.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ contract Hub is IHub, AccessManaged {
8484
decimals: decimals,
8585
drawnRate: drawnRate.toUint96(),
8686
irStrategy: irStrategy,
87-
reinvestmentStrategy: address(0),
87+
reinvestmentController: address(0),
8888
feeReceiver: feeReceiver,
8989
liquidityFee: 0
9090
});
@@ -96,7 +96,7 @@ contract Hub is IHub, AccessManaged {
9696
feeReceiver: feeReceiver,
9797
liquidityFee: 0,
9898
irStrategy: irStrategy,
99-
reinvestmentStrategy: address(0)
99+
reinvestmentController: address(0)
100100
})
101101
);
102102
emit AssetUpdate(assetId, drawnIndex, drawnRate, lastUpdateTimestamp);
@@ -117,14 +117,14 @@ contract Hub is IHub, AccessManaged {
117117
require(config.feeReceiver != address(0), InvalidFeeReceiver());
118118
require(config.irStrategy != address(0), InvalidIrStrategy());
119119
require(
120-
config.reinvestmentStrategy != address(0) || asset.swept == 0,
121-
InvalidReinvestmentStrategy()
120+
config.reinvestmentController != address(0) || asset.swept == 0,
121+
InvalidReinvestmentController()
122122
);
123123

124124
asset.feeReceiver = config.feeReceiver;
125125
asset.liquidityFee = config.liquidityFee;
126126
asset.irStrategy = config.irStrategy;
127-
asset.reinvestmentStrategy = config.reinvestmentStrategy;
127+
asset.reinvestmentController = config.reinvestmentController;
128128

129129
asset.updateDrawnRate(assetId);
130130

@@ -361,7 +361,7 @@ contract Hub is IHub, AccessManaged {
361361
asset.swept += amount.toUint128();
362362
asset.updateDrawnRate(assetId);
363363

364-
IERC20(asset.underlying).safeTransfer(asset.reinvestmentStrategy, amount);
364+
IERC20(asset.underlying).safeTransfer(asset.reinvestmentController, amount);
365365

366366
emit Sweep(assetId, amount);
367367
}
@@ -376,7 +376,7 @@ contract Hub is IHub, AccessManaged {
376376
asset.swept -= amount.toUint128();
377377
asset.updateDrawnRate(assetId);
378378

379-
IERC20(asset.underlying).safeTransferFrom(asset.reinvestmentStrategy, address(this), amount);
379+
IERC20(asset.underlying).safeTransferFrom(asset.reinvestmentController, address(this), amount);
380380

381381
emit Reclaim(assetId, amount);
382382
}
@@ -574,7 +574,7 @@ contract Hub is IHub, AccessManaged {
574574
feeReceiver: _assets[assetId].feeReceiver,
575575
liquidityFee: _assets[assetId].liquidityFee,
576576
irStrategy: _assets[assetId].irStrategy,
577-
reinvestmentStrategy: _assets[assetId].reinvestmentStrategy
577+
reinvestmentController: _assets[assetId].reinvestmentController
578578
});
579579
}
580580

@@ -760,8 +760,8 @@ contract Hub is IHub, AccessManaged {
760760
address caller,
761761
uint256 amount
762762
) internal view {
763-
// sufficient check to disallow when strategy unset
764-
require(caller == asset.reinvestmentStrategy, OnlyReinvestmentStrategy());
763+
// sufficient check to disallow when controller unset
764+
require(caller == asset.reinvestmentController, OnlyReinvestmentController());
765765
require(amount > 0 && amount <= asset.liquidity, InvalidSweepAmount());
766766
}
767767

@@ -770,8 +770,8 @@ contract Hub is IHub, AccessManaged {
770770
address caller,
771771
uint256 amount
772772
) internal view {
773-
// sufficient check to disallow when strategy unset
774-
require(caller == asset.reinvestmentStrategy, OnlyReinvestmentStrategy());
773+
// sufficient check to disallow when controller unset
774+
require(caller == asset.reinvestmentController, OnlyReinvestmentController());
775775
require(amount > 0 && amount <= asset.swept, InvalidSweepAmount());
776776
}
777777
}

src/contracts/HubConfigurator.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ contract HubConfigurator is Ownable, IHubConfigurator {
126126
}
127127

128128
/// @inheritdoc IHubConfigurator
129-
function updateReinvestmentStrategy(
129+
function updateReinvestmentController(
130130
address hub,
131131
uint256 assetId,
132-
address reinvestmentStrategy
132+
address reinvestmentController
133133
) external override onlyOwner {
134134
IHub targetHub = IHub(hub);
135135
DataTypes.AssetConfig memory config = targetHub.getAssetConfig(assetId);
136-
config.reinvestmentStrategy = reinvestmentStrategy;
136+
config.reinvestmentController = reinvestmentController;
137137
targetHub.updateAssetConfig(assetId, config);
138138
}
139139

src/contracts/Spoke.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ contract Spoke is ISpoke, Multicall, AccessManaged {
173173
/// @inheritdoc ISpoke
174174
function updatePositionManager(address positionManager, bool active) external restricted {
175175
_positionManager[positionManager].active = active;
176-
emit PositionManagerUpdate(positionManager, active);
176+
emit UpdatePositionManager(positionManager, active);
177177
}
178178

179179
// /////

src/contracts/TreasurySpoke.sol

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,17 @@ contract TreasurySpoke is ITreasurySpoke, Ownable {
6262
}
6363

6464
/// @inheritdoc ISpokeBase
65-
function borrow(uint256 reserveId, uint256 amount, address) external {
66-
/// intentionally left blank
65+
function borrow(uint256, uint256, address) external pure {
66+
revert UnsupportedAction();
6767
}
6868

6969
/// @inheritdoc ISpokeBase
70-
function repay(uint256 reserveId, uint256 amount, address) external {
71-
/// intentionally left blank
70+
function repay(uint256, uint256, address) external pure {
71+
revert UnsupportedAction();
7272
}
7373

7474
/// @inheritdoc ISpokeBase
75-
function liquidationCall(
76-
uint256 collateralReserveId,
77-
uint256 debtReserveId,
78-
address user,
79-
uint256 debtToCover
80-
) external {
81-
/// intentionally left blank
75+
function liquidationCall(uint256, uint256, address, uint256) external pure {
76+
revert UnsupportedAction();
8277
}
8378
}

src/interfaces/IHub.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ interface IHub is IHubBase, IAccessManaged {
9696
error SurplusDeficitReported(uint256 amount);
9797
error SpokeNotActive();
9898
error InvalidFeeShares();
99-
error InvalidReinvestmentStrategy();
99+
error InvalidReinvestmentController();
100100
error InvalidSweepAmount();
101-
error OnlyReinvestmentStrategy();
101+
error OnlyReinvestmentController();
102102

103103
/**
104104
* @notice Adds a new asset to the hub.
@@ -205,16 +205,16 @@ interface IHub is IHubBase, IAccessManaged {
205205
function eliminateDeficit(uint256 assetId, uint256 amount) external returns (uint256);
206206

207207
/**
208-
* @notice Sweeps an amount of liquidity of the corresponding asset and sends it to the configured reinvestment strategy.
209-
* @dev The strategy handles the actual reinvestment of funds, redistribution of interest, and investment caps.
208+
* @notice Sweeps an amount of liquidity of the corresponding asset and sends it to the configured reinvestment controller.
209+
* @dev The controller handles the actual reinvestment of funds, redistribution of interest, and investment caps.
210210
* @param assetId The identifier of the asset.
211211
* @param amount The amount to sweep.
212212
*/
213213
function sweep(uint256 assetId, uint256 amount) external;
214214

215215
/**
216-
* @notice Reclaims an amount of liquidity of the corresponding asset from the configured reinvestment strategy.
217-
* @dev The strategy can only reclaim up to swept amount. All accrued interest is distributed offchain.
216+
* @notice Reclaims an amount of liquidity of the corresponding asset from the configured reinvestment controller.
217+
* @dev The controller can only reclaim up to swept amount. All accrued interest is distributed offchain.
218218
* @param assetId The identifier of the asset.
219219
* @param amount The amount to reclaim.
220220
*/

src/interfaces/IHubConfigurator.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ interface IHubConfigurator {
9797
function updateInterestRateStrategy(address hub, uint256 assetId, address irStrategy) external;
9898

9999
/**
100-
* @notice Updates the reinvestment strategy of an asset.
100+
* @notice Updates the reinvestment controller of an asset.
101101
* @param hub The address of the Hub contract.
102102
* @param assetId The identifier of the asset.
103-
* @param reinvestmentStrategy The new reinvestment strategy.
103+
* @param reinvestmentController The new reinvestment controller.
104104
*/
105-
function updateReinvestmentStrategy(
105+
function updateReinvestmentController(
106106
address hub,
107107
uint256 assetId,
108-
address reinvestmentStrategy
108+
address reinvestmentController
109109
) external;
110110

111111
/**

src/interfaces/ISpoke.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ interface ISpoke is ISpokeBase, IMulticall, IAccessManaged {
9090
* @param positionManager The address of the position manager.
9191
* @param active True if position manager has become active, false otherwise.
9292
*/
93-
event PositionManagerUpdate(address indexed positionManager, bool active);
93+
event UpdatePositionManager(address indexed positionManager, bool active);
9494

9595
event RefreshPremiumDebt(
9696
uint256 indexed reserveId,

src/interfaces/ITreasurySpoke.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {ISpokeBase} from 'src/interfaces/ISpokeBase.sol';
88
* @title ITreasurySpoke
99
*/
1010
interface ITreasurySpoke is ISpokeBase {
11+
error UnsupportedAction();
12+
1113
/**
1214
* @notice Supplies a specified amount of the underlying asset to a given reserve.
1315
* @dev The Hub pulls the underlying asset from the caller, so prior approval is required.

src/libraries/math/MathUtils.sol

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {WadRayMath} from './WadRayMath.sol';
55

66
/**
77
* @title MathUtils library
8-
* @author Aave
9-
* @notice Provides functions to perform linear and compounded interest calculations
8+
* @author Aave Labs
109
*/
1110
library MathUtils {
1211
using WadRayMath for uint256;
@@ -24,7 +23,6 @@ library MathUtils {
2423
uint256 rate,
2524
uint40 lastUpdateTimestamp
2625
) internal view returns (uint256) {
27-
//solium-disable-next-line
2826
uint256 result = rate * (block.timestamp - uint256(lastUpdateTimestamp));
2927
unchecked {
3028
result = result / SECONDS_PER_YEAR;
@@ -33,81 +31,14 @@ library MathUtils {
3331
return WadRayMath.RAY + result;
3432
}
3533

36-
/**
37-
* @notice Calculates the new weighted average given a current weighted average, the sum of the weights subtracted with a new value, weight.
38-
* @dev Add precision to weighted average & new value before calling this method.
39-
* @param currentWeightedAvg The base weighted average.
40-
* @param currentSumWeights The base sum of weights.
41-
* @param newValue The new value to add or subtract.
42-
* @param newValueWeight The weight of the new value.
43-
* @return newWeightedAvg The weighted average after the operation.
44-
* @return newSumWeights The sum of weights after operation, cannot be less than 0.
45-
*/
46-
function addToWeightedAverage(
47-
uint256 currentWeightedAvg,
48-
uint256 currentSumWeights,
49-
uint256 newValue,
50-
uint256 newValueWeight
51-
) internal pure returns (uint256, uint256) {
52-
// newWeightedAvg, newSumWeights
53-
54-
if (newValueWeight == 0) {
55-
return (currentWeightedAvg, currentSumWeights);
56-
}
57-
if (currentSumWeights == 0) {
58-
return (newValue, newValueWeight);
59-
}
60-
61-
uint256 newSumWeights = currentSumWeights + newValueWeight;
62-
uint256 newWeightedAvg = ((currentWeightedAvg * currentSumWeights) +
63-
(newValue * newValueWeight)) / newSumWeights; // newSumWeights cannot be zero when execution reaches here
64-
65-
return (newWeightedAvg, newSumWeights);
66-
}
67-
68-
/**
69-
* @notice Calculates the new weighted average given a current weighted average, the sum of the weights added with a new value, weight.
70-
* @dev Add precision to weighted average & new value before calling this method.
71-
* @param currentWeightedAvg The base weighted average.
72-
* @param currentSumWeights The base sum of weights.
73-
* @param newValue The new value to add or subtract.
74-
* @param newValueWeight The weight of the new value.
75-
* @return newWeightedAvg The weighted average after the operation.
76-
* @return newSumWeights The sum of weights after operation, cannot be less than 0.
77-
* @dev Reverts when newValueWeight is greater than currentSumWeights.
78-
* @dev Reverts when the newWeightedValue (weight * value) is greater than currentWeightedSum (currentSumWeights * currentWeightedAvg).
79-
*/
80-
function subtractFromWeightedAverage(
81-
uint256 currentWeightedAvg,
82-
uint256 currentSumWeights,
83-
uint256 newValue,
84-
uint256 newValueWeight
85-
) internal pure returns (uint256, uint256) {
86-
// newWeightedAvg, newSumWeights
87-
if (newValueWeight == 0) return (currentWeightedAvg, currentSumWeights);
88-
89-
if (currentSumWeights == newValueWeight) return (0, 0); // no change
90-
if (currentSumWeights < newValueWeight) revert();
91-
92-
uint256 newWeightedValue = newValue * newValueWeight;
93-
uint256 currentWeightedSum = currentWeightedAvg * currentSumWeights;
94-
95-
if (currentWeightedSum < newWeightedValue) revert();
96-
97-
uint256 newSumWeights = currentSumWeights - newValueWeight;
98-
uint256 newWeightedAvg = (currentWeightedSum - newWeightedValue) / newSumWeights;
99-
100-
return (newWeightedAvg, newSumWeights);
101-
}
102-
10334
/**
10435
* @notice Returns the minimum of two values.
10536
* @param a The first value to compare.
10637
* @param b The second value to compare.
10738
* @return result The minimum of the two values.
10839
*/
10940
function min(uint256 a, uint256 b) internal pure returns (uint256 result) {
110-
assembly {
41+
assembly ('memory-safe') {
11142
result := xor(b, mul(xor(a, b), lt(a, b)))
11243
}
11344
}

0 commit comments

Comments
 (0)