Skip to content

Commit 2aafa2e

Browse files
committed
code review feedback
1 parent 5ce29c4 commit 2aafa2e

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

spot-contracts/contracts/vaults/RolloverVault.sol

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -222,25 +222,21 @@ contract RolloverVault is
222222
/// @return The list of asset tokens and amounts redeemed.
223223
function redeem(uint256 notes) external nonReentrant whenNotPaused returns (TokenAmount[] memory) {
224224
uint256 totalNotes = totalSupply();
225-
uint256 deployedCount_ = deployedCount();
226-
uint256 earnedCount_ = earnedCount();
227-
uint256 assetCount = 1 + deployedCount_ + earnedCount_;
228-
229-
TokenAmount[] memory redemptions = new TokenAmount[](assetCount);
225+
uint256 deployedCount_ = _deployed.length();
226+
uint256 assetCount = 2 + deployedCount_;
230227

231228
// burn notes
232229
_burn(_msgSender(), notes);
233230

234231
// aggregating vault assets to be redeemed
232+
TokenAmount[] memory redemptions = new TokenAmount[](assetCount);
235233
redemptions[0].token = underlying;
236234
for (uint256 i = 0; i < deployedCount_; i++) {
237-
redemptions[i + 1].token = deployedAt(i);
238-
}
239-
for (uint256 i = 0; i < earnedCount_; i++) {
240-
redemptions[i + 1 + deployedCount_].token = earnedAt(i);
235+
redemptions[i + 1].token = IERC20Upgradeable(_deployed.at(i));
241236
}
237+
redemptions[deployedCount_ + 1].token = IERC20Upgradeable(perp);
242238

243-
// transferring assets out proportionally
239+
// calculating amounts and transferring assets out proportionally
244240
for (uint256 i = 0; i < assetCount; i++) {
245241
redemptions[i].amount = _calculateAssetShare(redemptions[i].token, notes, totalNotes);
246242
redemptions[i].token.safeTransfer(_msgSender(), redemptions[i].amount);
@@ -250,7 +246,7 @@ contract RolloverVault is
250246
return redemptions;
251247
}
252248

253-
/// @notice Total value of assets currently held by the vault denominated in the underlying asset.
249+
/// @return The total value of assets currently held by the vault denominated in the underlying asset
254250
function getTVL() public returns (uint256) {
255251
uint256 totalAssets = 0;
256252

@@ -259,22 +255,19 @@ contract RolloverVault is
259255

260256
// The deployed asset value denominated in the underlying
261257
for (uint256 i = 0; i < _deployed.length(); i++) {
262-
ITranche tranche = deployedAt(i);
263-
uint256 balance = tranche.balanceOf(address(this));
264-
if (balance > 0) {
258+
ITranche tranche = ITranche(_deployed.at(i));
259+
uint256 trancheBalance = tranche.balanceOf(address(this));
260+
if (trancheBalance > 0) {
265261
(uint256 collateralBalance, uint256 debt) = tranche.getTrancheCollateralization();
266-
totalAssets += balance.mulDiv(collateralBalance, debt);
262+
totalAssets += trancheBalance.mulDiv(collateralBalance, debt);
267263
}
268264
}
269265

270266
// The earned asset (perp token) value denominated in the underlying
271-
for (uint256 i = 0; i < earnedCount(); i++) {
272-
IERC20Upgradeable perp_ = earnedAt(i);
273-
uint256 balance = perp_.balanceOf(address(this));
274-
if (balance > 0) {
275-
// The "earned" asset is assumed to be the perp token.
276-
totalAssets += balance.mulDiv(IPerpetualTranche(address(perp_)).getAvgPrice(), PERP_UNIT_PRICE);
277-
}
267+
uint256 perpBalance = perp.balanceOf(address(this));
268+
if (perpBalance > 0) {
269+
// The "earned" asset is assumed to be the perp token.
270+
totalAssets += perpBalance.mulDiv(IPerpetualTranche(address(perp)).getAvgPrice(), PERP_UNIT_PRICE);
278271
}
279272

280273
return totalAssets;
@@ -283,46 +276,43 @@ contract RolloverVault is
283276
//--------------------------------------------------------------------------
284277
// External & Public read methods
285278

286-
/// @notice Fetches the vault's asset token balance.
287279
/// @param token The address of the asset ERC-20 token held by the vault.
288-
/// @return The token balance.
289-
function assetBalance(IERC20Upgradeable token) external view returns (uint256) {
280+
/// @return The vault's asset token balance.
281+
function vaultAssetBalance(IERC20Upgradeable token) external view returns (uint256) {
290282
return isVaultAsset(token) ? token.balanceOf(address(this)) : 0;
291283
}
292284

293-
/// @notice Checks if the given token is held by the vault.
294-
/// @param token The address of a token to check.
295-
function isVaultAsset(IERC20Upgradeable token) public view returns (bool) {
296-
return (token == underlying) || _deployed.contains(address(token)) || (address(perp) == address(token));
297-
}
298-
299-
/// @notice Total count of deployed asset tokens held by the vault.
300-
/// @return The count.
301-
function deployedCount() public view returns (uint256) {
285+
/// @return Total count of deployed asset tokens held by the vault.
286+
function deployedCount() external view returns (uint256) {
302287
return _deployed.length();
303288
}
304289

305-
/// @notice The token address from the deployed asset token list by index.
306290
/// @param i The index of a token.
307-
function deployedAt(uint256 i) public view returns (ITranche) {
308-
return ITranche(_deployed.at(i));
291+
/// @return The token address from the deployed asset token list by index.
292+
function deployedAt(uint256 i) external view returns (IERC20Upgradeable) {
293+
return IERC20Upgradeable(_deployed.at(i));
309294
}
310295

311-
/// @notice Total count of earned income tokens held by the vault.
312-
/// @return The count.
313-
function earnedCount() public pure returns (uint256) {
296+
/// @return Total count of earned income tokens held by the vault.
297+
function earnedCount() external pure returns (uint256) {
314298
return 1;
315299
}
316300

317-
/// @notice The token address from the earned income token list by index.
318301
/// @param i The index of a token.
319-
function earnedAt(uint256 i) public view returns (IERC20Upgradeable) {
302+
/// @return The token address from the earned income token list by index.
303+
function earnedAt(uint256 i) external view returns (IERC20Upgradeable) {
320304
if (i > 0) {
321305
revert OutOfBounds();
322306
}
323307
return IERC20Upgradeable(perp);
324308
}
325309

310+
/// @param token The address of a token to check.
311+
/// @return If the given token is held by the vault.
312+
function isVaultAsset(IERC20Upgradeable token) public view returns (bool) {
313+
return (token == underlying) || _deployed.contains(address(token)) || (address(perp) == address(token));
314+
}
315+
326316
//--------------------------------------------------------------------------
327317
// Private write methods
328318

@@ -428,7 +418,7 @@ contract RolloverVault is
428418
/// @notice Redeems the deployed tranche tokens for the underlying asset.
429419
function _redeemTranches() private {
430420
for (uint256 i = 0; i < _deployed.length(); i++) {
431-
ITranche tranche = deployedAt(i);
421+
ITranche tranche = ITranche(_deployed.at(i));
432422
IBondController bond = IBondController(tranche.bond());
433423

434424
// if bond has mature, redeem the tranche token
@@ -458,7 +448,7 @@ contract RolloverVault is
458448
// as deletions involve swapping the deleted element to the
459449
// end of the set and removing the last element.
460450
for (uint256 i = _deployed.length(); i > 0; i--) {
461-
_syncDeployedAsset(deployedAt(i - 1));
451+
_syncDeployedAsset(IERC20Upgradeable(_deployed.at(i - i)));
462452
}
463453
_syncAsset(underlying);
464454
}

0 commit comments

Comments
 (0)