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 {
554554 }
555555
556556 /**
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.
558559 */
559560 function _convertRealToVirtualUnit (int256 _realUnit ) internal view returns (int256 ) {
560561 int256 virtualUnit = _realUnit.conservativePreciseDiv (positionMultiplier);
561562
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
563564 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 " );
565571 }
566572
567573 return virtualUnit;
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ const config: HardhatUserConfig = {
4141 localhost : {
4242 url : "http://127.0.0.1:8545" ,
4343 timeout : 100000 ,
44- gas : 9500000 ,
45- blockGasLimit : 9500000 ,
44+ gas : 12000000 ,
45+ blockGasLimit : 12000000 ,
4646 } ,
4747 kovan : {
4848 url : "https://kovan.infura.io/v3/" + process . env . INFURA_TOKEN ,
Original file line number Diff line number Diff line change 11{
22 "name" : " @setprotocol/set-protocol-v2" ,
3- "version" : " 0.0.43 " ,
3+ "version" : " 0.0.44 " ,
44 "description" : " " ,
55 "main" : " dist" ,
66 "types" : " dist/types" ,
Original file line number Diff line number Diff line change @@ -463,7 +463,19 @@ describe("SetToken", () => {
463463 } ) ;
464464
465465 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" ) ;
467479 } ) ;
468480 } ) ;
469481
You can’t perform that action at this time.
0 commit comments