Skip to content

feture: refactored ERC6909#284

Open
beebozy wants to merge 2 commits intoPerfect-Abstractions:mainfrom
beebozy:feture-refactor-ERC6909
Open

feture: refactored ERC6909#284
beebozy wants to merge 2 commits intoPerfect-Abstractions:mainfrom
beebozy:feture-refactor-ERC6909

Conversation

@beebozy
Copy link
Contributor

@beebozy beebozy commented Mar 1, 2026

Summary

Changes Made

Checklist

Before submitting this PR, please ensure:

  • Code follows the Solidity feature ban - No inheritance, constructors, modifiers, public/private variables, external library functions, using for directives, or selfdestruct

  • Code follows Design Principles - Readable, uses diamond storage, favors composition over inheritance

  • Code matches the codebase style - Consistent formatting, documentation, and patterns (e.g. ERC20Facet.sol)

  • Code is formatted with forge fmt

  • Existing tests pass - Run tests to be sure existing tests pass.

  • New tests are optional - If you don't provide tests for new functionality or changes then please create a new issue so this can be assigned to someone.

  • All tests pass - Run forge test and ensure everything works

  • Documentation updated - If applicable, update relevant documentation

Make sure to follow the contributing guidelines.

Additional Notes

@netlify
Copy link

netlify bot commented Mar 1, 2026

👷 Deploy request for compose-diamonds pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4386d25

@maxnorm maxnorm requested a review from mudgen March 2, 2026 17:20
@maxnorm maxnorm linked an issue Mar 6, 2026 that may be closed by this pull request
Copy link
Collaborator

@maxnorm maxnorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the redundant subfolder ERC6909. The new approach make it easier to add new features to a standard by only defining a new folder with the feature name under one main ERC6909 folder

* @dev Emits a {Transfer} event to the zero address.
* @param _amount The amount of tokens to burn.
*/
function burnERC6909(uint256 _id, uint256 _amount) external {
Copy link
Collaborator

@maxnorm maxnorm Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for ERC6909 in the selector

* @param _account The address whose tokens will be burned.
* @param _amount The amount of tokens to burn.
*/
function burnERC6909From(address _account, uint256 _id, uint256 _amount) external {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Same here for the selector (no ERC6909)
  • Use _from instead of _account
  • add a InvalidSender error for _from == address(0)

function burnERC6909From(address _account, uint256 _id, uint256 _amount) external {
ERC6909Storage storage s = getStorage();
uint256 currentAllowance = s.allowance[_account][msg.sender][_id];
uint256 fromBalance = s.balanceOf[msg.sender][_id];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure check the right balance (currently, the fromBalance use the caller balance)

}
unchecked {
s.allowance[_account][msg.sender][_id] = currentAllowance - _amount;
s.balanceOf[_account][_id] = fromBalance - _amount;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Move the balance update after the allowance check.
  • Check if the balance is sufficient for the amount burned

You can refer to the current burn & transfer in the ERC6909Mod

s.balanceOf[_account][_id] = fromBalance - _amount;
}
}
emit Transfer(_account, msg.sender, address(0), _id, _amount);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse order

event Transfer(
   address _caller, address indexed _sender, address indexed _receiver, uint256 indexed _id, uint256 _amount
);

Here the _caller = msg.sender and the _sender = _from/_account

* @param _account The address whose tokens will be burned.
* @param _amount The amount of tokens to burn.
*/
function burnERC6909From(address _account, uint256 _id, uint256 _amount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust like the facet

* @param _value The number of tokens to mint.
*/
function mintERC6909(address _account, uint256 _id, uint256 _value) {
ERC6909Storage storage s = getStorage();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get storage after the receiver check. this avoid unneccery storage access if we revert

* @param _account The address receiving the newly minted tokens.
* @param _value The number of tokens to mint.
*/
function mintERC6909(address _account, uint256 _id, uint256 _value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ERC6909 in selector

@beebozy
Copy link
Contributor Author

beebozy commented Mar 8, 2026

Will make the changes and revert before the day ends

@beebozy
Copy link
Contributor Author

beebozy commented Mar 9, 2026

Hi sir, @maxnorm could you review again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Refactor ERC6909 Implementation

2 participants