Skip to content
Draft
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": "86709",
"add: with transfer": "108006",
"draw": "104177",
"eliminateDeficit: full": "72584",
"eliminateDeficit: partial": "82189",
"mintFeeShares": "82770",
"payFee": "70834",
"refreshPremium": "70391",
"remove: full": "75613",
"remove: partial": "80751",
"reportDeficit": "111899",
"restore: full": "76569",
"restore: full - with transfer": "169178",
"restore: partial": "85291",
"restore: partial - with transfer": "143271",
"transferShares": "69648"
"add": "66302",
"add: with transfer": "104699",
"draw": "103557",
"eliminateDeficit: full": "72132",
"eliminateDeficit: partial": "81737",
"mintFeeShares": "79937",
"payFee": "73447",
"refreshPremium": "69994",
"remove: full": "76553",
"remove: partial": "77397",
"reportDeficit": "121622",
"restore: full": "86292",
"restore: full - with transfer": "179323",
"restore: partial": "95014",
"restore: partial - with transfer": "152994",
"transferShares": "79061"
}
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": "227997",
"repayNative": "166265",
"supplyAsCollateralNative": "160205",
"supplyNative": "135802",
"withdrawNative: full": "125580",
"withdrawNative: partial": "136774"
"borrowNative": "227628",
"repayNative": "166396",
"supplyAsCollateralNative": "157359",
"supplyNative": "133156",
"withdrawNative: full": "124044",
"withdrawNative: partial": "133344"
}
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": "213175",
"repayWithSig": "186537",
"borrowWithSig": "212806",
"repayWithSig": "186668",
"setSelfAsUserPositionManagerWithSig": "75385",
"setUsingAsCollateralWithSig": "85409",
"supplyWithSig": "152034",
"supplyWithSig": "149388",
"updateUserDynamicConfigWithSig": "63129",
"updateUserRiskPremiumWithSig": "62099",
"withdrawWithSig": "130834"
"withdrawWithSig": "130612"
}
8 changes: 4 additions & 4 deletions snapshots/Spoke.Getters.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"getUserAccountData: supplies: 0, borrows: 0": "13005",
"getUserAccountData: supplies: 1, borrows: 0": "49355",
"getUserAccountData: supplies: 2, borrows: 0": "80991",
"getUserAccountData: supplies: 2, borrows: 1": "100457",
"getUserAccountData: supplies: 2, borrows: 2": "119226"
"getUserAccountData: supplies: 1, borrows: 0": "49279",
"getUserAccountData: supplies: 2, borrows: 0": "80839",
"getUserAccountData: supplies: 2, borrows: 1": "100414",
"getUserAccountData: supplies: 2, borrows: 2": "119292"
}
48 changes: 24 additions & 24 deletions snapshots/Spoke.Operations.ZeroRiskPremium.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"borrow: first": "189605",
"borrow: second action, same reserve": "169471",
"liquidationCall (receiveShares): full": "295608",
"liquidationCall (receiveShares): partial": "295326",
"liquidationCall: full": "305100",
"liquidationCall: partial": "304818",
"permitReserve + repay (multicall)": "164506",
"permitReserve + supply (multicall)": "146828",
"permitReserve + supply + enable collateral (multicall)": "161301",
"repay: full": "123800",
"repay: partial": "128770",
"borrow: first": "199334",
"borrow: second action, same reserve": "179200",
"liquidationCall (receiveShares): full": "304392",
"liquidationCall (receiveShares): partial": "304110",
"liquidationCall: full": "310567",
"liquidationCall: partial": "310285",
"permitReserve + repay (multicall)": "164528",
"permitReserve + supply (multicall)": "143521",
"permitReserve + supply + enable collateral (multicall)": "157994",
"repay: full": "123822",
"repay: partial": "128792",
"setUserPositionManagersWithSig: disable": "47039",
"setUserPositionManagersWithSig: enable": "68951",
"supply + enable collateral (multicall)": "141481",
"supply: 0 borrows, collateral disabled": "122874",
"supply: 0 borrows, collateral enabled": "105845",
"supply: second action, same reserve": "105774",
"supply + enable collateral (multicall)": "138174",
"supply: 0 borrows, collateral disabled": "119567",
"supply: 0 borrows, collateral enabled": "102538",
"supply: second action, same reserve": "102467",
"updateUserDynamicConfig: 1 collateral": "74603",
"updateUserDynamicConfig: 2 collaterals": "89520",
"updateUserRiskPremium: 1 borrow": "94940",
"updateUserRiskPremium: 2 borrows": "104075",
"updateUserRiskPremium: 1 borrow": "94973",
"updateUserRiskPremium: 2 borrows": "104910",
"usingAsCollateral: 0 borrows, enable": "59638",
"usingAsCollateral: 1 borrow, disable": "104981",
"usingAsCollateral: 1 borrow, disable": "105014",
"usingAsCollateral: 1 borrow, enable": "42526",
"usingAsCollateral: 2 borrows, disable": "126089",
"usingAsCollateral: 2 borrows, disable": "126231",
"usingAsCollateral: 2 borrows, enable": "42538",
"withdraw: 0 borrows, full": "127997",
"withdraw: 0 borrows, partial": "132732",
"withdraw: 1 borrow, partial": "159169",
"withdraw: 2 borrows, partial": "173287",
"withdraw: non collateral": "105920"
"withdraw: 0 borrows, full": "124061",
"withdraw: 0 borrows, partial": "129226",
"withdraw: 1 borrow, partial": "155266",
"withdraw: 2 borrows, partial": "169999",
"withdraw: non collateral": "102490"
}
48 changes: 24 additions & 24 deletions snapshots/Spoke.Operations.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"borrow: first": "258588",
"borrow: second action, same reserve": "201454",
"liquidationCall (receiveShares): full": "327696",
"liquidationCall (receiveShares): partial": "327414",
"liquidationCall: full": "337188",
"liquidationCall: partial": "336906",
"permitReserve + repay (multicall)": "161988",
"permitReserve + supply (multicall)": "146828",
"permitReserve + supply + enable collateral (multicall)": "161301",
"repay: full": "117879",
"repay: partial": "137249",
"borrow: first": "268029",
"borrow: second action, same reserve": "210895",
"liquidationCall (receiveShares): full": "336192",
"liquidationCall (receiveShares): partial": "335910",
"liquidationCall: full": "342367",
"liquidationCall: partial": "342085",
"permitReserve + repay (multicall)": "162006",
"permitReserve + supply (multicall)": "143521",
"permitReserve + supply + enable collateral (multicall)": "157994",
"repay: full": "117901",
"repay: partial": "137271",
"setUserPositionManagersWithSig: disable": "47039",
"setUserPositionManagersWithSig: enable": "68951",
"supply + enable collateral (multicall)": "141481",
"supply: 0 borrows, collateral disabled": "122874",
"supply: 0 borrows, collateral enabled": "105845",
"supply: second action, same reserve": "105774",
"supply + enable collateral (multicall)": "138174",
"supply: 0 borrows, collateral disabled": "119567",
"supply: 0 borrows, collateral enabled": "102538",
"supply: second action, same reserve": "102467",
"updateUserDynamicConfig: 1 collateral": "74603",
"updateUserDynamicConfig: 2 collaterals": "89520",
"updateUserRiskPremium: 1 borrow": "148344",
"updateUserRiskPremium: 2 borrows": "198096",
"updateUserRiskPremium: 1 borrow": "157899",
"updateUserRiskPremium: 2 borrows": "217975",
"usingAsCollateral: 0 borrows, enable": "59638",
"usingAsCollateral: 1 borrow, disable": "158385",
"usingAsCollateral: 1 borrow, disable": "167940",
"usingAsCollateral: 1 borrow, enable": "42526",
"usingAsCollateral: 2 borrows, disable": "228110",
"usingAsCollateral: 2 borrows, disable": "247296",
"usingAsCollateral: 2 borrows, enable": "42538",
"withdraw: 0 borrows, full": "127997",
"withdraw: 0 borrows, partial": "132732",
"withdraw: 1 borrow, partial": "210071",
"withdraw: 2 borrows, partial": "255841",
"withdraw: non collateral": "105920"
"withdraw: 0 borrows, full": "124061",
"withdraw: 0 borrows, partial": "129226",
"withdraw: 1 borrow, partial": "215690",
"withdraw: 2 borrows, partial": "251977",
"withdraw: non collateral": "102490"
}
54 changes: 27 additions & 27 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ contract Hub is IHub, AccessManaged {
decimals: decimals,
drawnRate: drawnRate.toUint96(),
irStrategy: irStrategy,
realizedFees: 0,
reinvestmentController: address(0),
feeReceiver: feeReceiver,
liquidityFee: 0
Expand All @@ -125,7 +124,7 @@ contract Hub is IHub, AccessManaged {
reinvestmentController: address(0)
})
);
emit UpdateAsset(assetId, drawnIndex, drawnRate, 0);
emit UpdateAsset(assetId, drawnIndex, drawnRate);

