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

Fix: Event and Token_id #136

Merged
merged 8 commits into from
Sep 2, 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
2 changes: 0 additions & 2 deletions debug_usdcarb.log

This file was deleted.

Empty file removed deploy.js
Empty file.
100 changes: 0 additions & 100 deletions genesis.json

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/deploy_minter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PROJECT=$3
OWNER=$DEPLOYER_ADDRESS
PUBLIC_SALE_OPEN=1
MAX_VALUE=20000000000
UNIT_PRICE=11
UNIT_PRICE=11000000

output=$(starkli deploy $class_hash "$PROJECT" "$ERC20" "$PUBLIC_SALE_OPEN" u256:"$MAX_VALUE" u256:"$UNIT_PRICE" "$OWNER" --account "$STARKNET_ACCOUNT" --rpc "$STARKNET_RPC" --keystore "$STARKNET_KEYSTORE" --keystore-password "$KEYSTORE_PASSWORD" 2>&1)

Expand Down
6 changes: 3 additions & 3 deletions scripts/deploy_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ USAGE="Usage: ./deploy_project.sh <CLASS_HASH>"

# You can change these variables
OWNER=$DEPLOYER_ADDRESS
FROM_TIMESTAMP=2024
DURATION_IN_YEARS=20
FROM_TIMESTAMP=2020
DURATION_IN_YEARS=19

