Skip to content

Commit d42678e

Browse files
committed
fix: remove feeShares from storage
1 parent 71524f8 commit d42678e

File tree

7 files changed

+75
-83
lines changed

7 files changed

+75
-83
lines changed

snapshots/Hub.Operations.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"add": "115905",
3-
"draw": "136122",
4-
"eliminateDeficit: full": "59894",
5-
"eliminateDeficit: partial": "69470",
6-
"payFee": "104887",
2+
"add": "113922",
3+
"draw": "122579",
4+
"eliminateDeficit: full": "57911",
5+
"eliminateDeficit: partial": "67487",
6+
"payFee": "69276",
77
"refreshPremium": "96807",
8-
"remove: full": "89351",
9-
"remove: partial": "82477",
10-
"reportDeficit": "145071",
11-
"restore: full": "109509",
12-
"restore: partial": "140039",
13-
"transferShares": "88677"
8+
"remove: full": "75842",
9+
"remove: partial": "80511",
10+
"reportDeficit": "109460",
11+
"restore: full": "90998",
12+
"restore: partial": "104428",
13+
"transferShares": "70166"
1414
}

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": "12164",
3-
"getUserAccountData: supplies: 1, borrows: 0": "49358",
4-
"getUserAccountData: supplies: 2, borrows: 0": "81667",
5-
"getUserAccountData: supplies: 2, borrows: 1": "102408",
6-
"getUserAccountData: supplies: 2, borrows: 2": "121803"
3+
"getUserAccountData: supplies: 1, borrows: 0": "49375",
4+
"getUserAccountData: supplies: 2, borrows: 0": "81701",
5+
"getUserAccountData: supplies: 2, borrows: 1": "102442",
6+
"getUserAccountData: supplies: 2, borrows: 2": "121837"
77
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"borrow: first": "230223",
3-
"borrow: second action, same reserve": "193644",
4-
"liquidationCall: full": "293534",
5-
"liquidationCall: partial": "358923",
6-
"permitReserve + repay (multicall)": "266777",
7-
"permitReserve + supply (multicall)": "142983",
8-
"permitReserve + supply + enable collateral (multicall)": "190335",
9-
"repay: full": "153645",
10-
"repay: partial": "178108",
2+
"borrow: first": "194629",
3+
"borrow: second action, same reserve": "175150",
4+
"liquidationCall: full": "291636",
5+
"liquidationCall: partial": "309871",
6+
"permitReserve + repay (multicall)": "231183",
7+
"permitReserve + supply (multicall)": "141000",
8+
"permitReserve + supply + enable collateral (multicall)": "176809",
9+
"repay: full": "153662",
10+
"repay: partial": "178125",
1111
"setUserPositionManagerWithSig: disable": "44918",
1212
"setUserPositionManagerWithSig: enable": "68947",
13-
"supply + enable collateral (multicall)": "168277",
14-
"supply: 0 borrows, collateral disabled": "117795",
15-
"supply: 0 borrows, collateral enabled": "134313",
16-
"supply: 1 borrow": "134305",
17-
"supply: second action, same reserve": "117213",
13+
"supply + enable collateral (multicall)": "154751",
14+
"supply: 0 borrows, collateral disabled": "115812",
15+
"supply: 0 borrows, collateral enabled": "120787",
16+
"supply: 1 borrow": "120779",
17+
"supply: second action, same reserve": "103687",
1818
"updateUserDynamicConfig: 1 collateral": "73761",
1919
"updateUserDynamicConfig: 2 collaterals": "88621",
20-
"updateUserRiskPremium: 1 borrow": "97380",
21-
"updateUserRiskPremium: 2 borrows": "110677",
20+
"updateUserRiskPremium: 1 borrow": "97397",
21+
"updateUserRiskPremium: 2 borrows": "110694",
2222
"usingAsCollateral: 0 borrows, enable": "58976",
23-
"usingAsCollateral: 1 borrow, disable": "107627",
23+
"usingAsCollateral: 1 borrow, disable": "107644",
2424
"usingAsCollateral: 1 borrow, enable": "32298",
25-
"usingAsCollateral: 2 borrows, disable": "130092",
25+
"usingAsCollateral: 2 borrows, disable": "130109",
2626
"usingAsCollateral: 2 borrows, enable": "41876",
27-
"withdraw: 0 borrows, full": "142070",
28-
"withdraw: 0 borrows, partial": "135094",
29-
"withdraw: 1 borrow, partial": "176197",
30-
"withdraw: 2 borrows, partial": "198650",
31-
"withdraw: non collateral": "136337"
27+
"withdraw: 0 borrows, full": "128578",
28+
"withdraw: 0 borrows, partial": "133162",
29+
"withdraw: 1 borrow, partial": "162722",
30+
"withdraw: 2 borrows, partial": "185175",
31+
"withdraw: non collateral": "117877"
3232
}

