Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ERC1155Supply extension #418

Merged
merged 60 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
ffe29aa
feat: add erc1155 supply extension
0xNeshi Nov 22, 2024
4f3cbf0
docs: add missing colon (:) in _do_mint errors
0xNeshi Nov 25, 2024
07280d7
feat: add missing fns that use _update
0xNeshi Nov 25, 2024
593382f
test: fix tests
0xNeshi Nov 25, 2024
f03095a
ref: reorganize internal fns
0xNeshi Nov 25, 2024
84b22d2
ref(test): rename tests to refer to mint/burn
0xNeshi Nov 25, 2024
8ab4013
test: add noop test case
0xNeshi Nov 25, 2024
d73d028
fix: remove pub from internal fns
0xNeshi Nov 25, 2024
c6d528c
ref(test): remove unused BOB
0xNeshi Nov 25, 2024
00cc395
docs: fix comments
0xNeshi Nov 25, 2024
5e1f59b
docs: add ADOC
0xNeshi Nov 25, 2024
7603acf
docs: add CHANGELOG
0xNeshi Nov 25, 2024
2c52a35
fix: return 'pub' keyword to all relevant fns
0xNeshi Nov 25, 2024
205fd09
test: add panic unit tests
0xNeshi Nov 25, 2024
4a22ec4
test: check both balance_of and total_supply for mint in unit tests
0xNeshi Nov 25, 2024
360afa2
ref(test): use random_token_ids in mint_panics_on_total_supply_all_ov…
0xNeshi Nov 25, 2024
f45fd5b
test: fix mint_panics_on_total_supply_overflow unit text
0xNeshi Nov 25, 2024
f8209fe
test: add integration tests
0xNeshi Nov 25, 2024
6262b55
ref(test): rename variable in after_mint_batch unit test
0xNeshi Nov 25, 2024
e584fe4
ref(test): add safe transfer (+ batch) tests
0xNeshi Nov 25, 2024
b9b4041
chore: add benches
0xNeshi Nov 25, 2024
bc01405
docs: remove newline from changelog
0xNeshi Nov 25, 2024
5f4c666
docs: add missing newline in adoc
0xNeshi Nov 25, 2024
273e699
test: revert change to e2e script
0xNeshi Nov 25, 2024
923fb6a
Merge branch 'main' into feat/erc1155-supply
0xNeshi Nov 27, 2024
b7a2943
ref: _update calculation
0xNeshi Nov 27, 2024
88b631d
ref: make _update & _update_with_acceptance_check non-public
0xNeshi Nov 27, 2024
4494898
docs: fix paths in comments
0xNeshi Nov 27, 2024
785d875
docs: fix missing backticks warning
0xNeshi Nov 27, 2024
98d57ac
docs: fix URL and fix Metadata mention to Supply
0xNeshi Nov 27, 2024
ba5bb23
ref: iterate over slice instead of calling .iter()
0xNeshi Nov 27, 2024
57b4555
Merge branch 'main' into feat/erc1155-supply
bidzyyys Nov 28, 2024
2e60067
docs: Apply adoc update from code review
0xNeshi Dec 2, 2024
1ce5d28
ref: extract IErc1155Supply trait with shorter comments
0xNeshi Dec 3, 2024
0f694fe
ref: remove erc1155-specific funcs from benches for supply ext.
0xNeshi Dec 3, 2024
1a88aea
chore: merge with main
0xNeshi Dec 3, 2024
bcee629
docs: allow missing error docs
0xNeshi Dec 3, 2024
beaaf52
test: add missing IErc1155Supply import in unit tests
0xNeshi Dec 3, 2024
b6d6129
ref: fix clippy warnings
0xNeshi Dec 3, 2024
d37baf5
test: add missing unit tests for invalid receiver/sender
0xNeshi Dec 3, 2024
c6f91a6
test: setup->init
0xNeshi Dec 3, 2024
f968ca4
Merge branch 'main' into feat/erc1155-supply
0xNeshi Dec 3, 2024
e04f99f
docs: Apply comment suggestions from code review
0xNeshi Dec 4, 2024
2436791
feat: implement [Add/Sub]AssignUnchecked for StorageUint
0xNeshi Dec 4, 2024
33e3844
ref: use sub_assign_unckeched in _update
0xNeshi Dec 4, 2024
36e57ca
chore: add 'mint' to supply bench
0xNeshi Dec 4, 2024
d311910
test: add happy path erc1155 tests
0xNeshi Dec 4, 2024
b8195fb
test: refactor & fix e2e tests
0xNeshi Dec 4, 2024
ea0599c
test: revert change to e2e-tests.sh
0xNeshi Dec 4, 2024
36c1726
test: add missing total_supply assertion in motsu test
0xNeshi Dec 4, 2024
21990cd
docs: update changelog to include changes to math/storage.rs
0xNeshi Dec 5, 2024
012fa17
chore: merge with main
0xNeshi Dec 10, 2024
3db5c35
ref(test): import random_token_ids, random_values from root erc1155
0xNeshi Dec 10, 2024
4d5fba2
ref(test): refactor random_values in erc1155-supply e2e
0xNeshi Dec 10, 2024
0564db4
ref(test): refactor random_values in erc1155 e2e
0xNeshi Dec 10, 2024
bf2216d
ref(test): remove 'rand' from erc1155-supply example
0xNeshi Dec 10, 2024
bf33f24
ref(test): use function_selector in receiver mock
0xNeshi Dec 10, 2024
bb153c6
Merge branch 'main' into feat/erc1155-supply
bidzyyys Dec 10, 2024
f95fe09
ref: set IErc1155Supply to only contain supply-related functions that…
0xNeshi Dec 10, 2024
cb76b30
docs: add note on applying 'selector' to total_supply_all
0xNeshi Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `Erc1155Supply` extension. #418
- `Erc1155Pausable`extension. #432
- `Erc1155UriStorage` extension. #431
- `VestingWallet` contract. #402
Expand All @@ -17,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Implement `AddAssignUnchecked` and `SubAssignUnchecked` for `StorageUint`. #418
- Implement `MethodError` for `safe_erc20::Error`. #402
- Use `function_selector!` to calculate transfer type selector in `Erc1155`. #417
- Update internal functions of `Erc721` and `Erc721Consecutive` accept reference to `Bytes`. #437
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"examples/erc721-metadata",
"examples/erc1155",
"examples/erc1155-metadata-uri",
"examples/erc1155-supply",
"examples/merkle-proofs",
"examples/ownable",
"examples/vesting-wallet",
Expand All @@ -39,6 +40,7 @@ default-members = [
"examples/erc721-metadata",
"examples/erc1155",
"examples/erc1155-metadata-uri",
"examples/erc1155-supply",
"examples/safe-erc20",
"examples/merkle-proofs",
"examples/ownable",
Expand Down
79 changes: 79 additions & 0 deletions benches/src/erc1155_supply.rs
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use alloy::{
network::{AnyNetwork, EthereumWallet},
primitives::Address,
providers::ProviderBuilder,
sol,
sol_types::SolCall,
uint,
};
use e2e::{receipt, Account};

use crate::{
report::{ContractReport, FunctionReport},
CacheOpt,
};

sol!(
#[sol(rpc)]
contract Erc1155Supply {
function mint(address to, uint256 id, uint256 amount, bytes memory data) external;
function totalSupply(uint256 id) external view returns (uint256);
function totalSupply() external view returns (uint256);
function exists(uint256 id) external view returns (bool);
}
);

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("Erc1155Supply"), ContractReport::add)?;

