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: migrate repo from Cairo 2.2.0 - 2.6.4 #41

Merged
merged 14 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
- uses: actions/checkout@v3
- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.6.5"
- name: Check cairo format
run: scarb fmt --check
- name: Build cairo programs
run: scarb build
run: scarb build
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
- uses: actions/checkout@v3
- name: Set up Scarb
uses: software-mansion/setup-scarb@v1
- name: Set up Starknet Foundry
uses: foundry-rs/setup-snfoundry@v3
- name: Run cairo tests
run: scarb test

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target/
target/
.snfoundry*
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scarb 2.6.5
starknet-foundry 0.27.0
20 changes: 20 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "cairo_erc_3525"
version = "2.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
name = "openzeppelin"
version = "0.14.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b"

[[package]]
name = "snforge_std"
version = "0.27.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de"
13 changes: 8 additions & 5 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
name = "cairo_erc_3525"
version = "2.1.0"
edition = "2023_01"
cairo-version = "2.6.3"
cairo-version = "2.6.4"

[lib]

[dependencies]
starknet = ">=2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.19.0" }
starknet = "2.6.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.14.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" }

[[target.starknet-contract]]
sierra = true
casm = true

[scripts]
test = "snforge test"

[tool.snforge]
exit_first = false
exit_first = false
6 changes: 3 additions & 3 deletions src/extensions/metadata/module.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ mod ERC3525MetadataComponent {
use starknet::ContractAddress;

// External deps
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait;
use openzeppelin::introspection::src5::SRC5Component::{SRC5, SRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::introspection::src5::{
SRC5Component, SRC5Component::InternalTrait as SRC5InternalTrait
};

// Local deps
use cairo_erc_3525::extensions::metadata::interface::{
Expand Down
18 changes: 9 additions & 9 deletions src/extensions/slotapprovable/module.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[starknet::component]
mod ERC3525SlotApprovableComponent {
// Core deps
use openzeppelin::token::erc721::interface::IERC721;
use traits::{Into, TryInto};
use option::OptionTrait;
use zeroable::Zeroable;
Expand All @@ -10,13 +11,12 @@ mod ERC3525SlotApprovableComponent {
use starknet::{get_caller_address, ContractAddress};

// External deps
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait;
use openzeppelin::introspection::src5::SRC5Component::{SRC5, SRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;

use openzeppelin::token::erc721::erc721::ERC721Component::InternalTrait as ERC721InternalTrait;
use openzeppelin::token::erc721::erc721::ERC721Component::ERC721;
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::introspection::src5::{
SRC5Component, SRC5Component::InternalTrait as SRC5InternalTrait
};
use openzeppelin::token::erc721::{
ERC721Component, ERC721HooksEmptyImpl, ERC721Component::InternalTrait as ERC721InternalTrait
};

// Local deps
use cairo_erc_3525::module::ERC3525Component::InternalTrait as ERC3525InternalTrait;
Expand Down Expand Up @@ -143,7 +143,7 @@ mod ERC3525SlotApprovableComponent {

// [Effect] Store approval
let mut erc721_comp = get_dep_component_mut!(ref self, ERC721Comp);
erc721_comp._approve(to, token_id);
erc721_comp.approve(to, token_id);
}

fn approve_value(
Expand Down Expand Up @@ -249,7 +249,7 @@ mod ERC3525SlotApprovableComponent {
// [Compute] Operator is owner or approved for all
let erc721_comp = get_dep_component!(self, ERC721Comp);
let owner = erc721_comp.owner_of(token_id);
let is_owner_or_approved = erc721_comp._is_approved_or_owner(operator, token_id);
let is_owner_or_approved = erc721_comp.get_approved(token_id) == operator;

// [Compute] Operator is approved for slot
let erc3525_comp = get_dep_component!(self, ERC3525Comp);
Expand Down
7 changes: 6 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ mod presets {
mod erc3525_mintable_burnable_metadata_slot_approvable_slot_enumerable;
}

mod tests;
mod test_helpers {
mod account;
mod contracts;
mod receiver;
mod utils;
}
21 changes: 11 additions & 10 deletions src/module.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[starknet::component]
mod ERC3525Component {
// Core deps
use openzeppelin::token::erc721::interface::IERC721;
use array::{ArrayTrait, SpanTrait};
use option::OptionTrait;
use traits::{Into, TryInto};
Expand All @@ -12,12 +13,12 @@ mod ERC3525Component {

// External deps
use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait;
use openzeppelin::introspection::src5::SRC5Component::{SRC5, SRC5Camel};
// use openzeppelin::introspection::src5::SRC5Component::{SRC5, SRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait};
use openzeppelin::token::erc721::erc721::ERC721Component::InternalTrait as ERC721InternalTrait;
use openzeppelin::token::erc721::erc721::ERC721Component::ERC721;
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::token::erc721::{
ERC721Component, ERC721HooksEmptyImpl, ERC721Component::InternalTrait as ERC721InternalTrait
};
use openzeppelin::account::interface::ISRC6_ID;

// Local deps
Expand Down Expand Up @@ -131,7 +132,7 @@ mod ERC3525Component {
let erc721_comp = get_dep_component!(@self, ERC721);
let owner = erc721_comp.owner_of(token_id);
assert(owner != operator, Errors::APPROVAL_TO_OWNER);
assert(erc721_comp._is_approved_or_owner(caller, token_id), Errors::CALLER_NOT_ALLOWED);
assert(erc721_comp.get_approved(token_id) == caller, Errors::CALLER_NOT_ALLOWED);

// [Effect] Store approved value
self._approve_value(token_id, operator, value);
Expand Down Expand Up @@ -296,7 +297,7 @@ mod ERC3525Component {
let owner = erc721_comp.owner_of(token_id);
let current_allowance = self._erc3525_approved_values.read((owner, token_id, spender));
let infinity: u256 = BoundedInt::max();
let is_approved = erc721_comp._is_approved_or_owner(spender, token_id);
let is_approved = erc721_comp.get_approved(token_id) == spender;

// [Effect] Update allowance if the rights are limited
if current_allowance == infinity || is_approved {
Expand Down Expand Up @@ -344,7 +345,7 @@ mod ERC3525Component {
) {
// [Effect] Mint a new enumerable token if supported, standard token otherwise
let mut erc721_comp = get_dep_component_mut!(ref self, ERC721);
erc721_comp._mint(to, token_id);
erc721_comp.mint(to, token_id);

// [Effect] Store slot
self._erc3525_slots.write(token_id, slot);
Expand Down Expand Up @@ -417,7 +418,7 @@ mod ERC3525Component {

// [Effect] Burn token
let mut erc721_comp = get_dep_component_mut!(ref self, ERC721);
erc721_comp._burn(token_id);
erc721_comp.burn(token_id);

// [Effect] Update token and total value
let value = self._erc3525_values.read(token_id);
Expand Down Expand Up @@ -566,13 +567,13 @@ mod ERC3525Component {
> of AssertTrait<TContractState> {
fn _assert_minted(self: @ComponentState<TContractState>, token_id: u256) {
let erc721_comp = get_dep_component!(self, ERC721);
let exists = erc721_comp._exists(token_id);
let exists = erc721_comp.exists(token_id);
assert(exists, Errors::TOKEN_NOT_MINTED);
}

fn _assert_not_minted(self: @ComponentState<TContractState>, token_id: u256) {
let erc721_comp = get_dep_component!(self, ERC721);
let exists = erc721_comp._exists(token_id);
let exists = erc721_comp.exists(token_id);
assert(!exists, Errors::TOKEN_ALREADY_MINTED);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/presets/erc3525_mintable_burnable.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ mod ERC3525MintableBurnable {
use starknet::{get_caller_address, ContractAddress};

// SRC5
use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;

// ERC721
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};

// ERC3525
use cairo_erc_3525::module::ERC3525Component;
Expand Down
6 changes: 2 additions & 4 deletions src/presets/erc3525_mintable_burnable_metadata.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ mod ERC3525MintableBurnableMetadata {
use starknet::{get_caller_address, ContractAddress};

// SRC5
use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;

// ERC721
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::token::erc721::interface::{
IERC721, IERC721CamelOnly, IERC721Metadata, IERC721MetadataCamelOnly
use openzeppelin::token::erc721::{
ERC721Component, ERC721HooksEmptyImpl, interface::{IERC721, IERC721CamelOnly}
};

// ERC3525
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ mod ERC3525MintableBurnableMSA {
use starknet::{get_caller_address, ContractAddress};

// SRC5
use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;

// ERC721
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::token::erc721::interface::{
IERC721, IERC721CamelOnly, IERC721Metadata, IERC721MetadataCamelOnly
use openzeppelin::token::erc721::{
ERC721Component, ERC721HooksEmptyImpl, interface::{IERC721, IERC721CamelOnly}
};

// ERC3525
Expand Down Expand Up @@ -59,8 +57,8 @@ mod ERC3525MintableBurnableMSA {
// Component implementations
#[abi(embed_v0)]
impl SRC5Impl = SRC5Component::SRC5Impl<ContractState>;
#[abi(embed_v0)]
impl SRC5CamelImpl = SRC5Component::SRC5CamelImpl<ContractState>;
// #[abi(embed_v0)]
// impl SRC5CamelImpl = SRC5Component::SRC5CamelImpl<ContractState>;
#[abi(embed_v0)]
impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl<ContractState>;
#[abi(embed_v0)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ mod ERC3525MintableBurnableMSASE {
use starknet::{get_caller_address, ContractAddress};

// SRC5
use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel};
// use openzeppelin::introspection::interface::{ISRC5, ISRC5Camel};
use openzeppelin::introspection::src5::SRC5Component;

// ERC721
use openzeppelin::token::erc721::erc721::ERC721Component;
use openzeppelin::token::erc721::interface::{
IERC721, IERC721CamelOnly, IERC721Metadata, IERC721MetadataCamelOnly
};
use openzeppelin::token::erc721::{ERC721Component, ERC721HooksEmptyImpl};

// ERC3525
use cairo_erc_3525::module::ERC3525Component;
Expand Down
61 changes: 61 additions & 0 deletions src/test_helpers/account.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts for Cairo v0.14.0 (presets/account.cairo)

/// # Account Preset
///
/// OpenZeppelin's upgradeable account which can change its public key and declare, deploy, or call contracts.
#[starknet::contract(account)]
pub(crate) mod AccountUpgradeable {
use openzeppelin::account::AccountComponent;
use openzeppelin::introspection::src5::SRC5Component;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
use starknet::ClassHash;

component!(path: AccountComponent, storage: account, event: AccountEvent);
component!(path: SRC5Component, storage: src5, event: SRC5Event);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);

// Account Mixin
#[abi(embed_v0)]
pub(crate) impl AccountMixinImpl =
AccountComponent::AccountMixinImpl<ContractState>;
impl AccountInternalImpl = AccountComponent::InternalImpl<ContractState>;

// Upgradeable
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
account: AccountComponent::Storage,
#[substorage(v0)]
src5: SRC5Component::Storage,
#[substorage(v0)]
upgradeable: UpgradeableComponent::Storage
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
AccountEvent: AccountComponent::Event,
#[flat]
SRC5Event: SRC5Component::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event
}

#[constructor]
pub(crate) fn constructor(ref self: ContractState, public_key: felt252) {
self.account.initializer(public_key);
}

#[abi(embed_v0)]
impl UpgradeableImpl of IUpgradeable<ContractState> {
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.account.assert_only_self();
self.upgradeable.upgrade(new_class_hash);
}
}
}
Loading
Loading