-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While fixing this issue, we found that the due to tests' inter-dependencies, some tests were failing. My advice would be to take a clean-state approach such that the balances of the users are predictable (same) before each test. However, for now, the tests do pass. Another thing to note is that the flow rate used in tests are very large. Although the tests work as expected, it would be better to consider smaller flow rates. Also replaced `MIN_LOWER` and `MIN_UPPER` with the values in seconds i.e., previously `MIN_LOWER=2` now it's `MIN_LOWER=helper.getSeconds(2)` indicating that `MIN_LOWER` is number of seconds in 2 days.
- Loading branch information
1 parent
a53a188
commit ca2cfac
Showing
3 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol"; | |
import "./interfaces/IERC20Mod.sol"; | ||
import "./interfaces/IStrollManager.sol"; | ||
|
||
|
||
// solhint-disable not-rely-on-time | ||
/// @title StrollManager | ||
/// @author Harsh Prakash <[email protected]> | ||
|
@@ -29,6 +30,9 @@ contract StrollManager is IStrollManager, Ownable { | |
uint64 _minLower, | ||
uint64 _minUpper | ||
) { | ||
if (_icfa == address(0)) revert ZeroAddress(); | ||
if (_minLower >= _minUpper) revert WrongLimits(_minLower, _minUpper); | ||
|
||
CFA_V1 = IConstantFlowAgreementV1(_icfa); | ||
minLower = _minLower; | ||
minUpper = _minUpper; | ||
|
@@ -149,6 +153,20 @@ contract StrollManager is IStrollManager, Ownable { | |
} | ||
} | ||
|
||
/// @dev IStrollManager.setLimits implementation. | ||
function setLimits(uint64 _lowerLimit, uint64 _upperLimit) | ||
external | ||
onlyOwner | ||
{ | ||
if (_lowerLimit >= _upperLimit) | ||
revert WrongLimits(_lowerLimit, _upperLimit); | ||
|
||
minLower = _lowerLimit; | ||
minUpper = _upperLimit; | ||
|
||
emit LimitsChanged(_lowerLimit, _upperLimit); | ||
} | ||
|
||
/// @dev IStrollManager.getTopUp implementation. | ||
function getTopUp( | ||
address _user, | ||
|
@@ -194,7 +212,7 @@ contract StrollManager is IStrollManager, Ownable { | |
TopUp storage topUp = topUps[_index]; | ||
|
||
address user = topUp.user; | ||
|
||
if (user != msg.sender && topUp.expiry >= block.timestamp) | ||
revert UnauthorizedCaller(msg.sender, user); | ||
|
||
|
@@ -244,8 +262,12 @@ contract StrollManager is IStrollManager, Ownable { | |
uint256 superBalance = topUp.superToken.balanceOf(topUp.user); | ||
uint256 positiveFlowRate = uint256(uint96(-1 * flowRate)); | ||
|
||
if (superBalance <= (positiveFlowRate * topUp.lowerLimit)) { | ||
return positiveFlowRate * topUp.upperLimit; | ||
// Selecting max between user defined limits and global limits. | ||
uint64 maxLowerLimit = (topUp.lowerLimit < minLower)? minLower: topUp.lowerLimit; | ||
uint64 maxUpperLimit = (topUp.upperLimit < minUpper)? minUpper: topUp.upperLimit; | ||
|
||
if (superBalance <= (positiveFlowRate * maxLowerLimit)) { | ||
return positiveFlowRate * maxUpperLimit; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters