Skip to content

Commit

Permalink
feat: add camel case support with our own logic
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbrs committed Aug 26, 2024
1 parent 1b3b906 commit e3866e6
Showing 1 changed file with 71 additions and 6 deletions.
77 changes: 71 additions & 6 deletions src/contracts/project.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ trait IExternal<TContractState> {
fn grant_offsetter_role(ref self: TContractState, offsetter: ContractAddress);
fn revoke_offsetter_role(ref self: TContractState, account: ContractAddress);
fn balance_of(self: @TContractState, account: ContractAddress, token_id: u256) -> u256;
fn balanceOf(self: @TContractState, account: ContractAddress, token_id: u256) -> u256;
fn balance_of_batch(
self: @TContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256>;
fn balanceOfBatch(
self: @TContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256>;
fn shares_of(self: @TContractState, account: ContractAddress, token_id: u256) -> u256;
fn safe_transfer_from(
ref self: TContractState,
Expand All @@ -34,6 +38,14 @@ trait IExternal<TContractState> {
value: u256,
data: Span<felt252>
);
fn safeTransferFrom(
ref self: TContractState,
from: ContractAddress,
to: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
);
fn safe_batch_transfer_from(
ref self: TContractState,
from: ContractAddress,
Expand All @@ -42,10 +54,22 @@ trait IExternal<TContractState> {
values: Span<u256>,
data: Span<felt252>
);
fn safeBatchTransferFrom(
ref self: TContractState,
from: ContractAddress,
to: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
);
fn set_approval_for_all(ref self: TContractState, operator: ContractAddress, approved: bool);
fn setApprovalForAll(ref self: TContractState, operator: ContractAddress, approved: bool);
fn is_approved_for_all(
self: @TContractState, owner: ContractAddress, operator: ContractAddress
) -> bool;
fn set_approval_for_all(ref self: TContractState, operator: ContractAddress, approved: bool);
fn isApprovedForAll(
self: @TContractState, owner: ContractAddress, operator: ContractAddress
) -> bool;
fn cc_to_internal(self: @TContractState, cc_value_to_send: u256, token_id: u256) -> u256;

fn internal_to_cc(self: @TContractState, internal_value_to_send: u256, token_id: u256) -> u256;
Expand Down Expand Up @@ -89,7 +113,6 @@ mod Project {
// #[abi(embed_v0)]
// impl ERC1155MetadataURIImpl =
// ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;
#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
Expand Down Expand Up @@ -304,6 +327,10 @@ mod Project {
self._balance_of(account, token_id) // Internal call to avoid ambiguous call
}

fn balanceOf(self: @ContractState, account: ContractAddress, token_id: u256) -> u256 {
self._balance_of(account, token_id)
}

fn balance_of_batch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
Expand All @@ -322,6 +349,12 @@ mod Project {
batch_balances.span()
}

fn balanceOfBatch(
self: @ContractState, accounts: Span<ContractAddress>, token_ids: Span<u256>
) -> Span<u256> {
super::IExternal::balance_of_batch(self, accounts, token_ids)
}

fn shares_of(self: @ContractState, account: ContractAddress, token_id: u256) -> u256 {
let amount_cc_bought = self
.erc1155
Expand All @@ -345,6 +378,17 @@ mod Project {
self._safe_transfer_from(from, to, token_id, value, data);
}

fn safeTransferFrom(
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
token_id: u256,
value: u256,
data: Span<felt252>
) {
self._safe_transfer_from(from, to, token_id, value, data)
}

fn safe_batch_transfer_from(
ref self: ContractState,
from: ContractAddress,
Expand All @@ -366,10 +410,15 @@ mod Project {
self._safe_batch_transfer_from(from, to, token_ids, to_send.span(), data);
}

fn is_approved_for_all(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
self.erc1155.is_approved_for_all(owner, operator)
fn safeBatchTransferFrom(
ref self: ContractState,
from: ContractAddress,
to: ContractAddress,
token_ids: Span<u256>,
values: Span<u256>,
data: Span<felt252>
) {
super::IExternal::safe_batch_transfer_from(ref self, from, to, token_ids, values, data)
}

fn set_approval_for_all(
Expand All @@ -378,6 +427,22 @@ mod Project {
self.erc1155.set_approval_for_all(operator, approved);
}

fn setApprovalForAll(ref self: ContractState, operator: ContractAddress, approved: bool) {
self.erc1155.set_approval_for_all(operator, approved);
}

fn is_approved_for_all(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
self.erc1155.is_approved_for_all(owner, operator)
}

fn isApprovedForAll(
self: @ContractState, owner: ContractAddress, operator: ContractAddress
) -> bool {
self.erc1155.is_approved_for_all(owner, operator)
}

fn cc_to_internal(self: @ContractState, cc_value_to_send: u256, token_id: u256) -> u256 {
let vintage_supply = self.vintage.get_carbon_vintage(token_id).supply.into();
let initial_project_supply = self.vintage.get_initial_project_cc_supply();
Expand Down

0 comments on commit e3866e6

Please sign in to comment.