Skip to content

Commit 815a2d3

Browse files
authored
feat: liquidityFee input for addAsset in hubConfigurator (#918)
1 parent 886cbce commit 815a2d3

File tree

5 files changed

+82
-22
lines changed

5 files changed

+82
-22
lines changed

src/hub/HubConfigurator.sol

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
2424
address hub,
2525
address underlying,
2626
address feeReceiver,
27+
uint256 liquidityFee,
2728
address irStrategy,
2829
bytes calldata irData
2930
) external onlyOwner returns (uint256) {
30-
return
31-
IHub(hub).addAsset(
32-
underlying,
33-
IERC20Metadata(underlying).decimals(),
34-
feeReceiver,
35-
irStrategy,
36-
irData
37-
);
31+
IHub targetHub = IHub(hub);
32+
uint256 assetId = targetHub.addAsset(
33+
underlying,
34+
IERC20Metadata(underlying).decimals(),
35+
feeReceiver,
36+
irStrategy,
37+
irData
38+
);
39+
_updateLiquidityFee(targetHub, assetId, liquidityFee);
40+
return assetId;
3841
}
3942

4043
/// @inheritdoc IHubConfigurator
@@ -43,10 +46,14 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
4346
address underlying,
4447
uint8 decimals,
4548
address feeReceiver,
49+
uint256 liquidityFee,
4650
address irStrategy,
4751
bytes calldata irData
4852
) external onlyOwner returns (uint256) {
49-
return IHub(hub).addAsset(underlying, decimals, feeReceiver, irStrategy, irData);
53+
IHub targetHub = IHub(hub);
54+
uint256 assetId = targetHub.addAsset(underlying, decimals, feeReceiver, irStrategy, irData);
55+
_updateLiquidityFee(targetHub, assetId, liquidityFee);
56+
return assetId;
5057
}
5158

5259
/// @inheritdoc IHubConfigurator
@@ -55,10 +62,7 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
5562
uint256 assetId,
5663
uint256 liquidityFee
5764
) external onlyOwner {
58-
IHub targetHub = IHub(hub);
59-
IHub.AssetConfig memory config = targetHub.getAssetConfig(assetId);
60-
config.liquidityFee = liquidityFee.toUint16();
61-
targetHub.updateAssetConfig(assetId, config, new bytes(0));
65+
_updateLiquidityFee(IHub(hub), assetId, liquidityFee);
6266
}
6367

6468
/// @inheritdoc IHubConfigurator
@@ -288,4 +292,10 @@ contract HubConfigurator is Ownable2Step, IHubConfigurator {
288292
config.drawCap = drawCap.toUint56();
289293
hub.updateSpokeConfig(assetId, spoke, config);
290294
}
295+
296+
function _updateLiquidityFee(IHub hub, uint256 assetId, uint256 liquidityFee) internal {
297+
IHub.AssetConfig memory config = hub.getAssetConfig(assetId);
298+
config.liquidityFee = liquidityFee.toUint16();
299+
hub.updateAssetConfig(assetId, config, new bytes(0));
300+
}
291301
}

