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

Add ERC1155 #896

Merged
merged 33 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e1ffb47
Add ERC1155 module, dual and interface
Dec 11, 2023
1378e54
Implement ERC1155 and update token_id variable names
Dec 12, 2023
5e27ef8
Add ERC1155 receiver mocks and test dual1155 receiver
Dec 12, 2023
8ec925e
apply linter
Dec 12, 2023
1e815d4
Update token_uri variable and remove IERC1155MetadataCamelOnly support
Dec 12, 2023
3fcd640
Add ERC1155 mocks and tests and add ERC1155 preset
Dec 15, 2023
5bf2d86
update CHANGELOG
Dec 15, 2023
7862594
adding PR number (#852)
Dec 15, 2023
1be1f2c
reset changlog
Dec 15, 2023
8836cdd
Merge branch 'main' into migrate-erc1155-contracts
Jan 17, 2024
24d695f
Update ERC1155Component Event and add batch_burn
Jan 18, 2024
fd41fdb
Add batch minting functions for ERC1155 tokens
Jan 18, 2024
5514177
Refactor code for better readability
Jan 24, 2024
a8e27e0
Merge branch 'migrate-erc1155-contracts' of github.com:cloudvenger/ca…
ericnordelo Feb 5, 2024
6ff198e
feat: finish first version with 2.5.3
ericnordelo Feb 5, 2024
d321db6
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 12, 2024
6172605
feat: apply review updates
ericnordelo Feb 12, 2024
c729003
feat: add tests
ericnordelo Feb 13, 2024
3b69f0e
feat: bump version and add entry to CHANGELOG
ericnordelo Feb 13, 2024
7877a83
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 13, 2024
57e3474
feat: add more tests
ericnordelo Feb 15, 2024
c4dc742
fix: remove print
ericnordelo Feb 15, 2024
76922ef
feat: add preset tests
ericnordelo Feb 16, 2024
6da745a
fix: format
ericnordelo Feb 16, 2024
027851a
feat: uncomment test
ericnordelo Feb 16, 2024
00a37e6
refactor: shortening test names
ericnordelo Feb 16, 2024
98dc3aa
Merge branch 'main' of github.com:OpenZeppelin/cairo-contracts into f…
ericnordelo Feb 20, 2024
814ccab
feat: move assertion
ericnordelo Feb 21, 2024
3e13f2c
Update src/token/erc1155/erc1155.cairo
ericnordelo Feb 22, 2024
43b8c67
fix: comments
ericnordelo Feb 22, 2024
991cc8d
Merge branch 'feat/erc1155-#572' of github.com:ericnordelo/cairo-cont…
ericnordelo Feb 22, 2024
71d6235
featL apply review updates
ericnordelo Feb 28, 2024
c77b3c1
feat: remove IAccount
ericnordelo Feb 29, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.4.4"
scarb-version: "2.5.3"
- name: Markdown lint
uses: DavidAnson/markdownlint-cli2-action@5b7c9f74fec47e6b15667b2cc23c63dff11e449e # v9
with:
Expand Down
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "openzeppelin"
version = "0.8.1"
edition = "2023_01"
cairo-version = "2.4.4"
cairo-version = "2.5.3"
authors = ["OpenZeppelin Community <[email protected]>"]
description = "OpenZeppelin Contracts written in Cairo for StarkNet, a decentralized ZK Rollup"
documentation = "https://docs.openzeppelin.com/contracts-cairo"
Expand All @@ -12,7 +12,7 @@ license-file = "LICENSE"
keywords = ["openzeppelin", "starknet", "cairo", "contracts", "security", "standards"]

[dependencies]
starknet = "2.4.4"
starknet = "2.5.3"

[lib]

Expand Down
2 changes: 1 addition & 1 deletion src/account/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ fn execute_calls(mut calls: Array<Call>) -> Array<Span<felt252>> {

fn execute_single_call(call: Call) -> Span<felt252> {
let Call{to, selector, calldata } = call;
starknet::call_contract_syscall(to, selector, calldata.span()).unwrap()
starknet::call_contract_syscall(to, selector, calldata).unwrap()
}
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;
2 changes: 1 addition & 1 deletion src/presets/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// # Account Preset
///
/// OpenZeppelin's basic account which can change its public key and declare, deploy, or call contracts.
#[starknet::contract]
#[starknet::contract(account)]
mod Account {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down
62 changes: 62 additions & 0 deletions src/presets/erc1155.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.8.1 (presets/erc1155.cairo)

/// # ERC1155 Preset
///
/// The ERC1155 contract offers a batch-mint mechanism that
/// can only be executed once upon contract construction.
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
#[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 ERC1155MetadataImpl = ERC1155Component::ERC1155MetadataImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155CamelOnly = ERC1155Component::ERC1155CamelOnlyImpl<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 `name`, `symbol` and `URI`.
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
/// Mints the `values` for `token_ids` tokens to `recipient`.
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
#[constructor]
fn constructor(
ref self: ContractState,
name: ByteArray,
symbol: ByteArray,
token_uri: ByteArray,
recipient: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>
) {
self.erc1155.initializer(name, symbol, token_uri);
self.erc1155.safe_batch_mint(recipient, token_ids, values, array![].span());
}
}
4 changes: 2 additions & 2 deletions src/presets/eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
///
/// OpenZeppelin's account which can change its public key and declare,
/// deploy, or call contracts, using Ethereum signing keys.
#[starknet::contract]
#[starknet::contract(account)]
mod EthAccountUpgradeable {
use openzeppelin::account::EthAccountComponent;
use openzeppelin::account::interface::EthPublicKey;
Expand Down Expand Up @@ -68,7 +68,7 @@ mod EthAccountUpgradeable {
self.eth_account.initializer(public_key);
}

#[external(v0)]
#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.eth_account.assert_only_self();
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_accesscontrol.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use openzeppelin::tests::mocks::accesscontrol_mocks::DualCaseAccessControlMock;
use openzeppelin::tests::utils::constants::{
ADMIN, AUTHORIZED, OTHER, OTHER_ADMIN, ROLE, OTHER_ROLE, ZERO
};
use openzeppelin::tests::utils::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use starknet::ContractAddress;
use starknet::testing;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_dual_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use openzeppelin::tests::mocks::ownable_mocks::{
CamelOwnableMock, CamelOwnablePanicMock, SnakeOwnableMock, SnakeOwnablePanicMock
};
use openzeppelin::tests::utils::constants::{OWNER, NEW_OWNER};
use openzeppelin::tests::utils::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use openzeppelin::utils::serde::SerializedAppend;
use starknet::testing::set_contract_address;
Expand Down
1 change: 0 additions & 1 deletion src/tests/access/test_ownable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::access::ownable::interface::{IOwnable, IOwnableCamelOnly};
use openzeppelin::tests::mocks::ownable_mocks::DualCaseOwnableMock;
use openzeppelin::tests::utils::constants::{ZERO, OTHER, OWNER};
use openzeppelin::tests::utils::debug::DebugContractAddress;
use openzeppelin::tests::utils;
use starknet::ContractAddress;
use starknet::storage::StorageMemberAccessTrait;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/account/test_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn test_execute_with_version(version: Option<felt252>) {
calldata.append_serde(recipient);
calldata.append_serde(amount);
let call = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span()
};
let mut calls = array![];
calls.append(call);
Expand Down Expand Up @@ -334,7 +334,7 @@ fn test_multicall() {
calldata1.append_serde(recipient1);
calldata1.append_serde(amount1);
let call1 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span()
};

// Craft call2
Expand All @@ -343,7 +343,7 @@ fn test_multicall() {
calldata2.append_serde(recipient2);
calldata2.append_serde(amount2);
let call2 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
Expand Down
2 changes: 1 addition & 1 deletion src/tests/account/test_dual_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn test_dual_is_valid_signature_exists_and_panics() {

#[test]
fn test_dual_supports_interface() {
let (snake_dispatcher, target) = setup_snake();
let (snake_dispatcher, _) = setup_snake();
let supports_isrc5 = snake_dispatcher.supports_interface(ISRC5_ID);
assert!(supports_isrc5);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/account/test_dual_eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn test_dual_is_valid_signature_exists_and_panics() {

#[test]
fn test_dual_supports_interface() {
let (snake_dispatcher, target) = setup_snake();
let (snake_dispatcher, _) = setup_snake();
assert!(snake_dispatcher.supports_interface(ISRC5_ID), "Should implement ISRC5");
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/account/test_eth_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn test_execute_with_version(version: Option<felt252>) {
calldata.append_serde(recipient);
calldata.append_serde(amount);
let call = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata.span()
};
let mut calls = array![];
calls.append(call);
Expand Down Expand Up @@ -349,7 +349,7 @@ fn test_multicall() {
calldata1.append_serde(recipient1);
calldata1.append_serde(amount1);
let call1 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata1.span()
};

// Craft call2
Expand All @@ -358,7 +358,7 @@ fn test_multicall() {
calldata2.append_serde(recipient2);
calldata2.append_serde(amount2);
let call2 = Call {
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2
to: erc20.contract_address, selector: selectors::transfer, calldata: calldata2.span()
};

// Bundle calls and exeute
Expand Down
4 changes: 1 addition & 3 deletions src/tests/account/test_secp256k1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fn test_pack_big_secp256k1_points() {
#[test]
fn test_unpack_big_secp256k1_points() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();

// Check point 1

Expand All @@ -60,12 +59,12 @@ fn test_unpack_big_secp256k1_points() {
let (x, y) = StorePacking::unpack((xlow, xhigh_and_parity)).get_coordinates().unwrap();

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

#[test]
fn test_secp256k1_serialization() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();

let mut serialized_point = array![];
let mut expected_serialization = array![];
Expand All @@ -88,7 +87,6 @@ fn test_secp256k1_serialization() {
#[test]
fn test_secp256k1_deserialization() {
let (big_point_1, big_point_2) = get_points();
let curve_size = Secp256k1Impl::get_curve_size();

// Check point 1

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;
martriay marked this conversation as resolved.
Show resolved Hide resolved
mod erc20_mocks;
mod erc721_mocks;
mod erc721_receiver_mocks;
Expand Down
10 changes: 6 additions & 4 deletions src/tests/mocks/account_mocks.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[starknet::contract]
#[starknet::contract(account)]
mod DualCaseAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -45,7 +45,7 @@ mod DualCaseAccountMock {
}
}

#[starknet::contract]
#[starknet::contract(account)]
mod SnakeAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -88,7 +88,7 @@ mod SnakeAccountMock {
}
}

#[starknet::contract]
#[starknet::contract(account)]
mod CamelAccountMock {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
Expand Down Expand Up @@ -132,13 +132,15 @@ mod CamelAccountMock {
self.account.initializer(publicKey);
}

#[external(v0)]
#[abi(per_item)]
#[generate_trait]
impl ExternalImpl of ExternalTrait {
#[external(v0)]
fn __execute__(self: @ContractState, mut calls: Array<Call>) -> Array<Span<felt252>> {
self.account.__execute__(calls)
}

#[external(v0)]
fn __validate__(self: @ContractState, mut calls: Array<Call>) -> felt252 {
self.account.__validate__(calls)
ericnordelo marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading
Loading