Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions snapshots/Hub.Operations.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"add": "86703",
"add: with transfer": "108000",
"draw": "104159",
"eliminateDeficit: full": "72578",
"eliminateDeficit: partial": "82183",
"mintFeeShares": "82752",
"payFee": "70816",
"refreshPremium": "70373",
"remove: full": "75607",
"remove: partial": "80745",
"reportDeficit": "111893",
"restore: full": "76563",
"restore: full - with transfer": "169172",
"restore: partial": "85273",
"restore: partial - with transfer": "143253",
"transferShares": "69630"
"add": "86714",
"add: with transfer": "108011",
"draw": "104170",
"eliminateDeficit: full": "72567",
"eliminateDeficit: partial": "82172",
"mintFeeShares": "82763",
"payFee": "70827",
"refreshPremium": "70384",
"remove: full": "75618",
"remove: partial": "80756",
"reportDeficit": "111882",
"restore: full": "76574",
"restore: full - with transfer": "169601",
"restore: partial": "85284",
"restore: partial - with transfer": "143264",
"transferShares": "69641"
}
12 changes: 6 additions & 6 deletions snapshots/NativeTokenGateway.Operations.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"borrowNative": "228656",
"repayNative": "166471",
"supplyAsCollateralNative": "160133",
"supplyNative": "135762",
"withdrawNative: full": "125557",
"withdrawNative: partial": "136746"
"borrowNative": "229074",
"repayNative": "166878",
"supplyAsCollateralNative": "160144",
"supplyNative": "135771",
"withdrawNative: full": "125566",
"withdrawNative: partial": "136757"
}
8 changes: 4 additions & 4 deletions snapshots/SignatureGateway.Operations.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"borrowWithSig": "213889",
"repayWithSig": "186743",
"borrowWithSig": "214307",
"repayWithSig": "187150",
"setSelfAsUserPositionManagerWithSig": "75385",
"setUsingAsCollateralWithSig": "85387",
"supplyWithSig": "151994",
"supplyWithSig": "152003",
"updateUserDynamicConfigWithSig": "63120",
"updateUserRiskPremiumWithSig": "62090",
"withdrawWithSig": "130812"
"withdrawWithSig": "130820"
}
4 changes: 2 additions & 2 deletions snapshots/Spoke.Getters.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"getUserAccountData: supplies: 0, borrows: 0": "13014",
"getUserAccountData: supplies: 1, borrows: 0": "49426",
"getUserAccountData: supplies: 2, borrows: 0": "81102",
"getUserAccountData: supplies: 2, borrows: 1": "101531",
"getUserAccountData: supplies: 2, borrows: 2": "120791"
"getUserAccountData: supplies: 2, borrows: 1": "101729",
"getUserAccountData: supplies: 2, borrows: 2": "121187"
}
50 changes: 25 additions & 25 deletions snapshots/Spoke.Operations.ZeroRiskPremium.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"borrow: first": "190384",
"borrow: second action, same reserve": "170250",
"liquidationCall (receiveShares): full": "303257",
"liquidationCall (receiveShares): partial": "302675",
"liquidationCall (reportDeficit): full": "367686",
"liquidationCall: full": "320893",
"liquidationCall: partial": "320311",
"permitReserve + repay (multicall)": "164576",
"permitReserve + supply (multicall)": "146756",
"permitReserve + supply + enable collateral (multicall)": "161207",
"repay: full": "123914",
"repay: partial": "128872",
"borrow: first": "190593",
"borrow: second action, same reserve": "170459",
"liquidationCall (receiveShares): full": "303873",
"liquidationCall (receiveShares): partial": "303291",
"liquidationCall (reportDeficit): full": "368324",
"liquidationCall: full": "321520",
"liquidationCall: partial": "320938",
"permitReserve + repay (multicall)": "164785",
"permitReserve + supply (multicall)": "146767",
"permitReserve + supply + enable collateral (multicall)": "161218",
"repay: full": "124123",
"repay: partial": "129081",
"setUserPositionManagersWithSig: disable": "47039",
"setUserPositionManagersWithSig: enable": "68951",
"supply + enable collateral (multicall)": "141409",
"supply: 0 borrows, collateral disabled": "122846",
"supply: 0 borrows, collateral enabled": "105817",
"supply: second action, same reserve": "105746",
"supply + enable collateral (multicall)": "141420",
"supply: 0 borrows, collateral disabled": "122857",
"supply: 0 borrows, collateral enabled": "105828",
"supply: second action, same reserve": "105757",
"updateUserDynamicConfig: 1 collateral": "74545",
"updateUserDynamicConfig: 2 collaterals": "89413",
"updateUserRiskPremium: 1 borrow": "95734",
"updateUserRiskPremium: 2 borrows": "105414",
"updateUserRiskPremium: 1 borrow": "95932",
"updateUserRiskPremium: 2 borrows": "105810",
"usingAsCollateral: 0 borrows, enable": "59616",
"usingAsCollateral: 1 borrow, disable": "105778",
"usingAsCollateral: 1 borrow, disable": "105976",
"usingAsCollateral: 1 borrow, enable": "42504",
"usingAsCollateral: 2 borrows, disable": "127327",
"usingAsCollateral: 2 borrows, disable": "127723",
"usingAsCollateral: 2 borrows, enable": "42516",
"withdraw: 0 borrows, full": "127955",
"withdraw: 0 borrows, partial": "132851",
"withdraw: 1 borrow, partial": "159982",
"withdraw: 2 borrows, partial": "174540",
"withdraw: non collateral": "105902"
"withdraw: 0 borrows, full": "127966",
"withdraw: 0 borrows, partial": "132862",
"withdraw: 1 borrow, partial": "160191",
"withdraw: 2 borrows, partial": "174947",
"withdraw: non collateral": "105913"
}
50 changes: 25 additions & 25 deletions snapshots/Spoke.Operations.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"borrow: first": "259319",
"borrow: second action, same reserve": "202185",
"liquidationCall (receiveShares): full": "335301",
"liquidationCall (receiveShares): partial": "334719",
"liquidationCall (reportDeficit): full": "359886",
"liquidationCall: full": "352937",
"liquidationCall: partial": "352355",
"permitReserve + repay (multicall)": "162044",
"permitReserve + supply (multicall)": "146756",
"permitReserve + supply + enable collateral (multicall)": "161207",
"repay: full": "117993",
"repay: partial": "137351",
"borrow: first": "259737",
"borrow: second action, same reserve": "202603",
"liquidationCall (receiveShares): full": "336126",
"liquidationCall (receiveShares): partial": "335544",
"liquidationCall (reportDeficit): full": "360524",
"liquidationCall: full": "353773",
"liquidationCall: partial": "353191",
"permitReserve + repay (multicall)": "162212",
"permitReserve + supply (multicall)": "146767",
"permitReserve + supply + enable collateral (multicall)": "161218",
"repay: full": "118202",
"repay: partial": "137560",
"setUserPositionManagersWithSig: disable": "47039",
"setUserPositionManagersWithSig: enable": "68951",
"supply + enable collateral (multicall)": "141409",
"supply: 0 borrows, collateral disabled": "122846",
"supply: 0 borrows, collateral enabled": "105817",
"supply: second action, same reserve": "105746",
"supply + enable collateral (multicall)": "141420",
"supply: 0 borrows, collateral disabled": "122857",
"supply: 0 borrows, collateral enabled": "105828",
"supply: second action, same reserve": "105757",
"updateUserDynamicConfig: 1 collateral": "74545",
"updateUserDynamicConfig: 2 collaterals": "89413",
"updateUserRiskPremium: 1 borrow": "149093",
"updateUserRiskPremium: 2 borrows": "199355",
"updateUserRiskPremium: 1 borrow": "149500",
"updateUserRiskPremium: 2 borrows": "200169",
"usingAsCollateral: 0 borrows, enable": "59616",
"usingAsCollateral: 1 borrow, disable": "159134",
"usingAsCollateral: 1 borrow, disable": "159541",
"usingAsCollateral: 1 borrow, enable": "42504",
"usingAsCollateral: 2 borrows, disable": "229264",
"usingAsCollateral: 2 borrows, disable": "230078",
"usingAsCollateral: 2 borrows, enable": "42516",
"withdraw: 0 borrows, full": "127955",
"withdraw: 0 borrows, partial": "132851",
"withdraw: 1 borrow, partial": "210836",
"withdraw: 2 borrows, partial": "257012",
"withdraw: non collateral": "105902"
"withdraw: 0 borrows, full": "127966",
"withdraw: 0 borrows, partial": "132862",
"withdraw: 1 borrow, partial": "211254",
"withdraw: 2 borrows, partial": "257837",
"withdraw: non collateral": "105913"
}
8 changes: 7 additions & 1 deletion src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,16 @@ contract Hub is IHub, AccessManaged {
}

