File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -554,14 +554,20 @@ contract SetToken is ERC20 {
554
554
}
555
555
556
556
/**
557
- * Takes a real unit and divides by the position multiplier to return the virtual unit
557
+ * Takes a real unit and divides by the position multiplier to return the virtual unit. Negative units will
558
+ * be rounded away from 0 so no need to check that unit will be rounded down to 0 in conversion.
558
559
*/
559
560
function _convertRealToVirtualUnit (int256 _realUnit ) internal view returns (int256 ) {
560
561
int256 virtualUnit = _realUnit.conservativePreciseDiv (positionMultiplier);
561
562
562
- // These checks ensure that the virtual unit does not return a result that has rounded down to 0
563
+ // This check ensures that the virtual unit does not return a result that has rounded down to 0
563
564
if (_realUnit > 0 && virtualUnit == 0 ) {
564
- revert ("Virtual unit conversion invalid " );
565
+ revert ("Real to Virtual unit conversion invalid " );
566
+ }
567
+
568
+ // This check ensures that when converting back to realUnits the unit won't be rounded down to 0
569
+ if (_realUnit > 0 && _convertVirtualToRealUnit (virtualUnit) == 0 ) {
570
+ revert ("Virtual to Real unit conversion invalid " );
565
571
}
566
572
567
573
return virtualUnit;
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ const config: HardhatUserConfig = {
41
41
localhost : {
42
42
url : "http://127.0.0.1:8545" ,
43
43
timeout : 100000 ,
44
- gas : 9500000 ,
45
- blockGasLimit : 9500000 ,
44
+ gas : 12000000 ,
45
+ blockGasLimit : 12000000 ,
46
46
} ,
47
47
kovan : {
48
48
url : "https://kovan.infura.io/v3/" + process . env . INFURA_TOKEN ,
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @setprotocol/set-protocol-v2" ,
3
- "version" : " 0.0.43 " ,
3
+ "version" : " 0.0.44 " ,
4
4
"description" : " " ,
5
5
"main" : " dist" ,
6
6
"types" : " dist/types" ,
Original file line number Diff line number Diff line change @@ -463,7 +463,19 @@ describe("SetToken", () => {
463
463
} ) ;
464
464
465
465
it ( "should revert" , async ( ) => {
466
- await expect ( subject ( ) ) . to . be . revertedWith ( "Virtual unit conversion invalid" ) ;
466
+ await expect ( subject ( ) ) . to . be . revertedWith ( "Real to Virtual unit conversion invalid" ) ;
467
+ } ) ;
468
+ } ) ;
469
+
470
+ describe ( "when the conversion back to real units would round down to 0" , async ( ) => {
471
+ beforeEach ( async ( ) => {
472
+ subjectNewUnit = BigNumber . from ( 1 ) ;
473
+ const hugePositionMultiplier = ether ( .99 ) ;
474
+ await setToken . connect ( subjectCaller . wallet ) . editPositionMultiplier ( hugePositionMultiplier ) ;
475
+ } ) ;
476
+
477
+ it ( "should revert" , async ( ) => {
478
+ await expect ( subject ( ) ) . to . be . revertedWith ( "Virtual to Real unit conversion invalid" ) ;
467
479
} ) ;
468
480
} ) ;
469
481
You can’t perform that action at this time.
0 commit comments