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: bump edition+add vintage #161

Merged
merged 4 commits into from
Dec 6, 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
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository = "https://github.com/carbonable-labs/carbon-protocol-v3"
keywords = ["starknet", "carbon credits", "carbonable", "protocol"]
readme = "README.md"
documentation = "https://github.com/carbonable-labs/carbon-protocol-v3"
edition = "2024_07"

[dependencies]
starknet = ">=2.8.5"
Expand Down
29 changes: 15 additions & 14 deletions src/components/erc1155/erc1155.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// See https://eips.ethereum.org/EIPS/eip-1155.
#[starknet::component]
pub mod ERC1155Component {
use core::num::traits::Zero;
use crate::components::erc1155::interface::{
IERC1155ReceiverDispatcher, IERC1155ReceiverDispatcherTrait
};
Expand Down Expand Up @@ -222,8 +223,8 @@ pub mod ERC1155Component {
values: Span<u256>,
data: Span<felt252>
) {
assert(Zeroable::is_non_zero(from), Errors::INVALID_SENDER);
assert(Zeroable::is_non_zero(to), Errors::INVALID_RECEIVER);
assert(from.is_non_zero(), Errors::INVALID_SENDER);
assert(to.is_non_zero(), Errors::INVALID_RECEIVER);

let operator = get_caller_address();
if from != operator {
Expand Down Expand Up @@ -496,11 +497,11 @@ pub mod ERC1155Component {
value: u256,
data: Span<felt252>
) {
assert(Zeroable::is_non_zero(to), Errors::INVALID_RECEIVER);
assert(to.is_non_zero(), Errors::INVALID_RECEIVER);

let token_ids = array![token_id].span();
let values = array![value].span();
self.update_with_acceptance_check(Zeroable::zero(), to, token_ids, values, data);
self.update_with_acceptance_check(Zero::zero(), to, token_ids, values, data);
}

/// Batched version of `mint_with_acceptance_check`.
Expand All @@ -521,8 +522,8 @@ pub mod ERC1155Component {
values: Span<u256>,
data: Span<felt252>
) {
assert(Zeroable::is_non_zero(to), Errors::INVALID_RECEIVER);
self.update_with_acceptance_check(Zeroable::zero(), to, token_ids, values, data);
assert(to.is_non_zero(), Errors::INVALID_RECEIVER);
self.update_with_acceptance_check(Zero::zero(), to, token_ids, values, data);
}

/// Destroys a `value` amount of tokens of type `token_id` from `from`.
Expand All @@ -539,11 +540,11 @@ pub mod ERC1155Component {
token_id: u256,
value: u256
) {
assert(Zeroable::is_non_zero(from), Errors::INVALID_SENDER);
assert(from.is_non_zero(), Errors::INVALID_SENDER);

let token_ids = array![token_id].span();
let values = array![value].span();
self.update(from, Zeroable::zero(), token_ids, values);
self.update(from, Zero::zero(), token_ids, values);
}

/// Batched version of `burn`.
Expand All @@ -561,8 +562,8 @@ pub mod ERC1155Component {
token_ids: Span<u256>,
values: Span<u256>
) {
assert(Zeroable::is_non_zero(from), Errors::INVALID_SENDER);
self.update(from, Zeroable::zero(), token_ids, values);
assert(from.is_non_zero(), Errors::INVALID_SENDER);
self.update(from, Zero::zero(), token_ids, values);
}

/// Version of `update` that performs the token acceptance check by calling
Expand Down Expand Up @@ -626,12 +627,12 @@ pub mod ERC1155Component {
}
let token_id = *token_ids.at(index);
let value = *values.at(index);
if Zeroable::is_non_zero(from) {
if from.is_non_zero() {
let from_balance = self.ERC1155_balances.read((token_id, from));
assert(from_balance >= value, Errors::INSUFFICIENT_BALANCE);
self.ERC1155_balances.write((token_id, from), from_balance - value);
}
if Zeroable::is_non_zero(to) {
if to.is_non_zero() {
let to_balance = self.ERC1155_balances.read((token_id, to));
self.ERC1155_balances.write((token_id, to), to_balance + value);
}
Expand Down Expand Up @@ -673,7 +674,7 @@ pub mod ERC1155Component {

let token_ids = array![token_id].span();
let values = array![value].span();
self.update(Zeroable::zero(), to, token_ids, values);
self.update(Zero::zero(), to, token_ids, values);
}

/// Batched version of `mint_with_acceptance_check`.
Expand All @@ -694,7 +695,7 @@ pub mod ERC1155Component {
values: Span<u256>
) {
assert(to.is_non_zero(), Errors::INVALID_RECEIVER);
self.update(Zeroable::zero(), to, token_ids, values);
self.update(Zero::zero(), to, token_ids, values);
}

/// Sets a new URI for all token types, by relying on the token type ID
Expand Down
14 changes: 6 additions & 8 deletions src/components/metadata.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::{ClassHash, ContractAddress};

#[starknet::interface]
trait IMetadataHandler<TContractState> {
pub trait IMetadataHandler<TContractState> {
fn uri(self: @TContractState, token_id: u256) -> Span<felt252>;
fn get_provider(self: @TContractState) -> ContractAddress;
fn set_provider(ref self: TContractState, provider: ContractAddress);
Expand All @@ -10,17 +10,18 @@ trait IMetadataHandler<TContractState> {
}

#[starknet::interface]
trait IMetadataDescriptor<TContractState> {
pub trait IMetadataDescriptor<TContractState> {
fn construct_uri(self: @TContractState, token_id: u256) -> Span<felt252>;
}

#[starknet::component]
mod MetadataComponent {
pub mod MetadataComponent {
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
use starknet::{ClassHash, ContractAddress};
use super::{IMetadataDescriptorLibraryDispatcher, IMetadataDescriptorDispatcherTrait};

#[storage]
struct Storage {
pub struct Storage {
MetadataHandler_uri_implementation: ClassHash,
MetadataHandler_provider: ContractAddress,
}
Expand Down Expand Up @@ -60,7 +61,7 @@ mod MetadataComponent {
}

fn set_uri(ref self: ComponentState<TContractState>, class_hash: ClassHash,) {
assert(!class_hash.is_zero(), 'URI class hash cannot be zero');
assert(class_hash.into() != 0, 'URI class hash cannot be zero');
let old_class_hash = self.MetadataHandler_uri_implementation.read();
self.MetadataHandler_uri_implementation.write(class_hash);
self.emit(MetadataUpgraded { old_class_hash, class_hash });
Expand All @@ -70,10 +71,7 @@ mod MetadataComponent {

#[cfg(test)]
mod TestMetadataComponent {
use starknet::ClassHash;
use super::MetadataComponent;
use super::{IMetadataHandlerDispatcherTrait, IMetadataHandlerDispatcher};
use carbon_v3::mock::metadata::TestMetadata;
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/components/minter/booking.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Core imports

#[derive(Drop, Copy)]
enum BookingStatus {
pub enum BookingStatus {
Unknown: (),
Booked: (),
Failed: (),
Expand All @@ -10,13 +10,13 @@ enum BookingStatus {
}

#[derive(Drop, Copy, Serde, starknet::Store)]
struct Booking {
pub struct Booking {
value: u256,
amount: u256,
status: u8,
}

trait BookingTrait {
pub trait BookingTrait {
fn new(value: u256, amount: u256, status: BookingStatus) -> Booking;
fn get_status(ref self: Booking) -> BookingStatus;
fn set_status(ref self: Booking, status: BookingStatus);
Expand Down
2 changes: 1 addition & 1 deletion src/components/minter/interface.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use starknet::ContractAddress;

#[starknet::interface]
trait IMint<TContractState> {
pub trait IMint<TContractState> {
fn get_carbonable_project_address(self: @TContractState) -> ContractAddress;
fn get_payment_token_address(self: @TContractState) -> ContractAddress;
fn get_unit_price(self: @TContractState) -> u256;
Expand Down
Loading
Loading