Skip to content

Commit f2934bd

Browse files
cgewecke0xSachinK
andauthored
Perp Leverage Strategy Extension (#5)
* Add PerpV2LeverageStrategyExtension contract, tests * Fix imports * Add short position test cases for shouldRebalance * Add short position test case for shouldRebalanceWithBounds * Refactor javadocs * Fix terminology * Fix bug in getChunkRebalanceNotional and add tests for short case * Add suggested changes * Fix failing tests * Fix when caller is a contract test cases * Improve javadocs in getCLR & handle account value is 0 * Improve javadocs * Fix skipped test cases * Add suggested javadoc changes * Remove extra line * Add PerpV2LeverageStrategyExtension contract, tests * Fix imports * Add short position test cases for shouldRebalance * Add short position test case for shouldRebalanceWithBounds * Refactor javadocs * Fix terminology * Fix bug in getChunkRebalanceNotional and add tests for short case * Add suggested changes * Fix failing tests * Fix when caller is a contract test cases * Improve javadocs in getCLR & handle account value is 0 * Improve javadocs * Fix skipped test cases * Add suggested javadoc changes * Remove extra line * Update version to 0.0.2-perp.0 * Fix setToken supply = 0 tests / use "fast" set-protocol-v2 typechain artifacts * Use BaseManager (V1) in tests * Remove spec todo * Revert pre-release package version bump * Remove unused log statements * Move absUint256 function to PreciseUnitMath Co-authored-by: alpha-guy <[email protected]>
1 parent 43599f4 commit f2934bd

File tree

12 files changed

+6710
-13
lines changed

12 files changed

+6710
-13
lines changed

contracts/extensions/PerpV2LeverageStrategyExtension.sol

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

contracts/lib/PreciseUnitMath.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
pragma solidity 0.6.10;
2020
pragma experimental ABIEncoderV2;
2121

22+
import { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol";
2223
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
2324
import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol";
2425

25-
2626
/**
2727
* @title PreciseUnitMath
2828
* @author Set Protocol
@@ -35,6 +35,7 @@ import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol"
3535
* - 4/21/21: Added approximatelyEquals function
3636
*/
3737
library PreciseUnitMath {
38+
using SafeCast for int256;
3839
using SafeMath for uint256;
3940
using SignedSafeMath for int256;
4041

@@ -195,4 +196,13 @@ library PreciseUnitMath {
195196
function approximatelyEquals(uint256 a, uint256 b, uint256 range) internal pure returns (bool) {
196197
return a <= b.add(range) && a >= b.sub(range);
197198
}
199+
200+
/**
201+
* Convert int256 variables to absolute uint256 values
202+
*
203+
* return uint256 Absolute value in uint256
204+
*/
205+
function absUint256(int256 _int256Value) internal pure returns(uint256) {
206+
return _int256Value > 0 ? _int256Value.toUint256() : _int256Value.mul(-1).toUint256();
207+
}
198208
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"web3": "^1.2.9"
9393
},
9494
"dependencies": {
95-
"@setprotocol/set-protocol-v2": "^0.1.9",
95+
"@setprotocol/set-protocol-v2": "^0.1.10-fast.0",
9696
"@uniswap/v3-sdk": "^3.5.1",
9797
"ethers": "5.5.2",
9898
"fs-extra": "^5.0.0",

0 commit comments

Comments
 (0)