Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into unit-tests/multiple-c…
Browse files Browse the repository at this point in the history
…ontract-deployment

# Conflicts:
#	contracts/src/token/erc721/mod.rs
#	lib/motsu/src/shims.rs
  • Loading branch information
qalisander committed Dec 11, 2024
2 parents f4a74c5 + 49ff333 commit a5d40c1
Show file tree
Hide file tree
Showing 78 changed files with 7,711 additions and 679 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,4 @@ jobs:
uses: actions/checkout@v4

- name: Check spelling of files in the workspace
uses: crate-ci/[email protected].1
uses: crate-ci/[email protected].2
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ 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
- `Erc1155Burnable` extension. #417
- `Erc1155MetadataUri` extension. #416
- `Poseidon2` sponge hash function. #388

### Changed

- Update "magic values" to explicit calculations in `Erc721Metadata::supports_interface`, and `Erc721::_check_on_erc721_received`. #442
- 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

### Fixed

Expand All @@ -28,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- ERC-1155 Multi Token Standard. #275
- `SafeErc20` Utility. #289
- Finite Fields arithmetics. #376
- Finite Fields arithmetic. #376
- `Ownable2Step` contract. #352
- `IOwnable` trait. #352

Expand All @@ -40,7 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Mini alloc is now used by default via the stylus-sdk. This avoids conflicts with duplicate `#[global_allocator]` definitions. #373
- Mini alloc is now used by default via the stylus-sdk. This avoids conflicts with duplicate `#[global_allocator]`
definitions. #373
- Removed the panic handler from the library, making it easier for `std` and `no_std` projects to use the library. #373

## [0.1.0] - 2024-10-17
Expand Down
26 changes: 26 additions & 0 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ members = [
"examples/erc721-consecutive",
"examples/erc721-metadata",
"examples/erc1155",
"examples/erc1155-metadata-uri",
"examples/erc1155-supply",
"examples/merkle-proofs",
"examples/ownable",
"examples/vesting-wallet",
Expand All @@ -35,6 +37,8 @@ default-members = [
"examples/erc721-consecutive",
"examples/erc721-metadata",
"examples/erc1155",
"examples/erc1155-metadata-uri",
"examples/erc1155-supply",
"examples/safe-erc20",
"examples/merkle-proofs",
"examples/ownable",
Expand Down Expand Up @@ -100,7 +104,9 @@ tiny-keccak = { version = "2.0.2", features = ["keccak"] }
tokio = { version = "1.12.0", features = ["full"] }
futures = "0.3.30"
dashmap = "6.1.0"
crypto-bigint = { version = "0.5.5", default-features = false, features = ["zeroize"] }
crypto-bigint = { version = "0.5.5", default-features = false, features = [
"zeroize",
] }
num-traits = "0.2.14"
zeroize = { version = "1.8.1", features = ["derive"] }
proptest = "1"
Expand Down Expand Up @@ -134,3 +140,10 @@ incremental = false

[profile.dev]
panic = "abort"

[workspace.metadata.typos]
default = { extend-ignore-identifiers-re = [
# ignore hex data samples.
"[0-9a-fA-F][0-9a-fA-F]",
] }
files = { extend-exclude = [] }
12 changes: 2 additions & 10 deletions benches/src/erc1155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use alloy::{
primitives::Address,
providers::ProviderBuilder,
sol,
sol_types::{SolCall, SolConstructor},
sol_types::SolCall,
uint,
};
use e2e::{receipt, Account};
Expand All @@ -26,14 +26,9 @@ sol!(
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;
function uri(uint256 id) external view returns (string memory uri);
}
);

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

const URI: &str = "https://github.com/OpenZeppelin/rust-contracts-stylus";

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports
Expand Down Expand Up @@ -102,7 +97,6 @@ pub async fn run_with(
// 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))?),
(uriCall::SIGNATURE, receipt!(contract.uri(token_1))?),
];

receipts
Expand All @@ -115,7 +109,5 @@ async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args = Erc1155Example::constructorCall { uri_: URI.to_owned() };
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc1155", Some(args), cache_opt).await
crate::deploy(account, "erc1155", None, cache_opt).await
}
85 changes: 85 additions & 0 deletions benches/src/erc1155_metadata_uri.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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 Erc1155MetadataUri {
function uri(uint256 id) external view returns (string memory uri);
function setTokenURI(uint256 tokenId, string memory tokenURI) external;
function setBaseURI(string memory tokenURI) external;
}
);

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

const URI: &str = "https://github.com/OpenZeppelin/rust-contracts-stylus";
const BASE_URI: &str = "https://github.com";
const TOKEN_URI: &str = "/some/token/uri";

pub async fn bench() -> eyre::Result<ContractReport> {
let reports = run_with(CacheOpt::None).await?;
let report = reports.into_iter().try_fold(
ContractReport::new("Erc1155MetadataUri"),
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_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 = Erc1155MetadataUri::new(contract_addr, &alice_wallet);

let token_id = uint!(1_U256);

// IMPORTANT: Order matters!
use Erc1155MetadataUri::*;
#[rustfmt::skip]
let receipts = vec![
(setTokenURICall::SIGNATURE, receipt!(contract.setTokenURI(token_id, TOKEN_URI.to_owned()))?),
(setBaseURICall::SIGNATURE, receipt!(contract.setBaseURI(BASE_URI.to_owned()))?),
(uriCall::SIGNATURE, receipt!(contract.uri(token_id))?),
];

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

async fn deploy(
account: &Account,
cache_opt: CacheOpt,
) -> eyre::Result<Address> {
let args =
Erc1155MetadataUriExample::constructorCall { uri_: URI.to_owned() };
let args = alloy::hex::encode(args.abi_encode());
crate::deploy(account, "erc1155-metadata-uri", Some(args), cache_opt).await
}
79 changes: 79 additions & 0 deletions benches/src/erc1155_supply.rs
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![
(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
}
2 changes: 2 additions & 0 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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
5 changes: 3 additions & 2 deletions benches/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use benches::{
access_control, erc1155, erc20, erc721, merkle_proofs, ownable,
report::BenchmarkReport,
access_control, erc1155, erc1155_metadata_uri, erc20, erc721,
merkle_proofs, ownable, report::BenchmarkReport,
};
use futures::FutureExt;
use itertools::Itertools;
Expand All @@ -14,6 +14,7 @@ async fn main() -> eyre::Result<()> {
merkle_proofs::bench().boxed(),
ownable::bench().boxed(),
erc1155::bench().boxed(),
erc1155_metadata_uri::bench().boxed(),
];

// Run benchmarks max 3 at the same time.
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["OpenZeppelin", ".."]
Loading

0 comments on commit a5d40c1

Please sign in to comment.