Skip to content

feat: ERC1155Burnable extension #417

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

Merged
merged 39 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5e96f2c
feat: add burnable
0xNeshi Nov 22, 2024
b22707d
test: add e2e tests
0xNeshi Nov 22, 2024
e4b47a8
ref(test): cleanup
0xNeshi Nov 22, 2024
0296a22
ref: use function_selector macro to calc receiver selectors
0xNeshi Nov 22, 2024
7a18f4a
docs: add changelog
0xNeshi Nov 22, 2024
b98e52c
test: add new unit tests
0xNeshi Nov 22, 2024
bab64f1
ref(test): use U256::ZERO instead of uint!(0_U256)
0xNeshi Nov 22, 2024
dd00bb5
docs: add adoc file
0xNeshi Nov 22, 2024
7e32ca7
ref(docs): reword _do_burn InsufficientBalance error descr
0xNeshi Nov 22, 2024
6f71064
ref(docs): add missing errors
0xNeshi Nov 22, 2024
42083a3
ref(docs): remove redundant newline from changelog
0xNeshi Nov 22, 2024
e2db9cc
ref(test): remove the need for setOperatorApprovals
0xNeshi Nov 22, 2024
407541b
chore: add benches
0xNeshi Nov 22, 2024
6b85438
test: add back setOperatorApprovals
0xNeshi Nov 22, 2024
204565d
docs: add missing PR id to changelog
0xNeshi Nov 25, 2024
7ab0e79
docs: update comments/test messages as per review suggestions
0xNeshi Nov 25, 2024
791f35c
Merge branch 'main' into feat/erc1155-burnable
0xNeshi Nov 25, 2024
bc948de
docs: update fn descriptions
0xNeshi Nov 26, 2024
3cfbd42
docs: remove requirements sections from trait
0xNeshi Nov 26, 2024
ca6e107
ref: extract ensure_approved_or_owner helper
0xNeshi Nov 26, 2024
9a70959
ref(test): update random_values to return non-random values
0xNeshi Nov 26, 2024
f6b44d6
ref(test): import random_[values/token_ids] from erc1155/mod.rs
0xNeshi Nov 26, 2024
8cc41e4
test: add missing insufficient balance tests for burn(batch)
0xNeshi Nov 26, 2024
3fa8c90
test(erc20): fix error_when_transfer_from_in_paused_state test name
0xNeshi Nov 26, 2024
7f45244
test: revert changes to e2e-tests.sh
0xNeshi Nov 26, 2024
55a7e5f
docs: fix comment in erc20burnable
0xNeshi Nov 26, 2024
a4d790d
docs: fix comments
0xNeshi Nov 26, 2024
0366a32
test: add missing insufficient balance unit tests
0xNeshi Nov 26, 2024
66273e6
test: change ERC1155InsufficientBalance.id to tokenId in e2e
0xNeshi Nov 26, 2024
ad7cf87
test: fix tests in burnable
0xNeshi Nov 26, 2024
fbe49c1
test: use fn selector consts in erc1155 unit tests
0xNeshi Nov 26, 2024
44c0fac
revert: erc20 test name
0xNeshi Nov 26, 2024
12dab5e
test: remove setOperatorApproval + remove burn for invalid sender tests
0xNeshi Nov 26, 2024
7c472c4
Merge branch 'main' into feat/erc1155-burnable
0xNeshi Nov 27, 2024
797a5a3
fix burn in benches
qalisander Nov 28, 2024
99065ab
Add restriction on the number of benchmarks running in parallel.
qalisander Nov 28, 2024
b6dbd4e
doc fix
qalisander Nov 28, 2024
ae8aa81
ref: remove unused 'report' import from benches/main
0xNeshi Nov 28, 2024
e5cc231
docs: fix URL in adoc
0xNeshi Nov 28, 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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- `IErc1155Burnable` extension. #417

### Changed

- Use `function_selector!` to calculate transfer type selector in `Erc1155`. #417

### Fixed

-

## [v0.2.0-alpha.1] - 2024-11-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ koba.workspace = true
e2e.workspace = true
serde = "1.0.203"
keccak-const = "0.2.0"
itertools = "0.13.0"
13 changes: 12 additions & 1 deletion benches/src/erc1155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ sol!(
function safeBatchTransferFrom(address from, address to, uint256[] memory ids, uint256[] memory values, bytes memory data) external;
function mint(address to, uint256 id, uint256 amount, bytes memory data) external;
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) external;
function burn(address account, uint256 id, uint256 value) external;
function burnBatch(address account, uint256[] memory ids, uint256[] memory values) external;
}
);

Expand Down Expand Up @@ -56,10 +58,16 @@ pub async fn run_with(

let bob = Account::new().await?;
let bob_addr = bob.address();
let bob_wallet = ProviderBuilder::new()
.network::<AnyNetwork>()
.with_recommended_fillers()
.wallet(EthereumWallet::from(bob.signer.clone()))
.on_http(bob.url().parse()?);

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

let contract = Erc1155::new(contract_addr, &alice_wallet);
let contract_bob = Erc1155::new(contract_addr, &bob_wallet);

let token_1 = uint!(1_U256);
let token_2 = uint!(2_U256);
Expand Down Expand Up @@ -87,7 +95,10 @@ pub async fn run_with(
(setApprovalForAllCall::SIGNATURE, receipt!(contract.setApprovalForAll(bob_addr, true))?),
(isApprovedForAllCall::SIGNATURE, receipt!(contract.isApprovedForAll(alice_addr, bob_addr))?),
(safeTransferFromCall::SIGNATURE, receipt!(contract.safeTransferFrom(alice_addr, bob_addr, token_1, value_1, data.clone()))?),
(safeBatchTransferFromCall::SIGNATURE, receipt!(contract.safeBatchTransferFrom(alice_addr, bob_addr, ids, values, data.clone()))?)
(safeBatchTransferFromCall::SIGNATURE, receipt!(contract.safeBatchTransferFrom(alice_addr, bob_addr, ids.clone(), values.clone(), data))?),
// We should burn Bob's tokens on behalf of Bob not Alice.
(burnCall::SIGNATURE, receipt!(contract_bob.burn(bob_addr, token_1, value_1))?),
(burnBatchCall::SIGNATURE, receipt!(contract_bob.burnBatch(bob_addr, ids, values))?),
];

receipts
Expand Down
22 changes: 16 additions & 6 deletions benches/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
use benches::{
access_control, erc20, erc721, merkle_proofs, ownable,
access_control, erc1155, erc20, erc721, merkle_proofs, ownable,
report::BenchmarkReport,
};
use futures::FutureExt;
use itertools::Itertools;

#[tokio::main]
async fn main() -> eyre::Result<()> {
let report = futures::future::try_join_all([
let benchmarks = [
access_control::bench().boxed(),
erc20::bench().boxed(),
erc721::bench().boxed(),
merkle_proofs::bench().boxed(),
ownable::bench().boxed(),
])
.await?
.into_iter()
.fold(BenchmarkReport::default(), BenchmarkReport::merge_with);
erc1155::bench().boxed(),
];

// Run benchmarks max 3 at the same time.
// Otherwise, nitro test node can overload and revert transaction.
const MAX_PARALLEL: usize = 3;
let mut report = BenchmarkReport::default();
for chunk in &benchmarks.into_iter().chunks(MAX_PARALLEL) {
report = futures::future::try_join_all(chunk)
.await?
.into_iter()
.fold(report, BenchmarkReport::merge_with);
}

println!();
println!("{report}");
Expand Down
Loading
Loading