Skip to content
Closed
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": "69634",
"add: with transfer": "108031",
"draw": "111774",
"eliminateDeficit: full": "75503",
"eliminateDeficit: partial": "83138",
"mintFeeShares": "105283",
"payFee": "108553",
"refreshPremium": "72799",
"remove: full": "83259",
"remove: partial": "80768",
"reportDeficit": "153945",
"restore: full": "101515",
"restore: full - with transfer": "194074",
"restore: partial": "127337",
"restore: partial - with transfer": "185317",
"transferShares": "97067"
}
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": "233782",
"repayNative": "169207",
"supplyAsCollateralNative": "160230",
"supplyNative": "135822",
"withdrawNative: full": "127926",
"withdrawNative: partial": "137226"
}
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": "216960",
"repayWithSig": "189479",
"setSelfAsUserPositionManagerWithSig": "75385",
"setUsingAsCollateralWithSig": "85409",
"supplyWithSig": "152034",
"supplyWithSig": "152054",
"updateUserDynamicConfigWithSig": "63129",
"updateUserRiskPremiumWithSig": "62099",
"withdrawWithSig": "130834"
"withdrawWithSig": "134494"
}
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": "51790",
"getUserAccountData: supplies: 2, borrows: 0": "85861",
"getUserAccountData: supplies: 2, borrows: 1": "107414",
"getUserAccountData: supplies: 2, borrows: 2": "128270"
}
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": "217073",
"borrow: second action, same reserve": "196826",
"liquidationCall (receiveShares): full": "344698",
"liquidationCall (receiveShares): partial": "344416",
"liquidationCall: full": "351885",
"liquidationCall: partial": "351603",
"permitReserve + repay (multicall)": "167361",
"permitReserve + supply (multicall)": "146853",
"permitReserve + supply + enable collateral (multicall)": "161326",
"repay: full": "126655",
"repay: partial": "131625",
"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)": "141506",
"supply: 0 borrows, collateral disabled": "122899",
"supply: 0 borrows, collateral enabled": "105870",
"supply: second action, same reserve": "105799",
"updateUserDynamicConfig: 1 collateral": "74603",
"updateUserDynamicConfig: 2 collaterals": "89520",
"updateUserRiskPremium: 1 borrow": "94940",
"updateUserRiskPremium: 2 borrows": "104075",
"updateUserRiskPremium: 1 borrow": "97244",
"updateUserRiskPremium: 2 borrows": "106361",
"usingAsCollateral: 0 borrows, enable": "59638",
"usingAsCollateral: 1 borrow, disable": "104981",
"usingAsCollateral: 1 borrow, disable": "107285",
"usingAsCollateral: 1 borrow, enable": "42526",
"usingAsCollateral: 2 borrows, disable": "126089",
"usingAsCollateral: 2 borrows, disable": "128375",
"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": "131165",
"withdraw: 0 borrows, partial": "133619",
"withdraw: 1 borrow, partial": "162754",
"withdraw: 2 borrows, partial": "176243",
"withdraw: non collateral": "106372"
}
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": "283751",
"borrow: second action, same reserve": "226504",
"liquidationCall (receiveShares): full": "357381",
"liquidationCall (receiveShares): partial": "357099",
"liquidationCall: full": "364568",
"liquidationCall: partial": "364286",
"permitReserve + repay (multicall)": "164272",
"permitReserve + supply (multicall)": "146853",
"permitReserve + supply + enable collateral (multicall)": "161326",
"repay: full": "120734",
"repay: partial": "140104",
"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)": "141506",
"supply: 0 borrows, collateral disabled": "122899",
"supply: 0 borrows, collateral enabled": "105870",
"supply: second action, same reserve": "105799",
"updateUserDynamicConfig: 1 collateral": "74603",
"updateUserDynamicConfig: 2 collaterals": "89520",
"updateUserRiskPremium: 1 borrow": "148344",
"updateUserRiskPremium: 2 borrows": "198096",
"updateUserRiskPremium: 1 borrow": "195116",
"updateUserRiskPremium: 2 borrows": "287318",
"usingAsCollateral: 0 borrows, enable": "59638",
"usingAsCollateral: 1 borrow, disable": "158385",
"usingAsCollateral: 1 borrow, disable": "205157",
"usingAsCollateral: 1 borrow, enable": "42526",
"usingAsCollateral: 2 borrows, disable": "228110",
"usingAsCollateral: 2 borrows, disable": "319332",
"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": "131165",
"withdraw: 0 borrows, partial": "133619",
"withdraw: 1 borrow, partial": "258124",
"withdraw: 2 borrows, partial": "261892",
"withdraw: non collateral": "106372"
}
62 changes: 16 additions & 46 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ contract Hub is IHub, AccessManaged {
uint256 lastUpdateTimestamp = block.timestamp;
_assets[assetId] = Asset({
liquidity: 0,
realizedFeesRay: 0,
deficitRay: 0,
swept: 0,
addedShares: 0,
Expand All @@ -108,7 +109,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 +125,7 @@ contract Hub is IHub, AccessManaged {
reinvestmentController: address(0)
})
);
emit UpdateAsset(assetId, drawnIndex, drawnRate, 0);
emit UpdateAsset(assetId, drawnIndex, drawnRate);

return assetId;
}
Expand All @@ -152,7 +152,6 @@ contract Hub is IHub, AccessManaged {

address oldFeeReceiver = asset.feeReceiver;
if (oldFeeReceiver != config.feeReceiver) {
_mintFeeShares(asset, assetId);
IHub.SpokeConfig memory spokeConfig;
spokeConfig.active = _spokes[assetId][oldFeeReceiver].active;
spokeConfig.halted = _spokes[assetId][oldFeeReceiver].halted;
Expand All @@ -168,7 +167,7 @@ contract Hub is IHub, AccessManaged {
require(irData.length == 0, InvalidInterestRateStrategy());
}

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit UpdateAssetConfig(assetId, config);
}
Expand Down Expand Up @@ -202,17 +201,7 @@ contract Hub is IHub, AccessManaged {
Asset storage asset = _assets[assetId];
asset.accrue();
IBasicInterestRateStrategy(asset.irStrategy).setInterestRateData(assetId, irData);
asset.updateDrawnRate(assetId);
}

/// @inheritdoc IHub
function mintFeeShares(uint256 assetId) external restricted returns (uint256) {
require(assetId < _assetCount, AssetNotListed());
Asset storage asset = _assets[assetId];
asset.accrue();
uint256 feeShares = _mintFeeShares(asset, assetId);
asset.updateDrawnRate(assetId);
return feeShares;
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);
}

