Skip to content

Conversation

onurinanc
Copy link
Contributor

@onurinanc onurinanc commented Aug 7, 2025

PR Checklist

  • Tests
  • Documentation
  • Changelog

ERC6909 Implementation in rust-contracts-stylus

Summary

This PR implements the ERC-6909 token and Supply extension in Rust for Arbitrum Stylus.

The following implementation is provided in this PR:

  • ERC-6909 + unit tests with motsu
  • Supply Extension + unit tests with motsu
  • Example usage of ERC-6909 and Supply Extension
  • Integration Tests for ERC-6909 and Supply Extension
  • Benchmark for both ERC6909 and Supply Extension

Comments

Integration tests and the benchmarks inside rust-contracts-stylus, which use nitro-testnode, didn't work with the M3 Pro Chip (would be an issue related to Docker). To solve the problem, firstly, [nitro-devnode] is tried to use. However, I observed that it is not suitable for the e2e::test workflow. So, an LTS Ubuntu machine is rented on AWS to run the integration tests and the benchmark.

For the Supply Extension implementation, Deref traits are implemented. Using Deref allows direct access to Erc6909 methods, improving readability and maintainability. However, deferencing operations might increase the gas. Designing Supply Token Extension in this way increases the abstraction and makes it easy to use for users who would like to use the Supply Extension with ERC-6909 Token Contract.

Future Improvements

Currently, this PR does not include other ERC-6909 Extensions, specifically ContentURI and Metadata. Their example usage and the benchmarks should be added to the repository.

The unit tests that differentiate the id should be added.

Benchmark

Benchmarks for ERC-6909 can be seen as follows:

| Contract::function                                                        | WASM Opt & Cached | Cached | Not Cached |
| ------------------------------------------------------------------------- | ----------------- | ------ | ---------- |
| Erc6909::mint(address,uint256,uint256)                                    |             27925 |  29307 |      45089 |
| Erc6909::balanceOf(address,uint256)                                       |              5101 |   6448 |      22230 |
| Erc6909::allowance(address,address,uint256)                               |              5875 |   7228 |      23010 |
| Erc6909::isOperator(address,address)                                      |              5322 |   6666 |      22448 |
| Erc6909::setOperator(address,bool)                                        |             27045 |  28433 |      44215 |
| Erc6909::transfer(address,uint256,uint256)                                |             34364 |  35786 |      51568 |
| Erc6909::approve(address,uint256,uint256)                                 |             27939 |  29332 |      45114 |
| Erc6909::transferFrom(address,address,uint256,uint256)                    |             20503 |  21943 |      37725 |
| Erc6909::burn(address,uint256,uint256)                                    |             11495 |  12893 |      28675 |

Copy link

netlify bot commented Aug 7, 2025

Deploy Preview for contracts-stylus canceled.

Name Link
🔨 Latest commit d2c0d06
🔍 Latest deploy log https://app.netlify.com/projects/contracts-stylus/deploys/68a57f180e24a5000885bb66

@bidzyyys bidzyyys changed the title Feature/erc6909 feat: add ERC-6909 Token and Supply extension Aug 7, 2025
@bidzyyys bidzyyys linked an issue Aug 7, 2025 that may be closed by this pull request
1 task
@bidzyyys bidzyyys linked an issue Aug 7, 2025 that may be closed by this pull request
1 task
};

use super::*;
use crate::token::erc6909::{ERC6909InvalidReceiver, ERC6909InvalidSender};
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused import: ERC6909InvalidReceiver

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of removing the error, could you add a test case covering the flow where this error is returned?

assert!(supports_interface_erc165);

Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing Antora docs (see docs/modules/ROOT)

@onurinanc onurinanc requested a review from 0xNeshi August 8, 2025 13:18
};

use super::*;
use crate::token::erc6909::{ERC6909InvalidReceiver, ERC6909InvalidSender};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of removing the error, could you add a test case covering the flow where this error is returned?

@@ -0,0 +1,10 @@
= ERC-6909
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you update this docs file to include a wider description of what the contract is, with an example implementation?
You probably used erc1155.adoc as inspiration for this, but it's also missing these things.
You can use erc20.adoc or erc721.adoc as inspiration.

For the example implementation, it would be sufficient to just copy/paste the code from examples/erc6909/src/lib.rs (we will have a more maintainable solution at some point).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, could you check it now?

CHANGELOG.md Outdated
Comment on lines 25 to 26
- Add ERC-6909 Token. #778
- Add ERC-6909 Supply Extension. # 779
Copy link
Collaborator

@0xNeshi 0xNeshi Aug 13, 2025

Choose a reason for hiding this comment

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

Suggested change
- Add ERC-6909 Token. #778
- Add ERC-6909 Supply Extension. # 779
- Add `Erc6909` contract and `Erc6909TokenSupply` extension. #777

The linked PR ID should be of the PR where this was implemented (in your case, the ID of this PR).

@onurinanc onurinanc requested a review from 0xNeshi August 13, 2025 12:58
@onurinanc
Copy link
Contributor Author

Hey, any update on this PR @0xNeshi ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add ERC-6909 Supply Extension [Feature]: Implement ERC-6909 Token
3 participants