let cached_reports = run_with(CacheOpt::Bid(0)).await?;
let report = cached_reports
.into_iter()
.try_fold(report, ContractReport::add_cached)?;

Ok(report)
}

pub async fn run_with(
cache_opt: CacheOpt,
) -> eyre::Result<Vec<FunctionReport>> {
let alice = Account::new().await?;
let alice_addr = alice.address();
let alice_wallet = ProviderBuilder::new()
.network::<AnyNetwork>()
.with_recommended_fillers()
.wallet(EthereumWallet::from(alice.signer.clone()))
.on_http(alice.url().parse()?);

let contract_addr = deploy(&alice, cache_opt).await?;

let contract = Erc1155Supply::new(contract_addr, &alice_wallet);

let token = uint!(1_U256);
let value = uint!(100_U256);

// IMPORTANT: Order matters!
use Erc1155Supply::*;
#[rustfmt::skip]
let receipts = vec![
0xNeshi marked this conversation as resolved.
Show resolved Hide resolved
(mintCall::SIGNATURE, receipt!(contract.mint(alice_addr, token, value, vec![].into()))?),
(existsCall::SIGNATURE, receipt!(contract.exists(token))?),
(totalSupply_0Call::SIGNATURE, receipt!(contract.totalSupply_0(token))?),
(totalSupply_1Call::SIGNATURE, receipt!(contract.totalSupply_1())?),
];

receipts
.into_iter()
.map(FunctionReport::new)
.collect::<eyre::Result<Vec<_>>>()
}

async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
crate::deploy(account, "erc1155-supply", None, cache_opt).await
}
1 change: 1 addition & 0 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde::Deserialize;
pub mod access_control;
pub mod erc1155;
pub mod erc1155_metadata_uri;
pub mod erc1155_supply;
pub mod erc20;
pub mod erc721;
pub mod merkle_proofs;
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/token/erc1155/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Common extensions to the ERC-1155 standard.
pub mod burnable;
pub mod metadata_uri;
pub mod supply;
pub mod uri_storage;

pub use burnable::IErc1155Burnable;
pub use metadata_uri::{Erc1155MetadataUri, IErc1155MetadataUri};
pub use supply::{Erc1155Supply, IErc1155Supply};
pub use uri_storage::Erc1155UriStorage;
Loading
Loading