snapshots/Spoke.Operations.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"borrow: first": "300376",
3-
"borrow: second action, same reserve": "226797",
4-
"liquidationCall: full": "326904",
5-
"liquidationCall: partial": "392293",
6-
"permitReserve + repay (multicall)": "300140",
7-
"permitReserve + supply (multicall)": "142983",
8-
"permitReserve + supply + enable collateral (multicall)": "190335",
9-
"repay: full": "148286",
10-
"repay: partial": "211471",
2+
"borrow: first": "264782",
3+
"borrow: second action, same reserve": "208303",
4+
"liquidationCall: full": "325006",
5+
"liquidationCall: partial": "343241",
6+
"permitReserve + repay (multicall)": "264546",
7+
"permitReserve + supply (multicall)": "141000",
8+
"permitReserve + supply + enable collateral (multicall)": "176809",
9+
"repay: full": "148303",
10+
"repay: partial": "211488",
1111
"setUserPositionManagerWithSig: disable": "44918",
1212
"setUserPositionManagerWithSig: enable": "68947",
13-
"supply + enable collateral (multicall)": "168277",
14-
"supply: 0 borrows, collateral disabled": "117795",
15-
"supply: 0 borrows, collateral enabled": "134313",
16-
"supply: 1 borrow": "134305",
17-
"supply: second action, same reserve": "117213",
13+
"supply + enable collateral (multicall)": "154751",
14+
"supply: 0 borrows, collateral disabled": "115812",
15+
"supply: 0 borrows, collateral enabled": "120787",
16+
"supply: 1 borrow": "120779",
17+
"supply: second action, same reserve": "103687",
1818
"updateUserDynamicConfig: 1 collateral": "73761",
1919
"updateUserDynamicConfig: 2 collaterals": "88621",
20-
"updateUserRiskPremium: 1 borrow": "205825",
21-
"updateUserRiskPremium: 2 borrows": "295653",
20+
"updateUserRiskPremium: 1 borrow": "170231",
21+
"updateUserRiskPremium: 2 borrows": "241548",
2222
"usingAsCollateral: 0 borrows, enable": "58976",
23-
"usingAsCollateral: 1 borrow, disable": "216072",
23+
"usingAsCollateral: 1 borrow, disable": "180478",
2424
"usingAsCollateral: 1 borrow, enable": "32298",
25-
"usingAsCollateral: 2 borrows, disable": "325067",
25+
"usingAsCollateral: 2 borrows, disable": "270962",
2626
"usingAsCollateral: 2 borrows, enable": "41876",
27-
"withdraw: 0 borrows, full": "142070",
28-
"withdraw: 0 borrows, partial": "135094",
29-
"withdraw: 1 borrow, partial": "282142",
30-
"withdraw: 2 borrows, partial": "391126",
31-
"withdraw: non collateral": "136337"
27+
"withdraw: 0 borrows, full": "128578",
28+
"withdraw: 0 borrows, partial": "133162",
29+
"withdraw: 1 borrow, partial": "233056",
30+
"withdraw: 2 borrows, partial": "323529",
31+
"withdraw: non collateral": "117877"
3232
}

src/hub/Hub.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,10 @@ contract Hub is IHub, AccessManaged {
9393
decimals: decimals,
9494
drawnRate: drawnRate.toUint96(),
9595
irStrategy: irStrategy,
96+
feeAmount: 0,
9697
reinvestmentController: address(0),
9798
feeReceiver: feeReceiver,
98-
liquidityFee: 0,
99-
feeAmount: 0,
100-
feeShares: 0
99+
liquidityFee: 0
101100
});
102101
_addFeeReceiver(assetId, feeReceiver);
103102

