Skip to content

Commit 02d0c45

Browse files
CheyenneAtapouravniculaeyan-manabsisDhairyaSethi
authored
feat: Consolidate Interfaces (#707)
Co-authored-by: Alexandru Niculae <[email protected]> Co-authored-by: YBM <[email protected]> Co-authored-by: Francesc Armengol Carrasco <[email protected]> Co-authored-by: DhairyaSethi <[email protected]>
1 parent c717934 commit 02d0c45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+847
-478
lines changed

snapshots/Hub.Operations.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"add": "119161",
3-
"draw": "112344",
4-
"refreshPremium": "100482",
5-
"remove: full": "79500",
6-
"remove: partial": "86000",
7-
"restore: full": "113578",
8-
"restore: partial": "119430"
3+
"draw": "112322",
4+
"refreshPremium": "100461",
5+
"remove: full": "79522",
6+
"remove: partial": "86022",
7+
"restore: full": "113622",
8+
"restore: partial": "119474"
99
}

snapshots/Spoke.Getters.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"getUserAccountData: supplies: 0, borrows: 0": "9361",
3-
"getUserAccountData: supplies: 1, borrows: 0": "44652",
4-
"getUserAccountData: supplies: 2, borrows: 0": "75071",
5-
"getUserAccountData: supplies: 2, borrows: 1": "98459",
6-
"getUserAccountData: supplies: 2, borrows: 2": "120403"
3+
"getUserAccountData: supplies: 1, borrows: 0": "44675",
4+
"getUserAccountData: supplies: 2, borrows: 0": "75117",
5+
"getUserAccountData: supplies: 2, borrows: 1": "98329",
6+
"getUserAccountData: supplies: 2, borrows: 2": "120097"
77
}

snapshots/Spoke.Operations.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"borrow: first": "257218",
3-
"borrow: second action, same reserve": "220690",
4-
"liquidationCall: full": "326531",
5-
"liquidationCall: partial": "349792",
6-
"permitReserve + repay (multicall)": "280092",
7-
"permitReserve + supply (multicall)": "140221",
8-
"permitReserve + supply + enable collateral (multicall)": "173706",
9-
"repay: full": "174490",
10-
"repay: partial": "238853",
11-
"setUserPositionManagerWithSig: disable": "38977",
12-
"setUserPositionManagerWithSig: enable": "63000",
13-
"supply + enable collateral (multicall)": "152140",
2+
"borrow: first": "257018",
3+
"borrow: second action, same reserve": "220490",
4+
"liquidationCall: full": "326113",
5+
"liquidationCall: partial": "349374",
6+
"permitReserve + repay (multicall)": "279760",
7+
"permitReserve + supply (multicall)": "140199",
8+
"permitReserve + supply + enable collateral (multicall)": "173682",
9+
"repay: full": "174381",
10+
"repay: partial": "238543",
11+
"setUserPositionManagerWithSig: disable": "38914",
12+
"setUserPositionManagerWithSig: enable": "62937",
13+
"supply + enable collateral (multicall)": "152138",
1414
"supply: 0 borrows, collateral disabled": "116034",
1515
"supply: 0 borrows, collateral enabled": "119181",
1616
"supply: 1 borrow": "119170",
1717
"supply: second action, same reserve": "102081",
1818
"updateUserDynamicConfig: 1 collateral": "53205",
1919
"updateUserDynamicConfig: 2 collaterals": "58499",
20-
"updateUserRiskPremium: 1 borrow": "143440",
21-
"updateUserRiskPremium: 2 borrows": "195186",
22-
"usingAsCollateral: 0 borrows, enable": "54026",
23-
"usingAsCollateral: 1 borrow, disable": "153666",
20+
"updateUserRiskPremium: 1 borrow": "143262",
21+
"updateUserRiskPremium: 2 borrows": "194807",
22+
"usingAsCollateral: 0 borrows, enable": "54024",
23+
"usingAsCollateral: 1 borrow, disable": "153486",
2424
"usingAsCollateral: 1 borrow, enable": "24786",
25-
"withdraw: 0 borrows, full": "133563",
26-
"withdraw: 0 borrows, partial": "135666",
27-
"withdraw: 1 borrow, partial": "252635"
25+
"withdraw: 0 borrows, full": "133631",
26+
"withdraw: 0 borrows, partial": "135734",
27+
"withdraw: 1 borrow, partial": "252502"
2828
}