if [ -z "$1" ]; then
echo "Error: No CLASS_HASH provided.$USAGE"
exit 1
fi
deploy() {
class_hash=$1
output=$(starkli deploy $class_hash "$OWNER" "$OWNER" $FROM_TIMESTAMP $DURATION_IN_YEARS --account "$STARKNET_ACCOUNT" --rpc "$STARKNET_RPC" --keystore "$STARKNET_KEYSTORE" --keystore-password "$KEYSTORE_PASSWORD" 2>&1)
output=$(starkli deploy $class_hash "$OWNER" $FROM_TIMESTAMP $DURATION_IN_YEARS --account "$STARKNET_ACCOUNT" --rpc "$STARKNET_RPC" --keystore "$STARKNET_KEYSTORE" --keystore-password "$KEYSTORE_PASSWORD" 2>&1)
if [[ $output == *"Error"* ]]; then
echo "Error at deployment: $output"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion src/components/minter/mint.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ mod MintComponent {
break;
}
values_cc.append(cc_amount.into());
tokens_ids.append(index.into());
let token_id = (index + 1).into();
tokens_ids.append(token_id);
index += 1;
};
// [Interaction] Pay
Expand Down
10 changes: 2 additions & 8 deletions src/components/offsetter/offset_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,8 @@ mod OffsetComponent {
let mut index: u32 = 0;
loop {
// [Check] Vintage is defined
let token_id = match vintages.get(index) {
Option::Some(value) => *value.unbox(),
Option::None => 0,
};
let carbon_amount = match cc_values.get(index) {
Option::Some(value) => *value.unbox(),
Option::None => 0,
};
let token_id = *vintages.at(index);
let carbon_amount = *cc_values.at(index);

if token_id != 0 && carbon_amount != 0 {
self.retire_carbon_credits(token_id, carbon_amount);
Expand Down
2 changes: 1 addition & 1 deletion src/components/vintage/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use carbon_v3::models::carbon_vintage::CarbonVintage;
#[starknet::interface]
trait IVintage<TContractState> {
/// Returns the project total carbon credits.
fn get_project_carbon(self: @TContractState) -> u128;
fn get_project_carbon(self: @TContractState) -> u256;

/// Returns the number of vintages of the project.
fn get_num_vintages(self: @TContractState) -> usize;
Expand Down
54 changes: 23 additions & 31 deletions src/components/vintage/vintage.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod VintageComponent {
struct Storage {
Vintage_vintages: LegacyMap<u256, CarbonVintage>,
Vintage_vintages_len: usize,
Vintage_project_carbon: u128,
Vintage_project_carbon: u256,
}

#[event]
Expand Down Expand Up @@ -49,8 +49,8 @@ mod VintageComponent {

#[derive(Drop, PartialEq, starknet::Event)]
struct ProjectCarbonUpdated {
old_carbon: u128,
new_carbon: u128,
old_carbon: u256,
new_carbon: u256,
}


Expand Down Expand Up @@ -82,21 +82,8 @@ mod VintageComponent {
+Drop<TContractState>,
+IAccessControl<TContractState>
> of IVintage<ComponentState<TContractState>> {
fn get_project_carbon(self: @ComponentState<TContractState>) -> u128 {
let mut project_carbon: u128 = 0;

// let mut index = self.Vintage_vintages_len.read();
// while index > 0 {
// index -= 1;
// let vintage = self.Vintage_vintages.read(index.into());
// if vintage.status != CarbonVintageType::Unset {
// project_carbon += vintage.supply.into();
// }
// };

project_carbon = self.Vintage_project_carbon.read();

project_carbon
fn get_project_carbon(self: @ComponentState<TContractState>) -> u256 {
self.Vintage_project_carbon.read()
}

fn get_num_vintages(self: @ComponentState<TContractState>) -> usize {
Expand All @@ -109,13 +96,14 @@ mod VintageComponent {

fn get_cc_vintages(self: @ComponentState<TContractState>) -> Span<CarbonVintage> {
let mut vintages = ArrayTrait::<CarbonVintage>::new();
let n = self.Vintage_vintages_len.read();
let num_vintages = self.Vintage_vintages_len.read();
let mut index = 0;
loop {
if index >= n {
if index >= num_vintages {
break ();
}
let vintage = self.Vintage_vintages.read(index.into());
let token_id = (index + 1).into();
let vintage = self.Vintage_vintages.read(token_id);
vintages.append(vintage);
index += 1;
};
Expand All @@ -136,13 +124,14 @@ mod VintageComponent {

fn get_initial_project_cc_supply(self: @ComponentState<TContractState>) -> u256 {
let mut project_supply: u256 = 0;
let n = self.Vintage_vintages_len.read();
let num_vintage = self.Vintage_vintages_len.read();
let mut index = 0;
loop {
if index >= n {
if index >= num_vintage {
break ();
}
let initial_vintage_supply = self.get_initial_cc_supply(index.into());
let token_id = (index + 1).into();
let initial_vintage_supply = self.get_initial_cc_supply(token_id);
project_supply += initial_vintage_supply;
index += 1;
};
Expand Down Expand Up @@ -221,16 +210,17 @@ mod VintageComponent {
break ();
}
let supply = *yearly_absorptions.at(index);

let old_vintage = self.Vintage_vintages.read(index.into());
let vintage = CarbonVintage {
let token_id = (index + 1).into();
let old_vintage = self.Vintage_vintages.read(token_id);
let mut vintage = CarbonVintage {
year: (start_year + index).into(),
supply: supply,
failed: 0,
created: 0,
status: CarbonVintageType::Projected,
};
self.Vintage_vintages.write(index.into(), vintage);
self.Vintage_vintages.write(token_id, vintage);

self
.emit(
VintageUpdate {
Expand All @@ -254,12 +244,14 @@ mod VintageComponent {
) {
// [Storage] Store new vintages
self.Vintage_vintages_len.write(number_of_years.into());
let mut index = starting_year;
let n = index + number_of_years;
let mut index = 0;
let n = number_of_years;
loop {
if index == n {
break ();
}
let token_id = (index + 1).into();

let vintage: CarbonVintage = CarbonVintage {
year: index.into(),
supply: 0,
Expand All @@ -268,7 +260,7 @@ mod VintageComponent {
status: CarbonVintageType::Projected,
};

self.Vintage_vintages.write(index.into(), vintage);
self.Vintage_vintages.write(token_id, vintage);
index += 1;
};
}
Expand Down
Loading
Loading