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: ERC1155 #275

Merged
merged 80 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c24e0bd
build erc1155 skeleton
programskillforverification Sep 4, 2024
b0539cd
migrate erc1155 uri-storage
programskillforverification Sep 5, 2024
ae3a353
add IErc1155 trait
programskillforverification Sep 6, 2024
f049f1d
try the first erc1155 internal func implementation
programskillforverification Sep 7, 2024
0188be0
add balanceof func and some tests
programskillforverification Sep 9, 2024
b136375
Merge branch 'main' into erc1155
programskillforverification Sep 13, 2024
5b871cc
fix all errors
programskillforverification Sep 13, 2024
b65f68b
add approval func and related tests
programskillforverification Sep 16, 2024
9883651
Merge branch 'main' into erc1155
programskillforverification Sep 18, 2024
654b51b
develop supply extension
programskillforverification Sep 20, 2024
1b2d10e
finish burnable and mod
programskillforverification Sep 21, 2024
4cbbeb7
Merge branch 'main' into erc1155
programskillforverification Sep 21, 2024
dd932cd
rest extensions done
programskillforverification Sep 21, 2024
47afca5
Merge branch 'main' into erc1155
programskillforverification Sep 24, 2024
ccaf2cc
init lib
programskillforverification Sep 24, 2024
cb1ce66
run the first test
programskillforverification Sep 24, 2024
49ba267
Merge branch 'main' into erc1155
programskillforverification Sep 24, 2024
6fc6753
Merge branch 'erc1155-test' into erc1155
programskillforverification Sep 24, 2024
6a87bf9
delete keyword
programskillforverification Sep 24, 2024
60acb14
Merge branch 'main' into erc1155
programskillforverification Sep 25, 2024
a12504b
Merge branch 'main' into erc1155
programskillforverification Sep 27, 2024
bb9627d
erc1155 example
programskillforverification Sep 30, 2024
8e9b006
Merge branch 'main' into erc1155
programskillforverification Sep 30, 2024
3ee507b
add IErc165 to Erc1155`
qalisander Sep 30, 2024
3e7618e
optimise imports
qalisander Sep 30, 2024
11247de
build(deps): bump crate-ci/typos from 1.24.6 to 1.25.0 (#303)
dependabot[bot] Oct 1, 2024
efb27da
Merge branch 'main' into erc1155
programskillforverification Oct 2, 2024
d9a4b62
fix all and add e2e tests
programskillforverification Oct 4, 2024
ea2a6b0
Merge branch 'main' into erc1155
bidzyyys Oct 4, 2024
3c52026
fix: remove redundat stylus-proc dependency
bidzyyys Oct 4, 2024
c22de71
fix: cargo doc
bidzyyys Oct 4, 2024
7901af7
split erc1155 and erc1155-supply
qalisander Oct 4, 2024
1977335
split erc1155 and erc1155-burnable
qalisander Oct 4, 2024
b2c7354
review fixes
qalisander Oct 7, 2024
ef23ba9
remove pausable
qalisander Oct 7, 2024
d3230e4
remove pausable from constructs test
qalisander Oct 7, 2024
f2c2a0f
chore: rename in docs
bidzyyys Oct 8, 2024
3e436df
docs: remove redundant links
bidzyyys Oct 8, 2024
541345b
docs: improve docs for IErc1155 trait
bidzyyys Oct 8, 2024
5452245
ref: IErc1155 trait impl
bidzyyys Oct 8, 2024
dded816
ref: re-use common code
bidzyyys Oct 8, 2024
dc1fc03
docs: docs for Erc1155ReceiverData
bidzyyys Oct 9, 2024
1674f63
test: add unit tests for Erc1155ReceiverData
bidzyyys Oct 9, 2024
090244a
docs: update code docs for ERC-1155 token
bidzyyys Oct 9, 2024
c7b358d
Merge branch 'main' into erc1155
bidzyyys Oct 9, 2024
35a66eb
test(e2e): remove impossible scenarios
bidzyyys Oct 9, 2024
c8f321d
feat: add benches for Erc1155 contract
bidzyyys Oct 10, 2024
b1e8cba
Merge branch 'main' into erc1155
bidzyyys Oct 21, 2024
2046916
ref: remove warning around IERC1155Receiver
bidzyyys Oct 24, 2024
ce661f8
fix: bump Rust version
bidzyyys Oct 24, 2024
5e66a8f
test(e2e): improve E2E tests for Erc1155 contract
bidzyyys Oct 25, 2024
4eb9f69
ref: split IERC1155Receiver interface to another file
bidzyyys Oct 25, 2024
f98e5b3
test(e2e): add E2E tests for ERC1155ReceiverMock transfers
bidzyyys Oct 28, 2024
652007e
test(e2e): E2E tests for batch transfers to ERC1155Receiver contract
bidzyyys Oct 29, 2024
eaf440f
Merge branch 'main' into erc1155
bidzyyys Oct 29, 2024
78e3ea7
test: improve unit tests for Erc1155
bidzyyys Oct 29, 2024
c2ffbde
test: add E2E tests for ERC1155Receiver mints
bidzyyys Oct 30, 2024
0d61c97
Merge branch 'main' into erc1155
bidzyyys Oct 30, 2024
ed1720c
fix: clippy
bidzyyys Oct 30, 2024
ffa4cc8
fix: clippy pass by reference
bidzyyys Oct 30, 2024
d576da8
fix: clippy
bidzyyys Oct 30, 2024
4bd4d12
fix: tests
bidzyyys Oct 30, 2024
e3af8f6
fix: disable clippy used_underscore_items
bidzyyys Oct 30, 2024
af9dadb
Merge branch 'main' into erc1155
bidzyyys Oct 30, 2024
4f16cba
ref: apply CR changes
bidzyyys Nov 2, 2024
c6ad909
Merge branch 'main' into erc1155
bidzyyys Nov 4, 2024
4710faf
owner->account in balance_of comment
0xNeshi Nov 7, 2024
412745d
Fix minor comment issues
0xNeshi Nov 7, 2024
ed2e27c
Merge branch 'main' into erc1155
bidzyyys Nov 7, 2024
361a2b1
docs: update CHANGELOG
bidzyyys Nov 7, 2024
537c2aa
more comment fixes
0xNeshi Nov 7, 2024
b48c1fe
remove redundant multiple accounts in mints_batch
0xNeshi Nov 7, 2024
2f53114
remove empty ctor from Erc1155Example
0xNeshi Nov 7, 2024
cb1e8c6
Add missing unit test cases
0xNeshi Nov 7, 2024
d892603
add missing unit tests
0xNeshi Nov 7, 2024
4ac18dc
Add missing burn-related e2e tests
0xNeshi Nov 7, 2024
55500ae
Merge branch 'main' into erc1155
0xNeshi Nov 7, 2024
efcad3d
Merge branch 'main' into erc1155
bidzyyys Nov 7, 2024
37d0ce1
chore: revert burnable E2E tests
bidzyyys Nov 7, 2024
0b37cf5
fix: benches
bidzyyys Nov 7, 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 Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"examples/erc721",
"examples/erc721-consecutive",
"examples/erc721-metadata",
"examples/erc1155",
"examples/merkle-proofs",
"examples/ownable",
"examples/access-control",
Expand All @@ -32,6 +33,7 @@ default-members = [
"examples/erc721",
"examples/erc721-consecutive",
"examples/erc721-metadata",
"examples/erc1155",
"examples/merkle-proofs",
"examples/ownable",
"examples/access-control",
Expand Down Expand Up @@ -104,10 +106,10 @@ quote = "1.0.35"
openzeppelin-stylus = { path = "contracts" }
openzeppelin-stylus-proc = { path = "contracts-proc", version = "0.1.0" }
openzeppelin-crypto = { path = "lib/crypto" }
motsu = { path = "lib/motsu"}
motsu = { path = "lib/motsu" }
motsu-proc = { path = "lib/motsu-proc", version = "0.1.0" }
e2e = { path = "lib/e2e" }
e2e-proc = {path = "lib/e2e-proc"}
e2e-proc = { path = "lib/e2e-proc" }

[profile.release]
codegen-units = 1
Expand Down
106 changes: 106 additions & 0 deletions benches/src/erc1155.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use alloy::{
network::{AnyNetwork, EthereumWallet},
primitives::Address,
providers::ProviderBuilder,
sol,
sol_types::{SolCall, SolConstructor},
uint,
};
use e2e::{receipt, Account};

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

sol!(
#[sol(rpc)]
contract Erc1155 {
function balanceOf(address account, uint256 id) external view returns (uint256 balance);
function balanceOfBatch(address[] accounts, uint256[] ids) external view returns (uint256[] memory balances);
function isApprovedForAll(address account, address operator) external view returns (bool approved);
function setApprovalForAll(address operator, bool approved) external;
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) external;
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;
}
);

sol!("../examples/erc1155/src/constructor.sol");

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
.into_iter()
.try_fold(ContractReport::new("Erc1155"), 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 bob = Account::new().await?;
let bob_addr = bob.address();

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

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

let token_1 = uint!(1_U256);
let token_2 = uint!(2_U256);
let token_3 = uint!(3_U256);
let token_4 = uint!(4_U256);

let value_1 = uint!(100_U256);
let value_2 = uint!(200_U256);
let value_3 = uint!(300_U256);
let value_4 = uint!(400_U256);

let ids = vec![token_1, token_2, token_3, token_4];
let values = vec![value_1, value_2, value_3, value_4];

let data: alloy_primitives::Bytes = vec![].into();

// IMPORTANT: Order matters!
use Erc1155::*;
#[rustfmt::skip]
let receipts = vec![
(mintCall::SIGNATURE, receipt!(contract.mint(alice_addr, token_1, value_1, data.clone()))?),
(mintBatchCall::SIGNATURE, receipt!(contract.mintBatch(alice_addr, ids.clone(), values.clone(), data.clone()))?),
(balanceOfCall::SIGNATURE, receipt!(contract.balanceOf(alice_addr, token_1))?),
(balanceOfBatchCall::SIGNATURE, receipt!(contract.balanceOfBatch(vec![alice_addr, bob_addr], vec![token_1, token_2]))?),
(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()))?)
];

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

async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = Erc1155Example::constructorCall {};
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc1155", Some(args), 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 @@ -14,6 +14,7 @@ use koba::config::{Deploy, Generate, PrivateKey};
use serde::Deserialize;

pub mod access_control;
pub mod erc1155;
pub mod erc20;
pub mod erc721;
pub mod merkle_proofs;
Expand Down
6 changes: 5 additions & 1 deletion contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
```
*/

#![allow(clippy::pub_underscore_fields, clippy::module_name_repetitions)]
#![allow(
clippy::pub_underscore_fields,
clippy::module_name_repetitions,
clippy::used_underscore_items

Check warning on line 45 in contracts/src/lib.rs

View workflow job for this annotation

GitHub Actions / stable / clippy

[clippy] reported by reviewdog 🐶 warning: unknown lint: `clippy::used_underscore_items` --> contracts/src/lib.rs:45:5 | 45 | clippy::used_underscore_items | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::used_underscore_binding` | = note: `#[warn(unknown_lints)]` on by default Raw Output: contracts/src/lib.rs:45:5:w:warning: unknown lint: `clippy::used_underscore_items` --> contracts/src/lib.rs:45:5 | 45 | clippy::used_underscore_items | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::used_underscore_binding` | = note: `#[warn(unknown_lints)]` on by default __END__
)]
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#![deny(rustdoc::broken_intra_doc_links)]
extern crate alloc;
Expand Down
Loading
Loading