Skip to content

Commit

Permalink
Add ERC1155 (#896)
Browse files Browse the repository at this point in the history
* Add ERC1155 module, dual and interface

* Implement ERC1155 and update token_id variable names

* Add ERC1155 receiver mocks and test dual1155 receiver

* apply linter

* Update token_uri variable and remove IERC1155MetadataCamelOnly support

* Add ERC1155 mocks and tests and add ERC1155 preset

* update CHANGELOG

* adding PR number (#852)

* reset changlog

* Update ERC1155Component Event and add batch_burn

* Add batch minting functions for ERC1155 tokens

* Refactor code for better readability
Update error testing and remove tests failing from erc1155

* feat: finish first version with 2.5.3

* feat: apply review updates

* feat: add tests

* feat: bump version and add entry to CHANGELOG

* feat: add more tests

* fix: remove print

* feat: add preset tests

* fix: format

* feat: uncomment test

* refactor: shortening test names

* feat: move assertion

* Update src/token/erc1155/erc1155.cairo

Co-authored-by: Martín Triay <[email protected]>

* fix: comments

* featL apply review updates

* feat: remove IAccount

---------

Co-authored-by: Arn0d <[email protected]>
Co-authored-by: Martín Triay <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent e47c5fb commit ca11b87
Show file tree
Hide file tree
Showing 29 changed files with 4,478 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- ERC1155 component and preset (#896)

### Changed

- Change unwrap to unwrap_syscall (#901)
Expand Down
2 changes: 2 additions & 0 deletions src/presets.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod account;
mod erc1155;
mod erc20;
mod erc721;
mod eth_account;

use account::Account;
use erc1155::ERC1155;
use erc20::ERC20;
use erc721::ERC721;
use eth_account::EthAccountUpgradeable;
72 changes: 72 additions & 0 deletions src/presets/erc1155.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.9.0 (presets/erc1155.cairo)

/// # ERC1155 Preset
///
/// The ERC1155 contract offers a batch-mint mechanism that
/// can only be executed once upon contract construction.
///
/// For more complex or custom contracts, use Wizard for Cairo
/// https://wizard.openzeppelin.com/cairo
#[starknet::contract]
mod ERC1155 {
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::token::erc1155::ERC1155Component;
use starknet::ContractAddress;

component!(path: ERC1155Component, storage: erc1155, event: ERC1155Event);
component!(path: SRC5Component, storage: src5, event: SRC5Event);

// ERC1155
#[abi(embed_v0)]
impl ERC1155Impl = ERC1155Component::ERC1155Impl<ContractState>;
#[abi(embed_v0)]
impl ERC1155MetadataURIImpl =
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;
impl ERC1155InternalImpl = ERC1155Component::InternalImpl<ContractState>;

// SRC5
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc1155: ERC1155Component::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
ERC1155Event: ERC1155Component::Event,
#[flat]
SRC5Event: SRC5Component::Event
}

/// Sets the `token_uri`.
/// Mints the `values` for `token_ids` tokens to `recipient`.
///
/// Requirements:
///
/// - `to` is either an account contract (supporting ISRC6) or
/// supports the `IERC1155Receiver` interface.
/// - `token_ids` and `values` must have the same length.
#[constructor]
fn constructor(
ref self: ContractState,
token_uri: ByteArray,
recipient: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>
) {
self.erc1155.initializer(token_uri);
self
.erc1155
.batch_mint_with_acceptance_check(recipient, token_ids, values, array![].span());
}
}
1 change: 1 addition & 0 deletions src/tests/account/test_secp256k1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn test_unpack_big_secp256k1_points() {
let (x, _) = StorePacking::unpack((xlow, xhigh_and_parity)).get_coordinates().unwrap_syscall();

assert_eq!(x, expected_x);
assert_eq!(y, expected_y);
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/tests/mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod accesscontrol_mocks;
mod account_mocks;
mod erc1155_mocks;
mod erc1155_receiver_mocks;
mod erc20_mocks;
mod erc721_mocks;
mod erc721_receiver_mocks;
Expand Down
Loading

0 comments on commit ca11b87

Please sign in to comment.