src/hub/interfaces/IHubConfigurator.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ interface IHubConfigurator {
1717
/// @param hub The address of the Hub contract.
1818
/// @param underlying The address of the underlying asset.
1919
/// @param feeReceiver The address of the fee receiver spoke.
20+
/// @param liquidityFee The liquidity fee of the asset, in BPS.
2021
/// @param irStrategy The address of the interest rate strategy contract.
2122
/// @param irData The interest rate data to apply to the given asset, encoded in bytes.
2223
/// @return The unique identifier of the added asset.
2324
function addAsset(
2425
address hub,
2526
address underlying,
2627
address feeReceiver,
28+
uint256 liquidityFee,
2729
address irStrategy,
2830
bytes calldata irData
2931
) external returns (uint256);
@@ -35,6 +37,7 @@ interface IHubConfigurator {
3537
/// @param underlying The address of the underlying asset.
3638
/// @param decimals The number of decimals of the asset.
3739
/// @param feeReceiver The address of the fee receiver spoke.
40+
/// @param liquidityFee The liquidity fee of the asset, in BPS.
3841
/// @param irStrategy The address of the interest rate strategy contract.
3942
/// @param irData The interest rate data to apply to the given asset, encoded in bytes.
4043
/// @return The unique identifier of the added asset.
@@ -43,6 +46,7 @@ interface IHubConfigurator {
4346
address underlying,
4447
uint8 decimals,
4548
address feeReceiver,
49+
uint256 liquidityFee,
4650
address irStrategy,
4751
bytes calldata irData
4852
) external returns (uint256);

tests/unit/HubConfigurator.t.sol

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ contract HubConfiguratorTest is HubBase {
4444
_addAsset({
4545
fetchErc20Decimals: vm.randomBool(),
4646
underlying: vm.randomAddress(),
47-
decimals: bound(vm.randomUint(), 0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS).toUint8(),
47+
decimals: vm
48+
.randomUint(
49+
Constants.MIN_ALLOWED_UNDERLYING_DECIMALS,
50+
Constants.MAX_ALLOWED_UNDERLYING_DECIMALS
51+
)
52+
.toUint8(),
4853
feeReceiver: vm.randomAddress(),
54+
liquidityFee: vm.randomUint(),
4955
interestRateStrategy: vm.randomAddress(),
5056
encodedIrData: encodedIrData
5157
});
@@ -59,6 +65,7 @@ contract HubConfiguratorTest is HubBase {
5965
underlying: vm.randomAddress(),
6066
decimals: 10,
6167
feeReceiver: vm.randomAddress(),
68+
liquidityFee: vm.randomUint(),
6269
interestRateStrategy: vm.randomAddress(),
6370
encodedIrData: abi.encode('invalid')
6471
});
@@ -69,6 +76,7 @@ contract HubConfiguratorTest is HubBase {
6976
address underlying,
7077
uint8 decimals,
7178
address feeReceiver,
79+
uint256 liquidityFee,
7280
address interestRateStrategy
7381
) public {
7482
assumeUnusedAddress(underlying);
@@ -77,6 +85,7 @@ contract HubConfiguratorTest is HubBase {
7785

7886
decimals = bound(decimals, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS + 1, type(uint8).max)
7987
.toUint8();
88+
liquidityFee = bound(liquidityFee, 0, PercentageMath.PERCENTAGE_FACTOR);
8089

8190
vm.expectRevert(IHub.InvalidAssetDecimals.selector, address(hub1));
8291
vm.prank(HUB_CONFIGURATOR_ADMIN);
@@ -85,6 +94,7 @@ contract HubConfiguratorTest is HubBase {
8594
underlying,
8695
decimals,
8796
feeReceiver,
97+
liquidityFee,
8898
interestRateStrategy,
8999
encodedIrData
90100
);
@@ -94,27 +104,58 @@ contract HubConfiguratorTest is HubBase {
94104
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
95105
address feeReceiver = makeAddr('newFeeReceiver');
96106
address interestRateStrategy = makeAddr('newIrStrategy');
107+
uint256 liquidityFee = vm.randomUint(0, PercentageMath.PERCENTAGE_FACTOR);
97108

98109
vm.expectRevert(IHub.InvalidAddress.selector, address(hub1));
99110
vm.prank(HUB_CONFIGURATOR_ADMIN);
100-
_addAsset(true, address(0), decimals, feeReceiver, interestRateStrategy, encodedIrData);
111+
_addAsset(
112+
true,
113+
address(0),
114+
decimals,
115+
feeReceiver,
116+
liquidityFee,
117+
interestRateStrategy,
118+
encodedIrData
119+
);
101120
}
102121

103122
function test_addAsset_revertsWith_InvalidAddress_irStrategy() public {
104123
address underlying = makeAddr('newUnderlying');
105124
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
106125
address feeReceiver = makeAddr('newFeeReceiver');
126+
uint256 liquidityFee = vm.randomUint(0, PercentageMath.PERCENTAGE_FACTOR);
107127

108128
vm.expectRevert(IHub.InvalidAddress.selector, address(hub1));
109129
vm.prank(HUB_CONFIGURATOR_ADMIN);
110-
_addAsset(true, underlying, decimals, feeReceiver, address(0), encodedIrData);
130+
_addAsset(true, underlying, decimals, feeReceiver, liquidityFee, address(0), encodedIrData);
131+
}
132+
133+
function test_addAsset_revertsWith_InvalidLiquidityFee() public {
134+
address underlying = makeAddr('newUnderlying');
135+
uint8 decimals = uint8(vm.randomUint(0, Constants.MAX_ALLOWED_UNDERLYING_DECIMALS));
136+
address feeReceiver = makeAddr('newFeeReceiver');
137+
address interestRateStrategy = address(new AssetInterestRateStrategy(address(hub1)));
138+
uint256 liquidityFee = vm.randomUint(PercentageMath.PERCENTAGE_FACTOR + 1, type(uint16).max);
139+
140+
vm.expectRevert(IHub.InvalidLiquidityFee.selector, address(hub1));
141+
vm.prank(HUB_CONFIGURATOR_ADMIN);
142+
_addAsset(
143+
false,
144+
underlying,
145+
decimals,
146+
feeReceiver,
147+
liquidityFee,
148+
interestRateStrategy,
149+
encodedIrData
150+
);
111151
}
112152

113153
function test_addAsset_fuzz(
114154
bool fetchErc20Decimals,
115155
address underlying,
116156
uint8 decimals,
117157
address feeReceiver,
158+
uint256 liquidityFee,
118159
uint16 optimalUsageRatio,
119160
uint32 baseVariableBorrowRate,
120161
uint32 variableRateSlope1,
@@ -129,6 +170,7 @@ contract HubConfiguratorTest is HubBase {
129170
Constants.MAX_ALLOWED_UNDERLYING_DECIMALS
130171
).toUint8();
131172
optimalUsageRatio = bound(optimalUsageRatio, MIN_OPTIMAL_RATIO, MAX_OPTIMAL_RATIO).toUint16();
173+
liquidityFee = bound(liquidityFee, 0, PercentageMath.PERCENTAGE_FACTOR);
132174

133175
baseVariableBorrowRate = bound(baseVariableBorrowRate, 0, MAX_BORROW_RATE / 3).toUint32();
134176
uint32 remainingAfterBase = MAX_BORROW_RATE.toUint32() - baseVariableBorrowRate;
@@ -152,7 +194,7 @@ contract HubConfiguratorTest is HubBase {
152194
);
153195

154196
IHub.AssetConfig memory expectedConfig = IHub.AssetConfig({
155-
liquidityFee: 0,
197+
liquidityFee: liquidityFee.toUint16(),
156198
feeReceiver: feeReceiver,
157199
irStrategy: interestRateStrategy,
158200
reinvestmentController: address(0)
@@ -172,12 +214,18 @@ contract HubConfiguratorTest is HubBase {
172214
)
173215
);
174216

217+
vm.expectCall(
218+
address(hub1),
219+
abi.encodeCall(IHub.updateAssetConfig, (hub1.getAssetCount(), expectedConfig, new bytes(0)))
220+
);
221+
175222
vm.prank(HUB_CONFIGURATOR_ADMIN);
176223
assetId = _addAsset(
177224
fetchErc20Decimals,
178225
underlying,
179226
decimals,
180227
feeReceiver,
228+
liquidityFee,
181229
interestRateStrategy,
182230
encodedIrData
183231
);
@@ -997,6 +1045,7 @@ contract HubConfiguratorTest is HubBase {
9971045
address underlying,
9981046
uint8 decimals,
9991047
address feeReceiver,
1048+
uint256 liquidityFee,
10001049
address interestRateStrategy,
10011050
bytes memory encodedIrData
10021051
) internal returns (uint256) {
@@ -1007,6 +1056,7 @@ contract HubConfiguratorTest is HubBase {
10071056
address(hub1),
10081057
underlying,
10091058
feeReceiver,
1059+
liquidityFee,
10101060
interestRateStrategy,
10111061
encodedIrData
10121062
);
@@ -1017,6 +1067,7 @@ contract HubConfiguratorTest is HubBase {
10171067
underlying,
10181068
decimals,
10191069
feeReceiver,
1070+
liquidityFee,
10201071
interestRateStrategy,
10211072
encodedIrData
10221073
);

tests/unit/Spoke/Spoke.Upgradeable.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ contract SpokeUpgradeableTest is SpokeBase {
200200

201201
function _getProxyInitializedVersion(address proxy) internal view returns (uint64) {
202202
bytes32 slotData = vm.load(proxy, INITIALIZABLE_STORAGE);
203-
console.log(uint256(slotData));
204203
return uint64(uint256(slotData) & ((1 << 64) - 1));
205204
}
206205

tests/unit/libraries/LiquidationLogic/LiquidationLogic.LiquidationAmounts.t.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,12 @@ contract LiquidationLogicLiquidationAmountsTest is LiquidationLogicBaseTest {
9494
) public {
9595
params = _bound(params);
9696
params.debtToCover = bound(params.debtToCover, params.debtReserveBalance, type(uint256).max);
97-
console.log('params.debtToCover', params.debtToCover);
9897
(
9998
uint256 expectedCollateralToLiquidate,
10099
uint256 expectedCollateralToLiquidator,
101100
uint256 expectedDebtToLiquidate
102101
) = _calculateRawLiquidationAmounts(params);
103102

104-
console.log('params.collateralAssetDecimals', params.collateralAssetDecimals);
105-
106103
params.collateralReserveBalance = bound(
107104
params.collateralReserveBalance,
108105
expectedCollateralToLiquidate + 1,
@@ -309,7 +306,6 @@ contract LiquidationLogicLiquidationAmountsTest is LiquidationLogicBaseTest {
309306
function _calculateRawLiquidationAmounts(
310307
LiquidationLogic.CalculateLiquidationAmountsParams memory params
311308
) internal returns (uint256, uint256, uint256) {
312-
console.log('_calculateRawLiquidationAmounts');
313309
uint256 liquidationBonus = liquidationLogicWrapper.calculateLiquidationBonus({
314310
healthFactorForMaxBonus: params.healthFactorForMaxBonus,
315311
liquidationBonusFactor: params.liquidationBonusFactor,

0 commit comments

Comments
 (0)