Skip to content

Commit 969478e

Browse files
author
Sachin
authored
PerpV2 Basis Trading Module (#198)
* Add initial implementation * Add WIP unit tests; Fix bugs * Add javadocs; Fix bugs * Fix protocol fees & tradeAndTrackFunding * Fix failing tests; Add test for moduleRedeemHook; Speed up tests * Add tests for getRedemptionAdjustments * Add suggested changes * Remove .only from tests * Fix: protocol and manager fee split * Fix withdrawFundingAndAccrueFees; Add comments * Add comments * Make overrides and super calls clearer; Add modifiers as required * Add comment explaining require statement in updatePerformanceFee * Updated version to 0.1.12-basis.0 * Remove _trackSettledFunding from withdrawAndAccrueFees * Dry withdrawFunding function; Fix typos * Fix getRedemptionAdjustment tests
1 parent 87e48a7 commit 969478e

File tree

9 files changed

+2329
-18
lines changed

9 files changed

+2329
-18
lines changed

contracts/lib/UnitConversionUtils.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,24 @@ library UnitConversionUtils {
5858
}
5959

6060
/**
61-
* @dev Converts an arbitrarily decimalized quantity into a PRECISE_UNIT quantity.
61+
* @dev Converts an arbitrarily decimalized quantity into a int256 PRECISE_UNIT quantity.
6262
*
6363
* @param _amount Non-PRECISE_UNIT amount to convert
6464
* @param _decimals Decimal precision of amount being converted to PRECISE_UNIT
65-
* @return Input converted to PRECISE_UNIT decimal format
65+
* @return Input converted to int256 PRECISE_UNIT decimal format
6666
*/
6767
function toPreciseUnitsFromDecimals(int256 _amount, uint8 _decimals) internal pure returns (int256) {
6868
return _amount.mul(int256(10**(18 - (uint(_decimals)))));
6969
}
70+
71+
/**
72+
* @dev Converts an arbitrarily decimalized quantity into a uint256 PRECISE_UNIT quantity.
73+
*
74+
* @param _amount Non-PRECISE_UNIT amount to convert
75+
* @param _decimals Decimal precision of amount being converted to PRECISE_UNIT
76+
* @return Input converted to uint256 PRECISE_UNIT decimal format
77+
*/
78+
function toPreciseUnitsFromDecimals(uint256 _amount, uint8 _decimals) internal pure returns (uint256) {
79+
return _amount.mul(10**(18 - (uint(_decimals))));
80+
}
7081
}

contracts/protocol/modules/PerpV2BasisTradingModule.sol

Lines changed: 532 additions & 0 deletions
Large diffs are not rendered by default.

contracts/protocol/modules/PerpV2LeverageModule.sol

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
238238
function initialize(
239239
ISetToken _setToken
240240
)
241-
external
241+
public
242242
onlySetManager(_setToken, msg.sender)
243243
onlyValidAndPendingSet(_setToken)
244244
onlyAllowedSet(_setToken)
@@ -319,10 +319,10 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
319319
int256 _baseQuantityUnits,
320320
uint256 _quoteBoundQuantityUnits
321321
)
322-
external
322+
public
323323
nonReentrant
324324
onlyManagerAndValidSet(_setToken)
325-
{
325+
{
326326
ActionInfo memory actionInfo = _createAndValidateActionInfo(
327327
_setToken,
328328
_baseToken,
@@ -403,7 +403,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
403403
*
404404
* NOTE: Function will revert if there is greater than a position unit amount of USDC of account value.
405405
*/
406-
function removeModule() external override onlyValidAndInitializedSet(ISetToken(msg.sender)) {
406+
function removeModule() public virtual override onlyValidAndInitializedSet(ISetToken(msg.sender)) {
407407
ISetToken setToken = ISetToken(msg.sender);
408408

409409
// Check that there is less than 1 position unit of USDC of account value (to tolerate PRECISE_UNIT math rounding errors).
@@ -456,7 +456,8 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
456456
ISetToken _setToken,
457457
uint256 _setTokenQuantity
458458
)
459-
external
459+
public
460+
virtual
460461
override
461462
onlyModule(_setToken)
462463
{
@@ -488,6 +489,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
488489
uint256 _setTokenQuantity
489490
)
490491
external
492+
virtual
491493
override
492494
onlyModule(_setToken)
493495
{
@@ -618,6 +620,7 @@ contract PerpV2LeverageModule is ModuleBase, ReentrancyGuard, Ownable, SetTokenA
618620
uint256 _setTokenQuantity
619621
)
620622
external
623+
virtual
621624
override
622625
returns (int256[] memory, int256[] memory _)
623626
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@setprotocol/set-protocol-v2",
3-
"version": "0.1.12",
3+
"version": "0.1.12-basis.0",
44
"description": "",
55
"main": "dist",
66
"types": "dist/types",

0 commit comments

Comments
 (0)