return assetId;
}
Expand All @@ -138,7 +137,7 @@ contract Hub is IHub, AccessManaged {
) external restricted {
require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];
asset.accrue();
asset.accrue(_spokes, assetId);

require(config.liquidityFee <= PercentageMath.PERCENTAGE_FACTOR, InvalidLiquidityFee());
require(config.feeReceiver != address(0) && config.irStrategy != address(0), InvalidAddress());
Expand Down Expand Up @@ -200,7 +199,7 @@ contract Hub is IHub, AccessManaged {
function setInterestRateData(uint256 assetId, bytes calldata irData) external restricted {
require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];
asset.accrue();
asset.accrue(_spokes, assetId);
IBasicInterestRateStrategy(asset.irStrategy).setInterestRateData(assetId, irData);
asset.updateDrawnRate(assetId);
}
Expand All @@ -209,7 +208,7 @@ contract Hub is IHub, AccessManaged {
function mintFeeShares(uint256 assetId) external restricted returns (uint256) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: determine if we want to keep this around, but doesnt seem necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mentioned that if there is no action for a while, we might want to manually trigger this, even with this kind of implementation

require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];
asset.accrue();
asset.accrue(_spokes, assetId);
uint256 feeShares = _mintFeeShares(asset, assetId);
asset.updateDrawnRate(assetId);
return feeShares;
Expand All @@ -220,7 +219,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateAdd(asset, spoke, amount);

