Skip to content

Commit

Permalink
Update dependencies and fix code formatting (#16)
Browse files Browse the repository at this point in the history
* Update dependencies and fix code formatting

* Update Scarb version to 2.5.4 for github action

---------

Co-authored-by: Trunks @ Carbonable <[email protected]>
  • Loading branch information
Arn0d and tekkac authored Mar 8, 2024
1 parent 42ca116 commit 670f7e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.3.1"
scarb-version: "2.5.4"
- name: Cairo lint
run: scarb fmt --check
- name: Cairo build
Expand Down
8 changes: 4 additions & 4 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest

[dependencies]
starknet = ">=2.3.1"
alexandria_storage = { git = "https://github.com/tekkac/alexandria", branch = "feat/interpolation-fast" }
alexandria_numeric = { git = "https://github.com/tekkac/alexandria", branch = "feat/interpolation-fast" }
openzeppelin = { git = "https://github.com/cloudvenger/cairo-contracts.git", rev = "fd41fdb9d04a701b2353c4cd0a8bd19f3139e88a" }
starknet = ">=2.5.3"
alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria", tag = "cairo-v2.5.4" }
alexandria_numeric = { git = "https://github.com/keep-starknet-strange/alexandria", tag = "cairo-v2.5.4" }
openzeppelin = { git = "https://github.com/cloudvenger/cairo-contracts.git", tag = "oz-cairo-2.5.3" }

[[target.starknet-contract]]
sierra = true
Expand Down
19 changes: 9 additions & 10 deletions src/components/absorber/carbon.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ mod AbsorberComponent {
use starknet::{get_block_timestamp, get_caller_address, ContractAddress};

// External imports
use alexandria_numeric::interpolate::{
interpolate_fast as interpolate, Interpolation, Extrapolation
};
use alexandria_numeric::interpolate::{interpolate, Interpolation, Extrapolation};
use alexandria_storage::list::{List, ListTrait};

// Internal imports
Expand Down Expand Up @@ -75,10 +73,10 @@ mod AbsorberComponent {
times[times.len() - 1]
}
fn get_times(self: @ComponentState<TContractState>) -> Span<u64> {
self.Absorber_times.read().array().span()
self.Absorber_times.read().array().expect('Can\'t get times').span()
}
fn get_absorptions(self: @ComponentState<TContractState>) -> Span<u64> {
self.Absorber_absorptions.read().array().span()
self.Absorber_absorptions.read().array().expect('Can\'t get absorptions').span()
}
fn get_absorption(self: @ComponentState<TContractState>, time: u64) -> u64 {
let times = self.Absorber_times.read();
Expand Down Expand Up @@ -142,8 +140,8 @@ mod AbsorberComponent {

// [Effect] Store new times and absorptions
let mut index = 0;
stored_times.append(*times[index]);
stored_absorptions.append(*absorptions[index]);
let _ = stored_times.append(*times[index]);
let _ = stored_absorptions.append(*absorptions[index]);
loop {
index += 1;
if index == times.len() {
Expand All @@ -154,8 +152,8 @@ mod AbsorberComponent {
// [Check] Absorptions are sorted
assert(*absorptions[index] >= *absorptions[index - 1], 'Absorptions not sorted');
// [Effect] Store values
stored_times.append(*times[index]);
stored_absorptions.append(*absorptions[index]);
let _ = stored_times.append(*times[index]);
let _ = stored_absorptions.append(*absorptions[index]);
};

// [Event] Emit event
Expand Down Expand Up @@ -195,7 +193,8 @@ mod AbsorberComponent {
) -> Span<u256> {
let times = self.Absorber_times.read();
let absorptions = self.Absorber_absorptions.read();
let absorptions_u256 = self.__span_u64_into_u256(absorptions.array().span());
let absorptions_u256 = self
.__span_u64_into_u256(absorptions.array().expect('Can\'t get absorptions').span());

// [Check] list time and absorptions are equal size
assert(times.len() == absorptions.len(), Errors::INVALID_ARRAY_LENGTH);
Expand Down
57 changes: 28 additions & 29 deletions src/contracts/project.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ trait IExternal<ContractState> {
ref self: ContractState, to: ContractAddress, token_ids: Span<u256>, values: Span<u256>
);
fn batch_burn(ref self: ContractState, token_ids: Span<u256>, values: Span<u256>);
fn set_uri(ref self: ContractState, token_id: u256, uri: felt252);
fn set_list_uri(ref self: ContractState, token_ids: Span<u256>, uris: Span<felt252>);
fn set_uri(ref self: ContractState, uri: ByteArray);
fn decimals(self: @ContractState) -> u8;
}

Expand Down Expand Up @@ -42,9 +41,10 @@ mod Project {
#[abi(embed_v0)]
impl ERC1155Impl = ERC1155Component::ERC1155Impl<ContractState>;
#[abi(embed_v0)]
impl ERC1155MetadataImpl = ERC1155Component::ERC1155MetadataImpl<ContractState>;
impl ERC1155MetadataURIImpl =
ERC1155Component::ERC1155MetadataURIImpl<ContractState>;
#[abi(embed_v0)]
impl ERC1155CamelOnly = ERC1155Component::ERC1155CamelOnlyImpl<ContractState>;
impl ERC1155Camel = ERC1155Component::ERC1155CamelImpl<ContractState>;
#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
#[abi(embed_v0)]
Expand Down Expand Up @@ -102,56 +102,55 @@ mod Project {

// Constructor
#[constructor]
fn constructor(
ref self: ContractState, name: felt252, symbol: felt252, owner: ContractAddress
) {
self.erc1155.initializer(name, symbol);
fn constructor(ref self: ContractState, base_uri: ByteArray, owner: ContractAddress) {
self.erc1155.initializer(base_uri);
self.ownable.initializer(owner);

self.src5.register_interface(OLD_IERC1155_ID);
self.src5.register_interface(IERC165_BACKWARD_COMPATIBLE_ID);
}

// Externals
#[external(v0)]
#[abi(embed_v0)]
impl ExternalImpl of super::IExternal<ContractState> {
fn mint(ref self: ContractState, to: ContractAddress, token_id: u256, value: u256) {
self.erc1155._mint(to, token_id, value);
self.erc1155.mint_with_acceptance_check(to, token_id, value, array![].span());
}

fn burn(ref self: ContractState, token_id: u256, value: u256) {
self.erc1155._burn(get_caller_address(), token_id, value);
self.erc1155.burn(get_caller_address(), token_id, value);
}

fn batch_mint(
ref self: ContractState, to: ContractAddress, token_ids: Span<u256>, values: Span<u256>
) {
self.erc1155._batch_mint(to, token_ids, values);
self.erc1155.batch_mint_with_acceptance_check(to, token_ids, values, array![].span());
}

fn batch_burn(ref self: ContractState, token_ids: Span<u256>, values: Span<u256>) {
self.erc1155._batch_burn(get_caller_address(), token_ids, values);
self.erc1155.batch_burn(get_caller_address(), token_ids, values);
}

fn set_uri(ref self: ContractState, token_id: u256, uri: felt252) {
self.erc1155._set_uri(token_id, uri);
fn set_uri(ref self: ContractState, uri: ByteArray) {
self.erc1155.set_base_uri(uri);
}

fn set_list_uri(
ref self: ContractState, mut token_ids: Span<u256>, mut uris: Span<felt252>
) {
assert(token_ids.len() == uris.len(), Errors::UNEQUAL_ARRAYS_URI);

loop {
if token_ids.len() == 0 {
break;
}
let id = *token_ids.pop_front().unwrap();
let uri = *uris.pop_front().unwrap();

self.erc1155._set_uri(id, uri);
}
}
// fn set_list_uri(
// ref self: ContractState, mut token_ids: Span<u256>, mut uris: Span<felt252>
// ) {
// assert(token_ids.len() == uris.len(), Errors::UNEQUAL_ARRAYS_URI);
//
// loop {
// if token_ids.len() == 0 {
// break;
// }
// let id = *token_ids.pop_front().unwrap();
// let uri = *uris.pop_front().unwrap();
//
// self.erc1155._set_uri(id, uri);
// }
// }

fn decimals(self: @ContractState) -> u8 {
self.absorber.get_cc_decimals()
Expand Down

0 comments on commit 670f7e9

Please sign in to comment.