Skip to content

Commit cb3856e

Browse files
committed
rename
1 parent 587e675 commit cb3856e

File tree

6 files changed

+48
-48
lines changed

6 files changed

+48
-48
lines changed

spot-contracts/contracts/FeePolicy.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.20;
33

44
import { IFeePolicy } from "./_interfaces/IFeePolicy.sol";
5-
import { SystemState, Range, Line } from "./_interfaces/CommonTypes.sol";
5+
import { SystemTVL, Range, Line } from "./_interfaces/CommonTypes.sol";
66
import { InvalidPerc, InvalidRange, InvalidFees } from "./_interfaces/ProtocolErrors.sol";
77

88
import { LineHelpers } from "./_utils/LineHelpers.sol";
@@ -34,9 +34,9 @@ import { MathHelpers } from "./_utils/MathHelpers.sol";
3434
* - If an operation moves the system back to the balance point, it charges a lower fee (or no fee).
3535
*
3636
* Incentives:
37-
* - When the vault is "under-subscribed", value is transferred from perp to the vault at a predefined rate.
37+
* - When the vault is "under-subscribed", value is transferred from perp to the vault at the computed rate.
3838
* This debases perp tokens gradually and enriches the rollover vault.
39-
* - When the vault is "over-subscribed", value is transferred from the vault to perp at a predefined rate.
39+
* - When the vault is "over-subscribed", value is transferred from the vault to perp at the computed rate.
4040
* This enriches perp tokens gradually and debases the rollover vault.
4141
* - This transfer is implemented through a periodic "rebalance" operation, executed by the vault, and
4242
* gradually nudges the system back into balance. On rebalance, the vault queries this policy
@@ -64,7 +64,7 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
6464

6565
//-----------------------------------------------------------------------------
6666
/// @notice The target system ratio i.e) the normalization factor.
67-
/// @dev The target system ratio, the target vault tvl to perp tvl ration and
67+
/// @dev The target system ratio, the target vault tvl to perp tvl ratio and
6868
/// is *different* from button-wood's tranche ratios.
6969
uint256 public override targetSystemRatio;
7070

@@ -259,7 +259,7 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
259259

260260
/// @inheritdoc IFeePolicy
261261
function computeRebalanceAmount(
262-
SystemState memory s
262+
SystemTVL memory s
263263
) external view override returns (int256 underlyingAmtIntoPerp) {
264264
// We skip rebalancing if dr is close to 1.0
265265
uint256 dr = computeDeviationRatio(s);
@@ -303,7 +303,7 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
303303
}
304304

305305
/// @inheritdoc IFeePolicy
306-
function computeDeviationRatio(SystemState memory s) public view override returns (uint256) {
306+
function computeDeviationRatio(SystemTVL memory s) public view override returns (uint256) {
307307
// NOTE: We assume that perp's TVL and vault's TVL values have the same base denomination.
308308
return s.vaultTVL.mulDiv(ONE, s.perpTVL).mulDiv(ONE, targetSystemRatio);
309309
}

spot-contracts/contracts/PerpetualTranche.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
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, SystemState } from "./_interfaces/CommonTypes.sol";
7+
import { TokenAmount, RolloverData, SystemTVL } from "./_interfaces/CommonTypes.sol";
88
import { UnauthorizedCall, UnauthorizedTransferOut, UnexpectedDecimals, UnexpectedAsset, UnacceptableParams, UnacceptableRollover, ExceededMaxSupply, ExceededMaxMintPerTranche, ReserveCountOverLimit, InvalidPerc } from "./_interfaces/ProtocolErrors.sol";
99

1010
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -642,7 +642,7 @@ contract PerpetualTranche is
642642

643643
/// @inheritdoc IPerpetualTranche
644644
function deviationRatio() external override afterStateUpdate nonReentrant returns (uint256) {
645-
return feePolicy.computeDeviationRatio(_querySystemState());
645+
return feePolicy.computeDeviationRatio(_querySystemTVL());
646646
}
647647

648648
//--------------------------------------------------------------------------
@@ -785,12 +785,12 @@ contract PerpetualTranche is
785785

786786
//-----------------------------------------------------------------------------
787787
// We charge no mint fee when interacting with other callers within the system.
788-
SystemState memory s = _querySystemState();
788+
SystemTVL memory s = _querySystemTVL();
789789
uint256 feePerc = _isProtocolCaller()
790790
? 0
791791
: feePolicy.computeFeePerc(
792792
feePolicy.computeDeviationRatio(s),
793-
feePolicy.computeDeviationRatio(SystemState({ perpTVL: s.perpTVL + valueIn, vaultTVL: s.vaultTVL }))
793+
feePolicy.computeDeviationRatio(SystemTVL({ perpTVL: s.perpTVL + valueIn, vaultTVL: s.vaultTVL }))
794794
);
795795
//-----------------------------------------------------------------------------
796796

