Skip to content

Commit

Permalink
(hub, circles): suppress group mint's acceptance call if along a path…
Browse files Browse the repository at this point in the history
… and not terminal flow
  • Loading branch information
benjaminbollen committed Sep 30, 2024
1 parent 74a6435 commit 61be206
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/circles/Circles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,21 @@ contract Circles is ERC1155, ICirclesErrors {
return;
}
// mint personal Circles to the human
_mintAndUpdateTotalSupply(_human, toTokenId(_human), issuance, "");
_mintAndUpdateTotalSupply(_human, toTokenId(_human), issuance, "", true);
// update the last mint time
mintTimes[_human].lastMintTime = uint96(block.timestamp);

emit PersonalMint(_human, issuance, startPeriod, endPeriod);
}

function _mintAndUpdateTotalSupply(address _account, uint256 _id, uint256 _value, bytes memory _data) internal {
_mint(_account, _id, _value, _data);
function _mintAndUpdateTotalSupply(
address _account,
uint256 _id,
uint256 _value,
bytes memory _data,
bool _doAcceptanceCheck
) internal {
_mint(_account, _id, _value, _data, _doAcceptanceCheck);

uint64 today = day(block.timestamp);
DiscountedBalance memory totalSupplyBalance = discountedTotalSupplies[_id];
Expand Down
9 changes: 7 additions & 2 deletions src/circles/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,20 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC
* Requirements:
*
* - `to` cannot be the zero address.
* - If `_doAcceptanceCheck` is true, it will perform ERC1155 acceptance check, otherwise only update
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
function _mint(address to, uint256 id, uint256 value, bytes memory data, bool _doAcceptanceCheck) internal {
if (to == address(0)) {
revert ERC1155InvalidReceiver(address(0));
}
(uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
if (_doAcceptanceCheck) {
_updateWithAcceptanceCheck(address(0), to, ids, values, data);
} else {
_update(address(0), to, ids, values);
}
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
_burnAndUpdateTotalSupply(_inviter, toTokenId(_inviter), INVITATION_COST);

// mint the welcome bonus to the newly registered human
_mintAndUpdateTotalSupply(msg.sender, toTokenId(msg.sender), WELCOME_BONUS, "");
_mintAndUpdateTotalSupply(msg.sender, toTokenId(msg.sender), WELCOME_BONUS, "", true);
}
}

Expand Down Expand Up @@ -499,7 +499,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {

for (uint256 i = 0; i < _avatars.length; i++) {
// mint the migrated balances to _owner
_mintAndUpdateTotalSupply(_owner, toTokenId(_avatars[i]), _amounts[i], "");
_mintAndUpdateTotalSupply(_owner, toTokenId(_avatars[i]), _amounts[i], "", true);
}
}

Expand Down Expand Up @@ -726,7 +726,9 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
safeBatchTransferFrom(_sender, treasuries[_group], _collateral, _amounts, dataWithGroup);

// mint group Circles to the receiver and send the original _data onwards
_mintAndUpdateTotalSupply(_receiver, toTokenId(_group), sumAmounts, _data);
// only if it is an explicit call perform the ERC1155 acceptance call; if not (ie via path),
// suppress the normal acceptance call and only perform the final stream based acceptance calls
_mintAndUpdateTotalSupply(_receiver, toTokenId(_group), sumAmounts, _data, _explicitCall);
}

/**
Expand Down

0 comments on commit 61be206

Please sign in to comment.