Skip to content

Commit

Permalink
(hub, circles): personalMint should not revert, calculateIssuanceWith…
Browse files Browse the repository at this point in the history
…Check
  • Loading branch information
benjaminbollen committed Mar 26, 2024
1 parent eca45c9 commit 88419a2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/circles/Circles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ contract Circles is ERC1155 {

// Public functions

// Internal functions

/**
* @notice Calculate the demurraged issuance for a human's avatar.
* @param _human Address of the human's avatar to calculate the issuance for.
*/
function _calculateIssuance(address _human) internal view returns (uint256) {
function calculateIssuance(address _human) public view returns (uint256) {
MintTime storage mintTime = mintTimes[_human];
if (mintTime.mintV1Status != address(0) && mintTime.mintV1Status != CIRCLES_STOPPED_V1) {
// Circles v1 contract cannot be active.
Expand Down Expand Up @@ -120,15 +118,17 @@ contract Circles is ERC1155 {
return Math64x64.mulu(Math64x64.sub(T[n], overcount), EXA);
}

// Internal functions

/**
* @notice Claim issuance for a human's avatar and update the last mint time.
* @param _human Address of the human's avatar to claim the issuance for.
*/
function _claimIssuance(address _human) internal {
uint256 issuance = _calculateIssuance(_human);
uint256 issuance = calculateIssuance(_human);
if (issuance == 0) {
// No issuance to claim.
revert CirclesERC1155NoMintToIssue(_human, mintTimes[_human].lastMintTime);
// No issuance to claim, simply return without reverting
return;
}
// mint personal Circles to the human
_mint(_human, toTokenId(_human), issuance, "");
Expand Down
2 changes: 0 additions & 2 deletions src/errors/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ interface IHubErrors {
interface ICirclesERC1155Errors {
error CirclesERC1155MintBlocked(address human, address mintV1Status);

error CirclesERC1155NoMintToIssue(address human, uint96 lastMintTime);

error CirclesERC1155AmountExceedsMaxUint190(address account, uint256 circlesId, uint256 amount, uint8 code);
}

Expand Down
7 changes: 4 additions & 3 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,16 @@ contract Hub is Circles, MetadataDefinitions, IHubErrors, ICirclesErrors {
}

/**
* @notice Calculate issuance allows to calculate the issuance for a human avatar.
* @notice Calculate issuance allows to calculate the issuance for a human avatar with a check
* to update the v1 mint status if updated.
* @param _human address of the human avatar to calculate the issuance for
* @return issuance amount of Circles that can be minted
*/
function calculateIssuance(address _human) external returns (uint256) {
function calculateIssuanceWithCheck(address _human) external returns (uint256) {
// check if v1 Circles is known to be stopped and update status
_checkHumanV1CirclesStatus(_human);
// calculate issuance for the human avatar, but don't mint
return _calculateIssuance(_human);
return calculateIssuance(_human);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions test/circles/MockCircles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ contract MockCircles is Circles {
}
}

function calculateIssuance(address _human) external view returns (uint256) {
return _calculateIssuance(_human);
}

function claimIssuance() external {
require(mintTimes[msg.sender].lastMintTime != 0, "Circles: Not registered");
_claimIssuance(msg.sender);
Expand Down

0 comments on commit 88419a2

Please sign in to comment.