Skip to content

Commit cea3a56

Browse files
committed
code review fix #1,#2
1 parent f333dd2 commit cea3a56

File tree

12 files changed

+45
-47
lines changed

12 files changed

+45
-47
lines changed

spot-contracts/contracts/FeePolicy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.19;
33

44
import { IFeePolicy } from "./_interfaces/IFeePolicy.sol";
5-
import { SubscriptionParams } from "./_interfaces/ReturnData.sol";
5+
import { SubscriptionParams } from "./_interfaces/CommonTypes.sol";
66

77
import { MathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
88
import { SafeCastUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol";

spot-contracts/contracts/PerpetualTranche.sol

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.19;
44
import { IERC20MetadataUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
55
import { IERC20Upgradeable, IPerpetualTranche, IBondIssuer, IFeePolicy, IBondController, ITranche } from "./_interfaces/IPerpetualTranche.sol";
66
import { IRolloverVault } from "./_interfaces/IRolloverVault.sol";
7-
import { TokenAmount, RolloverData, SubscriptionParams } from "./_interfaces/ReturnData.sol";
7+
import { TokenAmount, RolloverData, SubscriptionParams } from "./_interfaces/CommonTypes.sol";
88
import { UnauthorizedCall, UnauthorizedTransferOut, UnacceptableReference, UnexpectedDecimals, UnexpectedAsset, UnacceptableDeposit, UnacceptableRedemption, UnacceptableParams, UnacceptableRollover, ExceededMaxSupply, ExceededMaxMintPerTranche } from "./_interfaces/ProtocolErrors.sol";
99

1010
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -585,10 +585,10 @@ contract PerpetualTranche is
585585
returns (TokenAmount[] memory)
586586
{
587587
uint256 perpSupply = totalSupply();
588-
if(perpSupply == 0){
588+
if (perpSupply == 0) {
589589
revert UnacceptableRedemption();
590590
}
591-
return _computeRedemptionAmts(perpAmtBurnt, totalSupply());
591+
return _computeRedemptionAmts(perpAmtBurnt, perpSupply);
592592
}
593593

594594
/// @inheritdoc IPerpetualTranche
@@ -851,10 +851,7 @@ contract PerpetualTranche is
851851
uint256 tokenOutBalance = tokenOut.balanceOf(address(this));
852852
tokenOutAmtRequested = MathUpgradeable.min(tokenOutAmtRequested, tokenOutBalance);
853853
if (trancheInAmtAvailable <= 0 || trancheInPrice <= 0 || tokenOutPrice <= 0 || tokenOutAmtRequested <= 0) {
854-
return RolloverData({
855-
trancheInAmt: 0,
856-
tokenOutAmt: 0
857-
});
854+
return RolloverData({ trancheInAmt: 0, tokenOutAmt: 0 });
858855
}
859856
//-----------------------------------------------------------------------------
860857
// Basic rollover with fees:

spot-contracts/contracts/Rebalancer.sol

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IERC20MetadataUpgradeable } from "@openzeppelin/contracts-upgradeable/t
66
import { ITranche } from "./_interfaces/buttonwood/ITranche.sol";
77
import { IBondController } from "./_interfaces/buttonwood/IBondController.sol";
88
import { IPerpetualTranche } from "./_interfaces/IPerpetualTranche.sol";
9-
import { TokenAmount } from "./_interfaces/ReturnData.sol";
9+
import { TokenAmount } from "./_interfaces/CommonTypes.sol";
1010
import { IRolloverVault } from "./_interfaces/IRolloverVault.sol";
1111
import { IFeePolicy } from "./_interfaces/IFeePolicy.sol";
1212

@@ -66,10 +66,7 @@ contract Rebalancer {
6666
uint256 public constant ONE = FEE_ONE_PERC; // 1.0 or 100%
6767

6868
/// @notice TODO
69-
function deposit2(
70-
IPerpetualTranche perp,
71-
uint256 underlyingAmtIn
72-
) public returns (uint256, uint256) {
69+
function deposit2(IPerpetualTranche perp, uint256 underlyingAmtIn) public returns (uint256, uint256) {
7370
IRolloverVault vault = perp.vault();
7471
IERC20Upgradeable underlying = perp.underlying();
7572

@@ -157,10 +154,7 @@ contract Rebalancer {
157154
}
158155

159156
/// @notice TODO
160-
function redeemPerpsAndMintVaultNotes(
161-
IPerpetualTranche perp,
162-
uint256 perpAmtIn
163-
) external returns (uint256) {
157+
function redeemPerpsAndMintVaultNotes(IPerpetualTranche perp, uint256 perpAmtIn) external returns (uint256) {
164158
IRolloverVault vault = perp.vault();
165159
IERC20Upgradeable underlying = perp.underlying();
166160

spot-contracts/contracts/RolloverVault.sol

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IERC20Upgradeable, IPerpetualTranche, IBondIssuer, IBondController, ITr
66
import { IVault } from "./_interfaces/IVault.sol";
77
import { IRolloverVault } from "./_interfaces/IRolloverVault.sol";
88
import { IERC20Burnable } from "./_interfaces/IERC20Burnable.sol";
9-
import { TokenAmount, RolloverData, SubscriptionParams } from "./_interfaces/ReturnData.sol";
9+
import { TokenAmount, RolloverData, SubscriptionParams } from "./_interfaces/CommonTypes.sol";
1010
import { UnauthorizedCall, UnauthorizedTransferOut, UnacceptableReference, UnexpectedDecimals, UnexpectedAsset, UnacceptableDeposit, UnacceptableRedemption, OutOfBounds, TVLDecreased, UnacceptableSwap, InsufficientDeployment, DeployedCountOverLimit } from "./_interfaces/ProtocolErrors.sol";
1111

1212
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -408,10 +408,8 @@ contract RolloverVault is
408408
return redeem(notes);
409409
}
410410

411-
/// @notice Allows users to swap their underlying tokens for perps held by the vault.
411+
/// @inheritdoc IRolloverVault
412412
/// @dev Callers should call `recover` before executing `swapUnderlyingForPerps` to maximize vault liquidity.
413-
/// @param underlyingAmtIn The amount of underlying tokens swapped in.
414-
/// @return The amount of perp tokens swapped out.
415413
function swapUnderlyingForPerps(uint256 underlyingAmtIn) external nonReentrant whenNotPaused returns (uint256) {
416414
// Calculates the fee adjusted perp amount to transfer to the user.
417415
// NOTE: This operation should precede any token transfers.
@@ -453,9 +451,7 @@ contract RolloverVault is
453451
return perpAmtOut;
454452
}
455453

456-
/// @notice Allows users to swap their perp tokens for underlying tokens held by the vault.
457-
/// @param perpAmtIn The amount of perp tokens swapped in.
458-
/// @return The amount of underlying tokens swapped out.
454+
/// @inheritdoc IRolloverVault
459455
function swapPerpsForUnderlying(uint256 perpAmtIn) external nonReentrant whenNotPaused returns (uint256) {
460456
// Calculates the fee adjusted underlying amount to transfer to the user.
461457
IPerpetualTranche perp_ = perp;
@@ -498,11 +494,7 @@ contract RolloverVault is
498494
//--------------------------------------------------------------------------
499495
// External & Public methods
500496

501-
/// @notice Computes the amount of perp tokens that are returned when user swaps a given number of underlying tokens.
502-
/// @param underlyingAmtIn The number of underlying tokens the user swaps in.
503-
/// @return perpAmtOut The number of perp tokens returned to the user.
504-
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as mint fees.
505-
/// @return s The pre-swap perp and vault subscription state.
497+
/// @inheritdoc IRolloverVault
506498
function computeUnderlyingToPerpSwapAmt(uint256 underlyingAmtIn)
507499
public
508500
returns (
@@ -533,11 +525,7 @@ contract RolloverVault is
533525
return (perpAmtOut, perpFeeAmtToBurn, s);
534526
}
535527

536-
/// @notice Computes the amount of underlying tokens that are returned when user swaps a given number of perp tokens.
537-
/// @param perpAmtIn The number of perp tokens the user swaps in.
538-
/// @return underlyingAmtOut The number of underlying tokens returned to the user.
539-
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as burn fees.
540-
/// @return s The pre-swap perp and vault subscription state.
528+
/// @inheritdoc IRolloverVault
541529
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn)
542530
public
543531
returns (

spot-contracts/contracts/_interfaces/IFeePolicy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
5-
import { SubscriptionParams } from "./ReturnData.sol";
5+
import { SubscriptionParams } from "./CommonTypes.sol";
66

77
interface IFeePolicy {
88
/// @param dr The current system deviation ratio.

spot-contracts/contracts/_interfaces/IPerpetualTranche.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IFeePolicy } from "./IFeePolicy.sol";
88
import { IBondController } from "./buttonwood/IBondController.sol";
99
import { ITranche } from "./buttonwood/ITranche.sol";
1010
import { IRolloverVault } from "./IRolloverVault.sol";
11-
import { TokenAmount, RolloverData } from "./ReturnData.sol";
11+
import { TokenAmount, RolloverData } from "./CommonTypes.sol";
1212

1313
interface IPerpetualTranche is IERC20Upgradeable {
1414
//--------------------------------------------------------------------------

spot-contracts/contracts/_interfaces/IRolloverVault.sol

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@ pragma solidity ^0.8.0;
44
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
55
import { IVault } from "./IVault.sol";
66
import { IFeePolicy } from "./IFeePolicy.sol";
7-
import { SubscriptionParams } from "./ReturnData.sol";
7+
import { SubscriptionParams } from "./CommonTypes.sol";
88

99
interface IRolloverVault is IVault {
10+
/// @notice Allows users to swap their underlying tokens for perps held by the vault.
11+
/// @param underlyingAmtIn The amount of underlying tokens swapped in.
12+
/// @return The amount of perp tokens swapped out.
1013
function swapUnderlyingForPerps(uint256 underlyingAmtIn) external returns (uint256);
1114

15+
/// @notice Allows users to swap their perp tokens for underlying tokens held by the vault.
16+
/// @param perpAmtIn The amount of perp tokens swapped in.
17+
/// @return The amount of underlying tokens swapped out.
1218
function swapPerpsForUnderlying(uint256 perpAmtIn) external returns (uint256);
1319

20+
/// @notice Computes the amount of perp tokens that are returned when user swaps a given number of underlying tokens.
21+
/// @param underlyingAmtIn The number of underlying tokens the user swaps in.
22+
/// @return perpAmtOut The number of perp tokens returned to the user.
23+
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as mint fees.
24+
/// @return s The pre-swap perp and vault subscription state.
1425
function computeUnderlyingToPerpSwapAmt(uint256 underlyingAmtIn)
1526
external
1627
returns (
@@ -19,6 +30,11 @@ interface IRolloverVault is IVault {
1930
SubscriptionParams memory
2031
);
2132

33+
/// @notice Computes the amount of underlying tokens that are returned when user swaps a given number of perp tokens.
34+
/// @param perpAmtIn The number of perp tokens the user swaps in.
35+
/// @return underlyingAmtOut The number of underlying tokens returned to the user.
36+
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as burn fees.
37+
/// @return s The pre-swap perp and vault subscription state.
2238
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn)
2339
external
2440
returns (

spot-contracts/contracts/_interfaces/IVault.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
5-
import { TokenAmount } from "./ReturnData.sol";
5+
import { TokenAmount } from "./CommonTypes.sol";
66

77
/*
88
* @title IVault

spot-contracts/contracts/_utils/BondTranchesHelpers.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ library BondTranchesHelpers {
6060

6161
uint256[] memory trancheAmtsReq = new uint256[](2);
6262

63-
// We compute the amount of juniors required using all the seniors
64-
trancheAmtsReq[0] = trancheBalsAvailable[0] - (trancheBalsAvailable[0] % bt.trancheRatios[0]);
65-
trancheAmtsReq[1] = (trancheAmtsReq[0] * bt.trancheRatios[1]) / bt.trancheRatios[0];
63+
// We compute the amount of seniors required using all the juniors
64+
trancheAmtsReq[1] = trancheBalsAvailable[1] - (trancheBalsAvailable[1] % bt.trancheRatios[1]);
65+
trancheAmtsReq[0] = (trancheAmtsReq[1] * bt.trancheRatios[0]) / bt.trancheRatios[1];
6666

67-
// If enough juniors aren't available, we compute the amount of seniors required using all the juniors
68-
if (trancheAmtsReq[1] > trancheBalsAvailable[1]) {
69-
trancheAmtsReq[1] = trancheBalsAvailable[1] - (trancheBalsAvailable[1] % bt.trancheRatios[1]);
70-
trancheAmtsReq[0] = (trancheAmtsReq[1] * bt.trancheRatios[0]) / bt.trancheRatios[1];
67+
// If enough seniors aren't available, we compute the amount of juniors required using all the seniors
68+
if (trancheAmtsReq[0] > trancheBalsAvailable[0]) {
69+
trancheAmtsReq[0] = trancheBalsAvailable[0] - (trancheBalsAvailable[0] % bt.trancheRatios[0]);
70+
trancheAmtsReq[1] = (trancheAmtsReq[0] * bt.trancheRatios[1]) / bt.trancheRatios[0];
7171
}
7272

7373
return trancheAmtsReq;

0 commit comments

Comments
 (0)