Skip to content

Commit

Permalink
(errors, demurrage): move event DiscountCost down to demurrage; impro…
Browse files Browse the repository at this point in the history
…ve error names
  • Loading branch information
benjaminbollen committed May 6, 2024
1 parent 40ad78b commit 93f7221
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/circles/Demurrage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 4 additions & 8 deletions src/circles/DiscountedBalances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/errors/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/lift/ERC20DiscountedBalances.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 93f7221

Please sign in to comment.