Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into qalisander/make-codec…
Browse files Browse the repository at this point in the history
…ov-great-again
  • Loading branch information
qalisander committed Dec 10, 2024
2 parents 9881bfa + a19789a commit 5fc416f
Show file tree
Hide file tree
Showing 18 changed files with 2,067 additions and 2 deletions.
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
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
}
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

0 comments on commit 5fc416f

Please sign in to comment.