Skip to content

Commit

Permalink
Make Drips balances uint256 (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSandwich committed May 10, 2024
1 parent a8932b9 commit bdca796
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Drips.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract Drips is Managed, Streams, Splits {
uint8 public constant DRIVER_ID_OFFSET = 224;
/// @notice The total amount the protocol can store of each token.
/// It's the minimum of _MAX_STREAMS_BALANCE and _MAX_SPLITS_BALANCE.
uint128 public constant MAX_TOTAL_BALANCE = _MAX_STREAMS_BALANCE;
uint256 public constant MAX_TOTAL_BALANCE = _MAX_STREAMS_BALANCE;
/// @notice On every timestamp `T`, which is a multiple of `cycleSecs`, the receivers
/// gain access to steams received during `T - cycleSecs` to `T - 1`.
/// Always higher than 1.
Expand Down Expand Up @@ -232,7 +232,7 @@ contract Drips is Managed, Streams, Splits {
public
view
onlyProxy
returns (uint128 streamsBalance, uint128 splitsBalance)
returns (uint256 streamsBalance, uint256 splitsBalance)
{
Balance storage balance = _dripsStorage().balances[erc20];
return (balance.streams, balance.splits);
Expand Down Expand Up @@ -294,7 +294,7 @@ contract Drips is Managed, Streams, Splits {
/// @param erc20 The used ERC-20 token.
/// @param amt The amount to increase the streams or splits balance by.
function _verifyBalanceIncrease(IERC20 erc20, uint128 amt) internal view {
(uint256 streamsBalance, uint128 splitsBalance) = balances(erc20);
(uint256 streamsBalance, uint256 splitsBalance) = balances(erc20);
uint256 newTotalBalance = streamsBalance + splitsBalance + amt;
require(newTotalBalance <= MAX_TOTAL_BALANCE, "Total balance too high");
require(newTotalBalance <= erc20.balanceOf(address(this)), "Token balance too low");
Expand All @@ -316,7 +316,7 @@ contract Drips is Managed, Streams, Splits {
/// It must be at most the difference between the balance of the token held by the Drips
/// contract address and the sum of balances managed by the protocol as indicated by `balances`.
function withdraw(IERC20 erc20, address receiver, uint256 amt) public onlyProxy {
(uint128 streamsBalance, uint128 splitsBalance) = balances(erc20);
(uint256 streamsBalance, uint256 splitsBalance) = balances(erc20);
uint256 withdrawable = erc20.balanceOf(address(this)) - streamsBalance - splitsBalance;
require(amt <= withdrawable, "Withdrawal amount too high");
emit Withdrawn(erc20, receiver, amt);
Expand Down
4 changes: 2 additions & 2 deletions src/Giver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract GiversRegistry is Managed {
/// @notice The `Drips` contract used by `addressDriver`.
Drips internal immutable _drips;
/// @notice The maximum balance of each token that Drips can hold.
uint128 internal immutable _maxTotalBalance;
uint256 internal immutable _maxTotalBalance;

/// @param addressDriver_ The driver to use to `give`.
constructor(AddressDriver addressDriver_) {
Expand Down Expand Up @@ -136,7 +136,7 @@ contract GiversRegistry is Managed {
address(erc20), "", address(this).balance, "Failed to wrap native tokens"
);
}
(uint128 streamsBalance, uint128 splitsBalance) = _drips.balances(erc20);
(uint256 streamsBalance, uint256 splitsBalance) = _drips.balances(erc20);
uint256 maxAmt = _maxTotalBalance - streamsBalance - splitsBalance;
// The balance of the `Giver` clone contract.
amt = erc20.balanceOf(address(this));
Expand Down
2 changes: 1 addition & 1 deletion test/Drips.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ contract DripsTest is Test {
}

function testMaxBalanceIsNotTooHigh() public {
uint128 maxBalance = drips.MAX_TOTAL_BALANCE();
uint256 maxBalance = drips.MAX_TOTAL_BALANCE();
Constants consts = new Constants();
assertLe(maxBalance, consts.MAX_SPLITS_BALANCE(), "Max balance over max splits balance");
assertLe(maxBalance, consts.MAX_STREAMS_BALANCE(), "Max balance over max streams balance");
Expand Down

0 comments on commit bdca796

Please sign in to comment.