/// @inheritdoc IHubBase
function getAssetDrawnIndex(uint256 assetId) external view returns (uint256) {
function computeAssetDrawnIndex(uint256 assetId) external view returns (uint256) {
return _assets[assetId].getDrawnIndex();
}

/// @inheritdoc IHubBase
function computeAssetDrawnRate(uint256 assetId) external view returns (uint256) {
Asset storage asset = _assets[assetId];
return asset.getDrawnRate(assetId, asset.getDrawnIndex());
}

/// @inheritdoc IHubBase
function getAddedAssets(uint256 assetId) external view returns (uint256) {
return _assets[assetId].totalAddedAssets();
Expand Down
4 changes: 2 additions & 2 deletions src/hub/interfaces/IHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ interface IHub is IHubBase, IAccessManaged {
/// @return The amount of liquidity swept.
function getAssetSwept(uint256 assetId) external view returns (uint256);

/// @notice Returns the current drawn rate for the specified asset.
/// @notice Returns the last stored drawn rate for the specified asset.
/// @param assetId The identifier of the asset.
/// @return The current drawn rate of the asset.
/// @return The last stored drawn rate of the asset.
function getAssetDrawnRate(uint256 assetId) external view returns (uint256);

/// @notice Returns the number of spokes listed for the specified asset.
Expand Down
7 changes: 6 additions & 1 deletion src/hub/interfaces/IHubBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ interface IHubBase {
/// @notice Calculates the current drawn index for the specified asset.
/// @param assetId The identifier of the asset.
/// @return The current drawn index of the asset.
function getAssetDrawnIndex(uint256 assetId) external view returns (uint256);
function computeAssetDrawnIndex(uint256 assetId) external view returns (uint256);

/// @notice Calculates the current drawn rate for the specified asset.
/// @param assetId The identifier of the asset.
/// @return The current drawn rate of the asset.
function computeAssetDrawnRate(uint256 assetId) external view returns (uint256);

/// @notice Returns the total amount of the specified asset added to the Hub.
/// @param assetId The identifier of the asset.
Expand Down
28 changes: 19 additions & 9 deletions src/hub/libraries/AssetLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,10 @@ library AssetLogic {
}

/// @notice Updates the drawn rate of a specified asset.
/// @dev Premium debt is not used in the interest rate calculation.
/// @dev Uses last stored index; asset accrual should have already occurred.
/// @dev Imprecision from downscaling `deficitRay` does not accumulate.
function updateDrawnRate(IHub.Asset storage asset, uint256 assetId) internal {
uint256 drawnIndex = asset.drawnIndex;
uint256 newDrawnRate = IBasicInterestRateStrategy(asset.irStrategy).calculateInterestRate({
assetId: assetId,
liquidity: asset.liquidity,
drawn: asset.drawn(drawnIndex),
deficit: asset.deficitRay.fromRayUp(),
swept: asset.swept
});
uint256 newDrawnRate = asset.getDrawnRate(assetId, drawnIndex);
asset.drawnRate = newDrawnRate.toUint96();

emit IHub.UpdateAsset(assetId, drawnIndex, newDrawnRate, asset.realizedFees);
Expand Down Expand Up @@ -173,6 +165,24 @@ library AssetLogic {
);
}

/// @notice Calculates the latest drawn rate of a specified asset using the specified drawnIndex.
/// @dev Premium debt is not used in the interest rate calculation.
/// @dev Imprecision from downscaling `deficitRay` does not accumulate.
function getDrawnRate(
IHub.Asset storage asset,
uint256 assetId,
uint256 drawnIndex
) internal view returns (uint256) {
return
IBasicInterestRateStrategy(asset.irStrategy).calculateInterestRate({
assetId: assetId,
liquidity: asset.liquidity,
drawn: asset.drawn(drawnIndex),
deficit: asset.deficitRay.fromRayUp(),
swept: asset.swept
});
}

/// @notice Calculates the amount of fees derived from the index growth due to interest accrual.
/// @param drawnIndex The current drawn index.
function getUnrealizedFees(
Expand Down
4 changes: 2 additions & 2 deletions src/spoke/Spoke.sol
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ abstract contract Spoke is
UserPosition storage userPosition = _userPositions[onBehalfOf][reserveId];
_validateRepay(reserve.flags);

uint256 drawnIndex = reserve.hub.getAssetDrawnIndex(reserve.assetId);
uint256 drawnIndex = reserve.hub.computeAssetDrawnIndex(reserve.assetId);
(uint256 drawnDebtRestored, uint256 premiumDebtRayRestored) = userPosition
.calculateRestoreAmount(drawnIndex, amount);
uint256 restoredShares = drawnDebtRestored.rayDivDown(drawnIndex);
Expand Down Expand Up @@ -836,7 +836,7 @@ abstract contract Spoke is

IHubBase.PremiumDelta memory premiumDelta = userPosition.calculatePremiumDelta({
drawnSharesTaken: 0,
drawnIndex: hub.getAssetDrawnIndex(assetId),
drawnIndex: hub.computeAssetDrawnIndex(assetId),
riskPremium: newRiskPremium,
restoredPremiumRay: 0
});
Expand Down
4 changes: 2 additions & 2 deletions src/spoke/libraries/UserPositionDebt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ library UserPositionUtils {
IHubBase hub,
uint256 assetId
) internal view returns (uint256, uint256) {
return userPosition.getDebt(hub.getAssetDrawnIndex(assetId));
return userPosition.getDebt(hub.computeAssetDrawnIndex(assetId));
}

/// @return The user's drawn debt, expressed in asset units.
Expand All @@ -132,7 +132,7 @@ library UserPositionUtils {
IHubBase hub,
uint256 assetId
) internal view returns (DebtComponents memory) {
uint256 drawnIndex = hub.getAssetDrawnIndex(assetId);
uint256 drawnIndex = hub.computeAssetDrawnIndex(assetId);
return
DebtComponents({
drawnShares: userPosition.drawnShares,
Expand Down
4 changes: 2 additions & 2 deletions src/spoke/libraries/UserPositionUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ library UserPositionUtils {
IHubBase hub,
uint256 assetId
) internal view returns (uint256, uint256) {
return userPosition.getDebt(hub.getAssetDrawnIndex(assetId));
return userPosition.getDebt(hub.computeAssetDrawnIndex(assetId));
}

/// @return The user's drawn debt, expressed in asset units.
Expand All @@ -132,7 +132,7 @@ library UserPositionUtils {
IHubBase hub,
uint256 assetId
) internal view returns (DebtComponents memory) {
uint256 drawnIndex = hub.getAssetDrawnIndex(assetId);
uint256 drawnIndex = hub.computeAssetDrawnIndex(assetId);
return
DebtComponents({
drawnShares: userPosition.drawnShares,
Expand Down
10 changes: 5 additions & 5 deletions tests/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ abstract contract Base is Test {
) internal view returns (IHubBase.PremiumDelta memory) {
return
_getExpectedPremiumDelta({
drawnIndex: hub.getAssetDrawnIndex(assetId),
drawnIndex: hub.computeAssetDrawnIndex(assetId),
oldPremiumShares: oldPremiumShares,
oldPremiumOffsetRay: oldPremiumOffsetRay,
drawnShares: drawnShares,
Expand Down Expand Up @@ -1703,7 +1703,7 @@ abstract contract Base is Test {
uint256 assetId = spoke.getReserve(reserveId).assetId;
IHub hub = IHub(address(spoke.getReserve(reserveId).hub));

uint256 restoredShares = drawnDebtToRestore.rayDivDown(hub.getAssetDrawnIndex(assetId));
uint256 restoredShares = drawnDebtToRestore.rayDivDown(hub.computeAssetDrawnIndex(assetId));
uint256 riskPremium = _getUserLastRiskPremium(spoke, user);

return
Expand Down Expand Up @@ -2228,7 +2228,7 @@ abstract contract Base is Test {
uint256 premiumShares,
int256 premiumOffsetRay
) internal view returns (uint256) {
uint256 drawnIndex = hub.getAssetDrawnIndex(assetId);
uint256 drawnIndex = hub.computeAssetDrawnIndex(assetId);
return _calculatePremiumDebtRay(premiumShares, premiumOffsetRay, drawnIndex);
}

Expand Down Expand Up @@ -2286,7 +2286,7 @@ abstract contract Base is Test {
uint256 assetId,
uint256 premiumShares
) internal view returns (uint256) {
return _calculatePremiumAssetsRay(premiumShares, hub.getAssetDrawnIndex(assetId));
return _calculatePremiumAssetsRay(premiumShares, hub.computeAssetDrawnIndex(assetId));
}

/// @dev Helper function to withdraw fees from the treasury spoke
Expand Down Expand Up @@ -2423,7 +2423,7 @@ abstract contract Base is Test {
}

function _reserveDrawnIndex(ISpoke spoke, uint256 reserveId) internal view returns (uint256) {
return _hub(spoke, reserveId).getAssetDrawnIndex(_reserveAssetId(spoke, reserveId));
return _hub(spoke, reserveId).computeAssetDrawnIndex(_reserveAssetId(spoke, reserveId));
}

function _deploySpokeWithOracle(
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/MockSpoke.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ contract MockSpoke is Spoke, Test {
.toUint120();
_userPositions[user][info.debtReserveIds[i]].premiumOffsetRay =
(_userPositions[user][info.debtReserveIds[i]].premiumShares *
reserve.hub.getAssetDrawnIndex(reserve.assetId)).toInt256().toInt200() -
reserve.hub.computeAssetDrawnIndex(reserve.assetId)).toInt256().toInt200() -
(info.accruedPremiumAmounts[i] * WadRayMath.RAY).toInt256().toInt200() -
(info.realizedPremiumAmountsRay[i]).toInt256().toInt200();
}
Expand Down
Loading
Loading