/// @inheritdoc IHubBase
Expand All @@ -232,7 +221,7 @@ contract Hub is IHub, AccessManaged {
spoke.addedShares += shares;
asset.liquidity = liquidity.toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit Add(assetId, msg.sender, shares, amount);

Expand All @@ -255,7 +244,7 @@ contract Hub is IHub, AccessManaged {
spoke.addedShares -= shares;
asset.liquidity = liquidity.uncheckedSub(amount).toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

IERC20(asset.underlying).safeTransfer(to, amount);

Expand All @@ -280,7 +269,7 @@ contract Hub is IHub, AccessManaged {
spoke.drawnShares += drawnShares;
asset.liquidity = liquidity.uncheckedSub(amount).toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

IERC20(asset.underlying).safeTransfer(to, amount);

Expand Down Expand Up @@ -312,7 +301,7 @@ contract Hub is IHub, AccessManaged {
require(balance >= liquidity, InsufficientTransferred(liquidity.uncheckedSub(balance)));
asset.liquidity = liquidity.toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit Restore(assetId, msg.sender, drawnShares, premiumDelta, drawnAmount, premiumAmount);

Expand Down Expand Up @@ -341,7 +330,7 @@ contract Hub is IHub, AccessManaged {
asset.deficitRay += deficitAmountRay.toUint200();
spoke.deficitRay += deficitAmountRay.toUint200();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit ReportDeficit(assetId, msg.sender, drawnShares, premiumDelta, deficitAmountRay);

Expand Down Expand Up @@ -369,7 +358,7 @@ contract Hub is IHub, AccessManaged {
asset.deficitRay -= deficitAmountRay.toUint200();
coveredSpoke.deficitRay -= deficitAmountRay.toUint200();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit EliminateDeficit(assetId, msg.sender, spoke, shares, deficitAmountRay);

Expand All @@ -386,7 +375,7 @@ contract Hub is IHub, AccessManaged {
// no premium change allowed
require(premiumDelta.restoredPremiumRay == 0, InvalidPremiumChange());
_applyPremiumDelta(asset, spoke, premiumDelta);
asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit RefreshPremium(assetId, msg.sender, premiumDelta);
}
Expand All @@ -401,7 +390,7 @@ contract Hub is IHub, AccessManaged {
asset.accrue();
_validatePayFeeShares(sender, shares);
_transferShares(sender, receiver, shares);
asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit TransferShares(assetId, msg.sender, feeReceiver, shares);
}
Expand All @@ -415,7 +404,7 @@ contract Hub is IHub, AccessManaged {
asset.accrue();
_validateTransferShares(asset, sender, receiver, shares);
_transferShares(sender, receiver, shares);
asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit TransferShares(assetId, msg.sender, toSpoke, shares);
}
Expand All @@ -434,7 +423,7 @@ contract Hub is IHub, AccessManaged {
asset.liquidity = liquidity.uncheckedSub(amount).toUint120();
asset.swept += amount.toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

IERC20(asset.underlying).safeTransfer(msg.sender, amount);

Expand All @@ -455,7 +444,7 @@ contract Hub is IHub, AccessManaged {
asset.liquidity = liquidity.toUint120();
asset.swept -= amount.toUint120();

asset.updateDrawnRate(assetId);
asset.updateDrawnRateAndMintFeeShares(_spokes, assetId);

emit Reclaim(assetId, msg.sender, amount);
}
Expand Down Expand Up @@ -602,7 +591,7 @@ 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());
return asset.getUnrealizedFees(asset.getDrawnIndex());
}

/// @inheritdoc IHub
Expand Down Expand Up @@ -779,25 +768,6 @@ 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();
if (shares == 0) {
return 0;
}

address feeReceiver = asset.feeReceiver;
SpokeData storage feeReceiverSpoke = _spokes[assetId][feeReceiver];
require(feeReceiverSpoke.active, SpokeNotActive());

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

return shares;
}

/// @dev Returns the spoke's drawn amount for a specified asset.
function _getSpokeDrawn(
Asset storage asset,
Expand Down
Loading
Loading