src/contracts/AssetInterestRateStrategy.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {IAssetInterestRateStrategy, IBasicInterestRateStrategy} from 'src/interf
99
* @title AssetInterestRateStrategy contract
1010
* @author Aave Labs
1111
* @notice Asset interest rate strategy used by the Aave protocol
12-
* @dev Strategies are hub-specific, due to the usage of asset id as index of the _interestRateData.
12+
* @dev Strategies are hub-specific, due to the usage of asset identifier as index of the _interestRateData.
1313
*/
1414
contract AssetInterestRateStrategy is IAssetInterestRateStrategy {
1515
using WadRayMath for *;
@@ -36,7 +36,12 @@ contract AssetInterestRateStrategy is IAssetInterestRateStrategy {
3636
HUB = hub_;
3737
}
3838

39-
/// @inheritdoc IAssetInterestRateStrategy
39+
/**
40+
* @notice Sets the interest rate parameters for a specified asset.
41+
* @dev data contains bps values encoded in bytes.
42+
* @param assetId The identifier of the asset.
43+
* @param data The encoded parameters used to configure the interest rate of the asset.
44+
*/
4045
function setInterestRateData(uint256 assetId, bytes calldata data) external {
4146
require(HUB == msg.sender, OnlyHub());
4247
InterestRateData memory rateData = abi.decode(data, (InterestRateData));

src/contracts/Hub.sol

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {MathUtils} from 'src/libraries/math/MathUtils.sol';
1717
import {Constants} from 'src/libraries/helpers/Constants.sol';
1818

1919
import {IHubBase, IHub} from 'src/interfaces/IHub.sol';
20-
import {IAssetInterestRateStrategy} from 'src/interfaces/IAssetInterestRateStrategy.sol';
20+
import {IBasicInterestRateStrategy} from 'src/interfaces/IBasicInterestRateStrategy.sol';
2121

2222
contract Hub is IHub, AccessManaged {
2323
using EnumerableSet for EnumerableSet.AddressSet;
@@ -59,8 +59,8 @@ contract Hub is IHub, AccessManaged {
5959
require(decimals <= Constants.MAX_ALLOWED_ASSET_DECIMALS, InvalidAssetDecimals());
6060

6161
uint256 assetId = _assetCount++;
62-
IAssetInterestRateStrategy(irStrategy).setInterestRateData(assetId, data);
63-
uint256 drawnRate = IAssetInterestRateStrategy(irStrategy).calculateInterestRate({
62+
IBasicInterestRateStrategy(irStrategy).setInterestRateData(assetId, data);
63+
uint256 drawnRate = IBasicInterestRateStrategy(irStrategy).calculateInterestRate({
6464
assetId: assetId,
6565
liquidity: 0,
6666
drawn: 0,
@@ -171,7 +171,7 @@ contract Hub is IHub, AccessManaged {
171171
function setInterestRateData(uint256 assetId, bytes calldata data) external restricted {
172172
DataTypes.Asset storage asset = _assets[assetId];
173173
asset.accrue(assetId, _spokes[assetId][asset.feeReceiver]);
174-
IAssetInterestRateStrategy(asset.irStrategy).setInterestRateData(assetId, data);
174+
IBasicInterestRateStrategy(asset.irStrategy).setInterestRateData(assetId, data);
175175
asset.updateDrawnRate(assetId);
176176
}
177177

@@ -276,7 +276,7 @@ contract Hub is IHub, AccessManaged {
276276
return drawnShares;
277277
}
278278

279-
/// @inheritdoc IHub
279+
/// @inheritdoc IHubBase
280280
function reportDeficit(
281281
uint256 assetId,
282282
uint256 drawnAmount,
@@ -326,7 +326,7 @@ contract Hub is IHub, AccessManaged {
326326
return shares;
327327
}
328328

329-
/// @inheritdoc IHub
329+
/// @inheritdoc IHubBase
330330
function refreshPremium(uint256 assetId, DataTypes.PremiumDelta calldata premiumDelta) external {
331331
DataTypes.Asset storage asset = _assets[assetId];
332332
DataTypes.SpokeData storage spoke = _spokes[assetId][msg.sender];
@@ -342,7 +342,7 @@ contract Hub is IHub, AccessManaged {
342342
emit RefreshPremium(assetId, msg.sender, premiumDelta);
343343
}
344344

345-
/// @inheritdoc IHub
345+
/// @inheritdoc IHubBase
346346
function payFee(uint256 assetId, uint256 shares) external {
347347
DataTypes.SpokeData storage sender = _spokes[assetId][msg.sender];
348348
address feeReceiver = _assets[assetId].feeReceiver;
@@ -413,6 +413,12 @@ contract Hub is IHub, AccessManaged {
413413
return _assets[assetId];
414414
}
415415

416+
/// @inheritdoc IHubBase
417+
function getAssetUnderlyingAndDecimals(uint256 assetId) external view returns (address, uint8) {
418+
DataTypes.Asset storage asset = _assets[assetId];
419+
return (asset.underlying, asset.decimals);
420+
}
421+
416422
/// @inheritdoc IHub
417423
function getSpokeCount(uint256 assetId) external view returns (uint256) {
418424
return _assetToSpokes[assetId].length();
@@ -441,50 +447,46 @@ contract Hub is IHub, AccessManaged {
441447
uint256 assetId,
442448
address spoke
443449
) external view returns (DataTypes.SpokeConfig memory) {
444-
return
445-
DataTypes.SpokeConfig({
446-
active: _spokes[assetId][spoke].active,
447-
addCap: _spokes[assetId][spoke].addCap,
448-
drawCap: _spokes[assetId][spoke].drawCap
449-
});
450+
DataTypes.SpokeData storage spoke = _spokes[assetId][spoke];
451+
return DataTypes.SpokeConfig(spoke.active, spoke.addCap, spoke.drawCap);
450452
}
451453

452-
/// @inheritdoc IHub
454+
/// @inheritdoc IHubBase
453455
function previewAddByAssets(uint256 assetId, uint256 assets) public view returns (uint256) {
454456
return _assets[assetId].toAddedSharesDown(assets);
455457
}
456458

457-
/// @inheritdoc IHub
459+
/// @inheritdoc IHubBase
458460
function previewAddByShares(uint256 assetId, uint256 shares) public view returns (uint256) {
459461
return _assets[assetId].toAddedAssetsUp(shares);
460462
}
461463

462-
/// @inheritdoc IHub
464+
/// @inheritdoc IHubBase
463465
function previewRemoveByAssets(uint256 assetId, uint256 assets) public view returns (uint256) {
464466
return _assets[assetId].toAddedSharesUp(assets);
465467
}
466468

467-
/// @inheritdoc IHub
469+
/// @inheritdoc IHubBase
468470
function previewRemoveByShares(uint256 assetId, uint256 shares) public view returns (uint256) {
469471
return _assets[assetId].toAddedAssetsDown(shares);
470472
}
471473

472-
/// @inheritdoc IHub
474+
/// @inheritdoc IHubBase
473475
function previewDrawByAssets(uint256 assetId, uint256 assets) public view returns (uint256) {
474476
return _assets[assetId].toDrawnSharesUp(assets);
475477
}
476478

477-
/// @inheritdoc IHub
479+
/// @inheritdoc IHubBase
478480
function previewDrawByShares(uint256 assetId, uint256 shares) external view returns (uint256) {
479481
return _assets[assetId].toDrawnAssetsDown(shares);
480482
}
481483

482-
/// @inheritdoc IHub
484+
/// @inheritdoc IHubBase
483485
function previewRestoreByAssets(uint256 assetId, uint256 assets) public view returns (uint256) {
484486
return _assets[assetId].toDrawnSharesDown(assets);
485487
}
486488

487-
/// @inheritdoc IHub
489+
/// @inheritdoc IHubBase
488490
function previewRestoreByShares(uint256 assetId, uint256 shares) public view returns (uint256) {
489491
return _assets[assetId].toDrawnAssetsUp(shares);
490492
}
@@ -514,45 +516,78 @@ contract Hub is IHub, AccessManaged {
514516
return _assets[assetId].getDrawnIndex();
515517
}
516518

519+
/// @inheritdoc IHubBase
517520
function getAssetOwed(uint256 assetId) external view returns (uint256, uint256) {
518521
DataTypes.Asset storage asset = _assets[assetId];
519522
return (asset.drawn(), asset.premium());
520523
}
521524

525+
/// @inheritdoc IHubBase
522526
function getAssetTotalOwed(uint256 assetId) external view returns (uint256) {
523527
return _assets[assetId].totalOwed();
524528
}
525529

530+
/// @inheritdoc IHubBase
531+
function getAssetDrawnShares(uint256 assetId) external view returns (uint256) {
532+
return _assets[assetId].drawnShares;
533+
}
534+
535+
/// @inheritdoc IHubBase
536+
function getAssetPremiumData(uint256 assetId) external view returns (uint256, uint256, uint256) {
537+
DataTypes.Asset storage asset = _assets[assetId];
538+
return (asset.premiumShares, asset.premiumOffset, asset.realizedPremium);
539+
}
540+
541+
/// @inheritdoc IHubBase
526542
function getSpokeOwed(uint256 assetId, address spoke) external view returns (uint256, uint256) {
527543
DataTypes.SpokeData storage spokeData = _spokes[assetId][spoke];
528544
return (_getSpokeDrawn(spokeData, assetId), _getSpokePremium(spokeData, assetId));
529545
}
530546

547+
/// @inheritdoc IHubBase
531548
function getSpokeTotalOwed(uint256 assetId, address spoke) external view returns (uint256) {
532549
DataTypes.SpokeData storage spokeData = _spokes[assetId][spoke];
533550
return _getSpokeDrawn(spokeData, assetId) + _getSpokePremium(spokeData, assetId);
534551
}
535552

553+
/// @inheritdoc IHubBase
554+
function getSpokeDrawnShares(uint256 assetId, address spoke) external view returns (uint256) {
555+
return _spokes[assetId][spoke].drawnShares;
556+
}
557+
558+
/// @inheritdoc IHubBase
559+
function getSpokePremiumData(
560+
uint256 assetId,
561+
address spoke
562+
) external view returns (uint256, uint256, uint256) {
563+
DataTypes.SpokeData storage spokeData = _spokes[assetId][spoke];
564+
return (spokeData.premiumShares, spokeData.premiumOffset, spokeData.realizedPremium);
565+
}
566+
536567
function getAssetDrawnRate(uint256 assetId) external view returns (uint256) {
537568
return _assets[assetId].drawnRate;
538569
}
539570

540-
function getTotalAddedAssets(uint256 assetId) external view returns (uint256) {
571+
/// @inheritdoc IHubBase
572+
function getAssetAddedAmount(uint256 assetId) external view returns (uint256) {
541573
return _assets[assetId].totalAddedAssets();
542574
}
543575

544-
function getTotalAddedShares(uint256 assetId) external view returns (uint256) {
576+
/// @inheritdoc IHubBase
577+
function getAssetAddedShares(uint256 assetId) external view returns (uint256) {
545578
return _assets[assetId].totalAddedShares();
546579
}
547580

548-
function getSpokeAddedAmount(uint256 assetId, address spoke) external view returns (uint256) {
581+
/// @inheritdoc IHubBase
582+
function getSpokeAddedAssets(uint256 assetId, address spoke) external view returns (uint256) {
549583
DataTypes.Asset storage asset = _assets[assetId];
550584
uint256 unrealizedFeeShares;
551585
if (spoke == asset.feeReceiver) unrealizedFeeShares = asset.unrealizedFeeShares();
552586
return
553587
previewRemoveByShares(assetId, _spokes[assetId][spoke].addedShares + unrealizedFeeShares);
554588
}
555589

590+
/// @inheritdoc IHubBase
556591
function getSpokeAddedShares(uint256 assetId, address spoke) external view returns (uint256) {
557592
DataTypes.Asset storage asset = _assets[assetId];
558593
if (spoke == asset.feeReceiver) {
@@ -575,12 +610,13 @@ contract Hub is IHub, AccessManaged {
575610
}
576611

577612
function getAssetConfig(uint256 assetId) external view returns (DataTypes.AssetConfig memory) {
613+
DataTypes.Asset storage asset = _assets[assetId];
578614
return
579615
DataTypes.AssetConfig({
580-
feeReceiver: _assets[assetId].feeReceiver,
581-
liquidityFee: _assets[assetId].liquidityFee,
582-
irStrategy: _assets[assetId].irStrategy,
583-
reinvestmentController: _assets[assetId].reinvestmentController
616+
feeReceiver: asset.feeReceiver,
617+
liquidityFee: asset.liquidityFee,
618+
irStrategy: asset.irStrategy,
619+
reinvestmentController: asset.reinvestmentController
584620
});
585621
}
586622

@@ -589,9 +625,10 @@ contract Hub is IHub, AccessManaged {
589625
address spoke,
590626
DataTypes.SpokeConfig memory config
591627
) internal {
592-
_spokes[assetId][spoke].active = config.active;
593-
_spokes[assetId][spoke].addCap = config.addCap;
594-
_spokes[assetId][spoke].drawCap = config.drawCap;
628+
DataTypes.SpokeData storage spokeData = _spokes[assetId][spoke];
629+
spokeData.active = config.active;
630+
spokeData.addCap = config.addCap;
631+
spokeData.drawCap = config.drawCap;
595632
emit SpokeConfigUpdate(assetId, spoke, config);
596633
}
597634

0 commit comments

Comments
 (0)