@@ -578,14 +577,14 @@ contract Hub is IHub, AccessManaged {
578577
/// @inheritdoc IHubBase
579578
function getSpokeAddedAssets(uint256 assetId, address spoke) external view returns (uint256) {
580579
Asset storage asset = _assets[assetId];
581-
uint256 feeShares = spoke == asset.feeReceiver ? asset.feeShares : 0;
580+
uint256 feeShares = spoke == asset.feeReceiver ? asset.toAddedSharesDown(asset.feeAmount) : 0;
582581
return asset.toAddedAssetsDown(_spokes[assetId][spoke].addedShares + feeShares);
583582
}
584583

585584
/// @inheritdoc IHubBase
586585
function getSpokeAddedShares(uint256 assetId, address spoke) external view returns (uint256) {
587586
Asset storage asset = _assets[assetId];
588-
uint256 feeShares = spoke == asset.feeReceiver ? asset.feeShares : 0;
587+
uint256 feeShares = spoke == asset.feeReceiver ? asset.toAddedSharesDown(asset.feeAmount) : 0;
589588
return _spokes[assetId][spoke].addedShares + feeShares;
590589
}
591590

@@ -716,12 +715,11 @@ contract Hub is IHub, AccessManaged {
716715
}
717716

718717
function _mintFeeShares(Asset storage asset, uint256 assetId) internal {
719-
uint128 feeShares = asset.feeShares;
718+
uint128 feeShares = asset.toAddedSharesDown(asset.feeAmount).toUint128();
720719
address feeReceiver = asset.feeReceiver;
721720
asset.addedShares += feeShares;
722721
_spokes[assetId][feeReceiver].addedShares += feeShares;
723722
asset.feeAmount = 0;
724-
asset.feeShares = 0;
725723
emit IHub.AccrueFees(assetId, feeReceiver, feeShares);
726724
}
727725

src/hub/interfaces/IHub.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@ interface IHub is IHubBase, IAccessManaged {
2929
address underlying;
3030
//
3131
address irStrategy;
32+
uint96 feeAmount;
3233
//
3334
address reinvestmentController;
3435
//
3536
address feeReceiver;
3637
uint16 liquidityFee;
3738
uint8 decimals;
38-
//
39-
uint128 feeAmount;
40-
uint128 feeShares;
4139
}
4240

4341
struct AssetConfig {

src/hub/libraries/AssetLogic.sol

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ library AssetLogic {
7272

7373
/// @notice Returns the total added assets for the specified asset.
7474
function totalAddedAssets(IHub.Asset storage asset) internal view returns (uint256) {
75-
return asset.liquidity + asset.swept + asset.deficit + asset.totalOwed() - asset.feeAmount - asset.getUnrealizedFeeAmount(asset.getDrawnIndex());
75+
return
76+
asset.liquidity +
77+
asset.swept +
78+
asset.deficit +
79+
asset.totalOwed() -
80+
asset.feeAmount -
81+
asset.getUnrealizedFeeAmount(asset.getDrawnIndex());
7682
}
7783

7884
/// @notice Converts an amount of shares to the equivalent amount of added assets, rounding up.
@@ -129,20 +135,10 @@ library AssetLogic {
129135
return;
130136
}
131137

132-
uint256 assetsBefore = asset.totalAddedAssets();
133-
134138
uint256 newDrawnIndex = asset.getDrawnIndex();
135-
136-
uint256 feeAmount = asset.getUnrealizedFeeAmount(newDrawnIndex);
137-
asset.feeAmount += feeAmount.toUint128();
138-
uint256 feeShares = asset.toAddedSharesDown(feeAmount);
139-
asset.feeShares += feeShares.toUint128();
140-
139+
asset.feeAmount += asset.getUnrealizedFeeAmount(newDrawnIndex).toUint96();
141140
asset.drawnIndex = newDrawnIndex.toUint128();
142141
asset.lastUpdateTimestamp = block.timestamp.toUint32();
143-
144-
uint256 assetsAfter = asset.totalAddedAssets();
145-
require(assetsAfter == assetsBefore, "AssetLogic: total added assets mismatch");
146142
}
147143

148144
/// @notice Calculates the drawn index of a specified asset based on the existing drawn rate and index.

0 commit comments

Comments
 (0)