diff --git a/src/circles/Demurrage.sol b/src/circles/Demurrage.sol index eb8da73..18b461e 100644 --- a/src/circles/Demurrage.sol +++ b/src/circles/Demurrage.sol @@ -4,7 +4,7 @@ pragma solidity >=0.8.24; import "../errors/Errors.sol"; import "../lib/Math64x64.sol"; -contract Demurrage is ICirclesERC1155Errors { +contract Demurrage is ICirclesDemurrageErrors { // Type declarations /** @@ -142,6 +142,10 @@ contract Demurrage is ICirclesERC1155Errors { */ int128[15] internal R; + // Events + + event DiscountCost(address indexed account, uint256 indexed id, uint256 discountCost); + // Constructor constructor() { diff --git a/src/circles/DiscountedBalances.sol b/src/circles/DiscountedBalances.sol index 04d16d7..173ce76 100644 --- a/src/circles/DiscountedBalances.sol +++ b/src/circles/DiscountedBalances.sol @@ -13,10 +13,6 @@ contract DiscountedBalances is Demurrage { */ mapping(uint256 => mapping(address => DiscountedBalance)) public discountedBalances; - // Events - - event DiscountCost(address indexed account, uint256 indexed id, uint256 discountCost); - // Constructor /** @@ -45,7 +41,7 @@ contract DiscountedBalances is Demurrage { DiscountedBalance memory discountedBalance = discountedBalances[_id][_account]; if (_day < discountedBalance.lastUpdatedDay) { // DiscountedBalances: day is before last updated day - revert CirclesERC1155DayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 0); + revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 0); } uint256 dayDifference; unchecked { @@ -82,7 +78,7 @@ contract DiscountedBalances is Demurrage { function _updateBalance(address _account, uint256 _id, uint256 _balance, uint64 _day) internal { if (_balance > MAX_VALUE) { // DiscountedBalances: balance exceeds maximum value - revert CirclesERC1155AmountExceedsMaxUint190(_account, _id, _balance, 0); + revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, _balance, 0); } DiscountedBalance storage discountedBalance = discountedBalances[_id][_account]; discountedBalance.balance = uint192(_balance); @@ -100,7 +96,7 @@ contract DiscountedBalances is Demurrage { DiscountedBalance storage discountedBalance = discountedBalances[_id][_account]; if (_day < discountedBalance.lastUpdatedDay) { // DiscountedBalances: day is before last updated day - revert CirclesERC1155DayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 1); + revert CirclesDemurrageDayBeforeLastUpdatedDay(_account, _id, _day, discountedBalance.lastUpdatedDay, 1); } uint256 dayDifference; unchecked { @@ -117,7 +113,7 @@ contract DiscountedBalances is Demurrage { uint256 newBalance = discountedBalanceValue + _value; if (newBalance > MAX_VALUE) { // DiscountedBalances: balance exceeds maximum value - revert CirclesERC1155AmountExceedsMaxUint190(_account, _id, newBalance, 1); + revert CirclesDemurrageAmountExceedsMaxUint190(_account, _id, newBalance, 1); } discountedBalance.balance = uint192(newBalance); discountedBalance.lastUpdatedDay = _day; diff --git a/src/errors/Errors.sol b/src/errors/Errors.sol index 6548d0f..9894daf 100644 --- a/src/errors/Errors.sol +++ b/src/errors/Errors.sol @@ -35,14 +35,16 @@ interface IHubErrors { error CirclesHubNettedFlowMismatch(uint16 vertexPosition, int256 matrixNettedFlow, int256 streamNettedFlow); } -interface ICirclesERC1155Errors { +interface ICirclesDemurrageErrors { error CirclesERC1155MintBlocked(address human, address mintV1Status); - error CirclesERC1155AmountExceedsMaxUint190(address account, uint256 circlesId, uint256 amount, uint8 code); + error CirclesDemurrageAmountExceedsMaxUint190(address account, uint256 circlesId, uint256 amount, uint8 code); - error CirclesERC1155DayBeforeLastUpdatedDay( + error CirclesDemurrageDayBeforeLastUpdatedDay( address account, uint256 circlesId, uint64 day, uint64 lastUpdatedDay, uint8 code ); + + error CirclesERC1155CannotReceiveBatch(uint8 code); } interface ICirclesErrors { @@ -58,8 +60,6 @@ interface ICirclesErrors { error CirclesInvalidParameter(uint256 parameter, uint8 code); - error CirclesERC1155CannotReceiveBatch(uint8 code); - error CirclesAmountOverflow(uint256 amount, uint8 code); error CirclesArraysLengthMismatch(uint256 lengthArray1, uint256 lengthArray2, uint8 code); diff --git a/src/lift/ERC20DiscountedBalances.sol b/src/lift/ERC20DiscountedBalances.sol index 32f93ca..e17dee2 100644 --- a/src/lift/ERC20DiscountedBalances.sol +++ b/src/lift/ERC20DiscountedBalances.sol @@ -70,6 +70,9 @@ contract ERC20DiscountedBalances is ERC20Permit, Demurrage, IERC20 { function balanceOfOnDay(address _account, uint64 _day) public view returns (uint256) { DiscountedBalance memory discountedBalance = discountedBalances[_account]; + if (_day < discountedBalance.lastUpdatedDay) { + // ERC20 DiscountedBalances: day is before last updated day + } return _calculateDiscountedBalance(discountedBalance.balance, _day - discountedBalance.lastUpdatedDay); } @@ -83,7 +86,7 @@ contract ERC20DiscountedBalances is ERC20Permit, Demurrage, IERC20 { function _updateBalance(address _account, uint256 _balance, uint64 _day) internal { if (_balance > MAX_VALUE) { // Balance exceeds maximum value. - revert CirclesERC1155AmountExceedsMaxUint190(_account, 0, _balance, 0); + revert CirclesDemurrageAmountExceedsMaxUint190(_account, 0, _balance, 0); } DiscountedBalance storage discountedBalance = discountedBalances[_account]; discountedBalance.balance = uint192(_balance); @@ -97,7 +100,7 @@ contract ERC20DiscountedBalances is ERC20Permit, Demurrage, IERC20 { ) + _value; if (newBalance > MAX_VALUE) { // Balance exceeds maximum value. - revert CirclesERC1155AmountExceedsMaxUint190(_account, 0, newBalance, 0); + revert CirclesDemurrageAmountExceedsMaxUint190(_account, 0, newBalance, 0); } discountedBalance.balance = uint192(newBalance); discountedBalance.lastUpdatedDay = _day;