uint256 liquidity = asset.liquidity + amount;
Expand All @@ -244,7 +243,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateRemove(spoke, amount, to);

uint256 liquidity = asset.liquidity;
Expand All @@ -269,7 +268,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateDraw(asset, spoke, amount, to);

uint256 liquidity = asset.liquidity;
Expand Down Expand Up @@ -298,7 +297,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateRestore(asset, spoke, drawnAmount, premiumDelta.restoredPremiumRay);

uint120 drawnShares = asset.toDrawnSharesDown(drawnAmount).toUint120();
Expand Down Expand Up @@ -328,7 +327,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateReportDeficit(asset, spoke, drawnAmount, premiumDelta.restoredPremiumRay);

uint120 drawnShares = asset.toDrawnSharesDown(drawnAmount).toUint120();
Expand Down Expand Up @@ -358,7 +357,7 @@ contract Hub is IHub, AccessManaged {
SpokeData storage callerSpoke = _spokes[assetId][msg.sender];
SpokeData storage coveredSpoke = _spokes[assetId][spoke];

asset.accrue();
asset.accrue(_spokes, assetId);
uint256 deficitRay = coveredSpoke.deficitRay;
uint256 deficitAmountRay = (amount < deficitRay.fromRayUp()) ? amount.toRay() : deficitRay;
_validateEliminateDeficit(callerSpoke, deficitAmountRay);
Expand All @@ -381,7 +380,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
SpokeData storage spoke = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
require(spoke.active, SpokeNotActive());
// no premium change allowed
require(premiumDelta.restoredPremiumRay == 0, InvalidPremiumChange());
Expand All @@ -398,7 +397,7 @@ contract Hub is IHub, AccessManaged {
SpokeData storage receiver = _spokes[assetId][feeReceiver];
SpokeData storage sender = _spokes[assetId][msg.sender];

asset.accrue();
asset.accrue(_spokes, assetId);
_validatePayFeeShares(sender, shares);
_transferShares(sender, receiver, shares);
asset.updateDrawnRate(assetId);
Expand All @@ -412,7 +411,7 @@ contract Hub is IHub, AccessManaged {
SpokeData storage sender = _spokes[assetId][msg.sender];
SpokeData storage receiver = _spokes[assetId][toSpoke];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateTransferShares(asset, sender, receiver, shares);
_transferShares(sender, receiver, shares);
asset.updateDrawnRate(assetId);
Expand All @@ -425,7 +424,7 @@ contract Hub is IHub, AccessManaged {
require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateSweep(asset, msg.sender, amount);

uint256 liquidity = asset.liquidity;
Expand All @@ -446,7 +445,7 @@ contract Hub is IHub, AccessManaged {
require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];

asset.accrue();
asset.accrue(_spokes, assetId);
_validateReclaim(asset, msg.sender, amount);

uint256 liquidity = asset.liquidity + amount;
Expand Down Expand Up @@ -599,12 +598,6 @@ contract Hub is IHub, AccessManaged {
});
}

/// @inheritdoc IHub
function getAssetAccruedFees(uint256 assetId) external view returns (uint256) {
Asset storage asset = _assets[assetId];
return asset.realizedFees + asset.getUnrealizedFees(asset.getDrawnIndex());
}

/// @inheritdoc IHub
function getAssetSwept(uint256 assetId) external view returns (uint256) {
return _assets[assetId].swept;
Expand All @@ -622,11 +615,20 @@ contract Hub is IHub, AccessManaged {

/// @inheritdoc IHubBase
function getSpokeAddedAssets(uint256 assetId, address spoke) external view returns (uint256) {
return _assets[assetId].toAddedAssetsDown(_spokes[assetId][spoke].addedShares);
IHub.Asset storage asset = _assets[assetId];
if (spoke == asset.feeReceiver) {
return
asset.toAddedAssetsDown(_spokes[assetId][spoke].addedShares + asset.unrealizedFeeShares());
}
return asset.toAddedAssetsDown(_spokes[assetId][spoke].addedShares);
}

/// @inheritdoc IHubBase
function getSpokeAddedShares(uint256 assetId, address spoke) external view returns (uint256) {
IHub.Asset storage asset = _assets[assetId];
if (spoke == asset.feeReceiver) {
return _spokes[assetId][spoke].addedShares + asset.unrealizedFeeShares();
}
return _spokes[assetId][spoke].addedShares;
}

Expand Down Expand Up @@ -780,8 +782,7 @@ contract Hub is IHub, AccessManaged {
}

function _mintFeeShares(Asset storage asset, uint256 assetId) internal returns (uint256) {
uint256 fees = asset.realizedFees;
uint120 shares = asset.toAddedSharesDown(fees).toUint120();
uint120 shares = asset.unrealizedFeeShares().toUint120();
if (shares == 0) {
return 0;
}
Expand All @@ -792,8 +793,7 @@ contract Hub is IHub, AccessManaged {

asset.addedShares += shares;
feeReceiverSpoke.addedShares += shares;
asset.realizedFees = 0;
emit MintFeeShares(assetId, feeReceiver, shares, fees);
emit MintFeeShares(assetId, feeReceiver, shares);

return shares;
}
Expand Down
Loading