@@ -816,13 +816,13 @@ contract PerpetualTranche is
816816

817817
//-----------------------------------------------------------------------------
818818
// We charge no burn fee when interacting with other parts of the system.
819-
SystemState memory s = _querySystemState();
819+
SystemTVL memory s = _querySystemTVL();
820820
uint256 feePerc = _isProtocolCaller()
821821
? 0
822822
: feePolicy.computeFeePerc(
823823
feePolicy.computeDeviationRatio(s),
824824
feePolicy.computeDeviationRatio(
825-
SystemState({ perpTVL: s.perpTVL.mulDiv(perpSupply - perpAmt, perpSupply), vaultTVL: s.vaultTVL })
825+
SystemTVL({ perpTVL: s.perpTVL.mulDiv(perpSupply - perpAmt, perpSupply), vaultTVL: s.vaultTVL })
826826
)
827827
);
828828
//-----------------------------------------------------------------------------
@@ -1045,9 +1045,9 @@ contract PerpetualTranche is
10451045
return (trancheSupply > 0) ? trancheClaim.mulDiv(trancheAmt, trancheSupply, rounding) : trancheAmt;
10461046
}
10471047

1048-
/// @dev Queries the current system state of the perp and vault systems.
1049-
function _querySystemState() private view returns (SystemState memory) {
1050-
return SystemState({ perpTVL: _reserveValue(), vaultTVL: vault.getTVL() });
1048+
/// @dev Queries the current TVL of the perp and vault systems.
1049+
function _querySystemTVL() private view returns (SystemTVL memory) {
1050+
return SystemTVL({ perpTVL: _reserveValue(), vaultTVL: vault.getTVL() });
10511051
}
10521052

10531053
/// @dev Checks if the given token is the underlying collateral token.

spot-contracts/contracts/RolloverVault.sol

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IERC20Upgradeable, IPerpetualTranche, IBondController, ITranche, IFeePo
55
import { IVault } from "./_interfaces/IVault.sol";
66
import { IRolloverVault } from "./_interfaces/IRolloverVault.sol";
77
import { IERC20Burnable } from "./_interfaces/IERC20Burnable.sol";
8-
import { TokenAmount, RolloverData, SystemState } from "./_interfaces/CommonTypes.sol";
8+
import { TokenAmount, RolloverData, SystemTVL } from "./_interfaces/CommonTypes.sol";
99
import { UnauthorizedCall, UnauthorizedTransferOut, UnexpectedDecimals, UnexpectedAsset, OutOfBounds, UnacceptableSwap, InsufficientDeployment, DeployedCountOverLimit, InsufficientLiquidity, LastRebalanceTooRecent } from "./_interfaces/ProtocolErrors.sol";
1010

1111
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@@ -419,7 +419,7 @@ contract RolloverVault is
419419
IERC20Upgradeable underlying_ = underlying;
420420

421421
// Compute perp vault asset split.
422-
SystemState memory s = _querySystemState(perp_);
422+
SystemTVL memory s = _querySystemTVL(perp_);
423423
uint256 underlyingAmtIntoPerp = underlyingAmtIn.mulDiv(ONE, ONE + feePolicy.targetSystemRatio());
424424
uint256 underlyingAmtIntoVault = underlyingAmtIn - underlyingAmtIntoPerp;
425425

@@ -506,10 +506,10 @@ contract RolloverVault is
506506
/// @inheritdoc IVault
507507
function deposit(uint256 underlyingAmtIn) external override nonReentrant whenNotPaused returns (uint256) {
508508
// Compute the mint fees
509-
SystemState memory s = _querySystemState(perp);
509+
SystemTVL memory s = _querySystemTVL(perp);
510510
uint256 feePerc = feePolicy.computeFeePerc(
511511
feePolicy.computeDeviationRatio(s),
512-
feePolicy.computeDeviationRatio(SystemState({ perpTVL: s.perpTVL, vaultTVL: s.vaultTVL + underlyingAmtIn }))
512+
feePolicy.computeDeviationRatio(SystemTVL({ perpTVL: s.perpTVL, vaultTVL: s.vaultTVL + underlyingAmtIn }))
513513
);
514514

515515
// Calculates the fee adjusted amount of vault notes minted when depositing `underlyingAmtIn` of underlying tokens.
@@ -537,12 +537,12 @@ contract RolloverVault is
537537
}
538538

539539
// Compute the redemption fees
540-
SystemState memory s = _querySystemState(perp);
540+
SystemTVL memory s = _querySystemTVL(perp);
541541
uint256 vaultNoteSupply = totalSupply();
542542
uint256 feePerc = feePolicy.computeFeePerc(
543543
feePolicy.computeDeviationRatio(s),
544544
feePolicy.computeDeviationRatio(
545-
SystemState({
545+
SystemTVL({
546546
perpTVL: s.perpTVL,
547547
vaultTVL: s.vaultTVL.mulDiv(vaultNoteSupply - vaultNoteAmt, vaultNoteSupply)
548548
})
@@ -584,7 +584,7 @@ contract RolloverVault is
584584
IPerpetualTranche perp_ = perp;
585585
IERC20Upgradeable underlying_ = underlying;
586586
uint256 underlyingBalPre = underlying_.balanceOf(address(this));
587-
(uint256 perpAmtOut, , SystemState memory s) = computeUnderlyingToPerpSwapAmt(underlyingAmtIn);
587+
(uint256 perpAmtOut, , SystemTVL memory s) = computeUnderlyingToPerpSwapAmt(underlyingAmtIn);
588588

589589
// Revert if insufficient tokens are swapped in or out
590590
if (perpAmtOut <= 0 || underlyingAmtIn <= 0) {
@@ -655,24 +655,24 @@ contract RolloverVault is
655655

656656
/// @inheritdoc IRolloverVault
657657
function deviationRatio() external override nonReentrant returns (uint256) {
658-
return feePolicy.computeDeviationRatio(_querySystemState(perp));
658+
return feePolicy.computeDeviationRatio(_querySystemTVL(perp));
659659
}
660660

661661
/// @inheritdoc IRolloverVault
662662
function computeUnderlyingToPerpSwapAmt(
663663
uint256 underlyingAmtIn
664-
) public returns (uint256, uint256, SystemState memory) {
664+
) public returns (uint256, uint256, SystemTVL memory) {
665665
IPerpetualTranche perp_ = perp;
666666
// Compute equal value perps to swap out to the user
667-
SystemState memory s = _querySystemState(perp_);
667+
SystemTVL memory s = _querySystemTVL(perp_);
668668
uint256 perpAmtOut = underlyingAmtIn.mulDiv(perp_.totalSupply(), s.perpTVL);
669669

670670
//-----------------------------------------------------------------------------
671671
// When user swaps underlying for vault's perps -> perps are minted by the vault
672-
// We thus compute fees based on the post-mint subscription state.
672+
// We thus compute fees based on the post-mint system tvl.
673673
uint256 feePerc = feePolicy.computeFeePerc(
674674
feePolicy.computeDeviationRatio(s),
675-
feePolicy.computeDeviationRatio(SystemState({ perpTVL: s.perpTVL + underlyingAmtIn, vaultTVL: s.vaultTVL }))
675+
feePolicy.computeDeviationRatio(SystemTVL({ perpTVL: s.perpTVL + underlyingAmtIn, vaultTVL: s.vaultTVL }))
676676
);
677677
//-----------------------------------------------------------------------------
678678

@@ -683,19 +683,19 @@ contract RolloverVault is
683683
}
684684

685685
/// @inheritdoc IRolloverVault
686-
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn) public returns (uint256, uint256, SystemState memory) {
686+
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn) public returns (uint256, uint256, SystemTVL memory) {
687687
IPerpetualTranche perp_ = perp;
688688
// Compute equal value underlying tokens to swap out
689-
SystemState memory s = _querySystemState(perp_);
689+
SystemTVL memory s = _querySystemTVL(perp_);
690690
uint256 underlyingAmtOut = perpAmtIn.mulDiv(s.perpTVL, perp_.totalSupply());
691691

692692
//-----------------------------------------------------------------------------
693693
// When user swaps perps for vault's underlying -> perps are redeemed by the vault
694-
// We thus compute fees based on the post-burn subscription state.
694+
// We thus compute fees based on the post-burn system tvl.
695695
uint256 feePerc = feePolicy.computeFeePerc(
696696
feePolicy.computeDeviationRatio(s),
697697
feePolicy.computeDeviationRatio(
698-
SystemState({ perpTVL: s.perpTVL - underlyingAmtOut, vaultTVL: s.vaultTVL })
698+
SystemTVL({ perpTVL: s.perpTVL - underlyingAmtOut, vaultTVL: s.vaultTVL })
699699
)
700700
);
701701
//-----------------------------------------------------------------------------
@@ -846,7 +846,7 @@ contract RolloverVault is
846846
perp_.claimFees(address(this));
847847
_meldPerps(perp_);
848848

849-
SystemState memory s = _querySystemState(perp_);
849+
SystemTVL memory s = _querySystemTVL(perp_);
850850
int256 underlyingAmtIntoPerp = feePolicy.computeRebalanceAmount(s);
851851

852852
// When value is flowing into perp from the vault.
@@ -1068,9 +1068,9 @@ contract RolloverVault is
10681068
emit AssetSynced(token, balance);
10691069
}
10701070

1071-
/// @dev Queries the current system state of the perp and vault systems.
1072-
function _querySystemState(IPerpetualTranche perp_) private returns (SystemState memory) {
1073-
return SystemState({ perpTVL: perp_.getTVL(), vaultTVL: getTVL() });
1071+
/// @dev Queries the current TVL of the perp and vault systems.
1072+
function _querySystemTVL(IPerpetualTranche perp_) private returns (SystemTVL memory) {
1073+
return SystemTVL({ perpTVL: perp_.getTVL(), vaultTVL: getTVL() });
10741074
}
10751075

10761076
//--------------------------------------------------------------------------

spot-contracts/contracts/_interfaces/CommonTypes.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ struct TokenAmount {
1010
uint256 amount;
1111
}
1212

13-
/// @notice The system state parameters.
14-
struct SystemState {
13+
/// @notice The system TVL parameters.
14+
struct SystemTVL {
1515
/// @notice The current TVL of perp denominated in the underlying.
1616
uint256 perpTVL;
1717
/// @notice The current TVL of the vault denominated in the underlying.

spot-contracts/contracts/_interfaces/IFeePolicy.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
pragma solidity ^0.8.0;
33

4-
import { SystemState } from "./CommonTypes.sol";
4+
import { SystemTVL } from "./CommonTypes.sol";
55

66
interface IFeePolicy {
77
/// @return The percentage of the mint perp tokens to be charged as fees,
@@ -12,18 +12,18 @@ interface IFeePolicy {
1212
/// @return Number of decimals representing a multiplier of 1.0. So, 100% = 1*10**decimals.
1313
function decimals() external view returns (uint8);
1414

15-
/// @param s The subscription parameters of both the perp and vault systems.
16-
/// @return The deviation ratio given the system subscription parameters.
17-
function computeDeviationRatio(SystemState memory s) external view returns (uint256);
15+
/// @param s The TVL of both the perp and vault systems.
16+
/// @return The deviation ratio given the system TVL.
17+
function computeDeviationRatio(SystemTVL memory s) external view returns (uint256);
1818

1919
/// @return The target system ratio as a fixed-point number with {DECIMALS} decimal places.
2020
function targetSystemRatio() external view returns (uint256);
2121

2222
/// @notice Computes magnitude and direction of value flow between perp and the rollover vault
2323
/// expressed in underlying tokens.
24-
/// @param s The subscription parameters of both the perp and vault systems.
24+
/// @param s The TVL of both the perp and vault systems.
2525
/// @return underlyingAmtIntoPerp The value in underlying tokens, that need to flow from the vault into perp.
26-
function computeRebalanceAmount(SystemState memory s) external view returns (int256 underlyingAmtIntoPerp);
26+
function computeRebalanceAmount(SystemTVL memory s) external view returns (int256 underlyingAmtIntoPerp);
2727

2828
/// @return The share of the system tvl paid to the protocol owner as fees.
2929
function protocolSharePerc() external view returns (uint256);

spot-contracts/contracts/_interfaces/IRolloverVault.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import { IVault } from "./IVault.sol";
5-
import { SystemState, TokenAmount } from "./CommonTypes.sol";
5+
import { SystemTVL, TokenAmount } from "./CommonTypes.sol";
66

77
interface IRolloverVault is IVault {
88
/// @notice Gradually transfers value between the perp and vault, to bring the system back into balance.
@@ -40,17 +40,17 @@ interface IRolloverVault is IVault {
4040
/// @param underlyingAmtIn The number of underlying tokens the user swaps in.
4141
/// @return perpAmtOut The number of perp tokens returned to the user.
4242
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as mint fees.
43-
/// @return s The pre-swap perp and vault subscription state.
43+
/// @return s The pre-swap perp and vault TVL.
4444
function computeUnderlyingToPerpSwapAmt(
4545
uint256 underlyingAmtIn
46-
) external returns (uint256, uint256, SystemState memory);
46+
) external returns (uint256, uint256, SystemTVL memory);
4747

4848
/// @notice Computes the amount of underlying tokens that are returned when user swaps a given number of perp tokens.
4949
/// @param perpAmtIn The number of perp tokens the user swaps in.
5050
/// @return underlyingAmtOut The number of underlying tokens returned to the user.
5151
/// @return perpFeeAmtToBurn The amount of perp tokens to be paid to the perp contract as burn fees.
52-
/// @return s The pre-swap perp and vault subscription state.
53-
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn) external returns (uint256, uint256, SystemState memory);
52+
/// @return s The pre-swap perp and vault TVL.
53+
function computePerpToUnderlyingSwapAmt(uint256 perpAmtIn) external returns (uint256, uint256, SystemTVL memory);
5454

5555
/// @return The system's current deviation ratio.
5656
function deviationRatio() external returns (uint256);

0 commit comments

Comments
 (0)