Skip to content

Commit 34f16ac

Browse files
committed
Add natspec params for internal methods in PerpV2LeverageModule
1 parent 5fbaa3d commit 34f16ac

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

contracts/protocol/modules/PerpV2LeverageModule.sol

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
485485
* @param _setToken Instance of the SetToken
486486
* @param _setTokenQuantity Quantity of SetToken to issue
487487
* @param _component Address of deposit collateral component
488+
* @param _isEquity True if componentHook called from issuance module for equity flow, false otherwise
488489
*/
489490
function componentIssueHook(
490491
ISetToken _setToken,
@@ -515,6 +516,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
515516
* @param _setToken Instance of the SetToken
516517
* @param _setTokenQuantity Quantity of SetToken to redeem
517518
* @param _component Address of deposit collateral component
519+
* @param _isEquity True if componentHook called from issuance module for equity flow, false otherwise
518520
*/
519521
function componentRedeemHook(
520522
ISetToken _setToken,
@@ -711,6 +713,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
711713
* @param _setTokenQuantity Quantity of Set to issue
712714
* @param _isIssue If true, invocation is for issuance, redemption otherwise
713715
* @param _isSimulation If true, trading is only simulated (to return issuance adjustments)
716+
* @return int256 Amount of collateral to transfer in/out in position units
714717
*/
715718
function _executePositionTrades(
716719
ISetToken _setToken,
@@ -813,6 +816,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
813816
* | --------------------------------------- |
814817
*
815818
* @param _setToken Instance of the SetToken
819+
* @return accountValue Partial account value in position units
816820
*/
817821
function _calculatePartialAccountValuePositionUnit(ISetToken _setToken) internal view returns (int256 accountValue) {
818822
AccountInfo memory accountInfo = getAccountInfo(_setToken);
@@ -829,6 +833,9 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
829833
* Updates the collateral token default position unit. This function is called directly by
830834
* the componentIssue hook, skipping external position unit setting because that method is assumed
831835
* to be the end of a call sequence (e.g manager will not need to read the updated value)
836+
*
837+
* @param _setToken Instance of SetToken
838+
* @param _collateralNotionalQuantity Notional collateral quantity to deposit
832839
*/
833840
function _deposit(ISetToken _setToken, uint256 _collateralNotionalQuantity) internal {
834841
_setToken.invokeApprove(
@@ -846,6 +853,10 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
846853
*
847854
* NOTE: This flow is only used when invoking the external `deposit` function - it converts collateral
848855
* quantity units into a notional quantity.
856+
*
857+
* @param _setToken Instance of SetToken
858+
* @param _collateralQuantityUnits Collateral quantity in position units to deposit
859+
* @return uint256 Notional quantity deposited
849860
*/
850861
function _depositAndUpdatePositions(
851862
ISetToken _setToken,
@@ -880,6 +891,9 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
880891
* into a default position. This function is called directly by _accrueFee and _moduleRedeemHook,
881892
* skipping position unit state updates because the funds withdrawn to SetToken are immediately
882893
* forwarded to `feeRecipient` and SetToken owner respectively.
894+
*
895+
* @param _setToken Instance of SetToken
896+
* @param _collateralNotionalQuantity Notional collateral quantity to withdraw
883897
*/
884898
function _withdraw(ISetToken _setToken, uint256 _collateralNotionalQuantity) internal {
885899
if (_collateralNotionalQuantity == 0) return;
@@ -894,6 +908,10 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
894908
*
895909
* NOTE: This flow is only used when invoking the external `withdraw` function - it converts
896910
* a collateral units quantity into a notional quantity before invoking withdraw.
911+
*
912+
* @param _setToken Instance of SetToken
913+
* @param _collateralQuantityUnits Collateral quantity in position units to withdraw
914+
* @return uint256 Notional quantity withdrawn
897915
*/
898916
function _withdrawAndUpdatePositions(
899917
ISetToken _setToken,
@@ -935,7 +953,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
935953
* | Sell | false | true | exact input (true) | Min quote to receive |
936954
* |----------------------------------------------------|---------------------------- |
937955
*
938-
*
956+
* @param _actionInfo ActionInfo object
939957
* @return uint256 The base position delta resulting from the trade
940958
* @return uint256 The quote asset position delta resulting from the trade
941959
*/
@@ -969,8 +987,9 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
969987
* | Sell | false | true | exact input (true) |
970988
* |----------------------------------------------------|
971989
*
972-
* @return uint256 The base position delta resulting from the trade
973-
* @return uint256 The quote asset position delta resulting from the trade
990+
* @param _actionInfo ActionInfo object
991+
* @return uint256 The base position delta resulting from the trade
992+
* @return uint256 The quote asset position delta resulting from the trade
974993
*/
975994
function _simulateTrade(ActionInfo memory _actionInfo) internal returns (uint256, uint256) {
976995
IQuoter.SwapParams memory params = IQuoter.SwapParams({
@@ -987,7 +1006,10 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
9871006

9881007
/**
9891008
* @dev Calculates protocol fee on module and pays protocol fee from SetToken
990-
* @return uint256 Total protocol fee paid in underlying collateral decimals e.g (USDC = 6)
1009+
*
1010+
* @param _setToken Instance of SetToken
1011+
* @param _exchangedQuantity Notional quantity of USDC exchanged in trade (e.g deltaQuote)
1012+
* @return uint256 Total protocol fee paid in underlying collateral decimals e.g (USDC = 6)
9911013
*/
9921014
function _accrueProtocolFee(
9931015
ISetToken _setToken,
@@ -1089,6 +1111,9 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
10891111
/**
10901112
* @dev Update position address array if a token has been newly added or completely sold off
10911113
* during lever/delever
1114+
*
1115+
* @param _setToken Instance of SetToken
1116+
* @param _baseToken Address of virtual base token
10921117
*/
10931118
function _updatePositionList(ISetToken _setToken, address _baseToken) internal {
10941119
address[] memory positionList = positions[_setToken];
@@ -1122,6 +1147,10 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
11221147
* @dev Returns a dust tolerant check of whether a base position balance exists. Because we use
11231148
* position unit math to calculate notional amounts when trading positions, there's a chance
11241149
* we could have introduced a 1 wei rounding error.
1150+
*
1151+
* @param _setToken Instance of SetToken
1152+
* @param _baseToken Address of virtual base token
1153+
* @return bool True if a non-dust base token balance exists, false otherwise
11251154
*/
11261155
function _hasBaseBalance(ISetToken _setToken, address _baseToken) internal view returns(bool) {
11271156
int256 baseBalance = perpAccountBalance.getBase(address(_setToken), _baseToken);
@@ -1131,6 +1160,9 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
11311160
/**
11321161
* @dev Calculates the sum of collateralToken denominated market-prices of assets and debt for the Perp account per
11331162
* SetToken
1163+
*
1164+
* @param _setToken Instance of SetToken
1165+
* @return int256 External position unit
11341166
*/
11351167
function _calculateExternalPositionUnit(ISetToken _setToken) internal view returns (int256) {
11361168
PositionNotionalInfo[] memory positionInfo = getPositionNotionalInfo(_setToken);
@@ -1149,12 +1181,18 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
11491181
return externalPositionUnitInPrecisionDecimals.fromPreciseUnitToDecimals(collateralDecimals);
11501182
}
11511183

1152-
// @dev Retrieves collateral balance as an an 18 decimal vUSDC quote value
1184+
// @dev Retrieves collateral balance as an 18 decimal vUSDC quote value
1185+
//
1186+
// @param _setToken Instance of SetToken
1187+
// @return int256 Collateral balance as an 18 decimal vUSDC quote value
11531188
function _getCollateralBalance(ISetToken _setToken) internal view returns (int256) {
11541189
return perpVault.getBalance(address(_setToken)).toPreciseUnitsFromDecimals(collateralDecimals);
11551190
}
11561191

11571192
// @dev Retrieves net quote balance of all open positions
1193+
//
1194+
// @param _setToken Instance of SetToken
1195+
// @return int256 Net quote balance of all open positions
11581196
function _getNetQuoteBalance(ISetToken _setToken) internal view returns (int256 netQuoteBalance) {
11591197
for (uint256 i = 0; i < positions[_setToken].length; i++) {
11601198
netQuoteBalance = netQuoteBalance.add(
@@ -1170,6 +1208,12 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, AllowSetT
11701208
* the SetToken's components array, at the same index the collateral token occupies in the components
11711209
* array. All other values are left unset (0). An empty-value components length debtAdjustments
11721210
* array is also returned.
1211+
*
1212+
* @param _setToken Instance of the SetToken
1213+
* @param _components Array of components held by the SetToken
1214+
* @param _newExternalPositionUnit Dynamically calculated externalPositionUnit
1215+
* @return int256[] Components-length array with equity adjustment value at appropriate index
1216+
* @return int256[] Components-length array of zeroes (debt adjustements)
11731217
*/
11741218
function _formatAdjustments(
11751219
ISetToken _setToken,

0 commit comments

Comments
 (0)