Skip to content

Commit

Permalink
fix: deprecate LegacyMap
Browse files Browse the repository at this point in the history
  • Loading branch information
detectivekim committed Jun 27, 2024
1 parent 54e131e commit e9d84f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
8 changes: 0 additions & 8 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,3 @@ version = 1
[[package]]
name = "clober_cairo"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_std"
version = "0.25.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.25.0#5b366e24821e530fea97f11b211d220e8493fbea"
8 changes: 2 additions & 6 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
name = "clober_cairo"
version = "0.1.0"
edition = "2023_11"
cairo-version = "2.6.3"
cairo-version = "2.7.0-rc.0"
authors = ["Clober <[email protected]>"]
description = "Core Contracts written in Cairo for StarkNet"
readme = "README.md"
repository = "https://github.com/clober-dex/clober_cairo"
# license-file = "LICENSE"

[dependencies]
starknet = "2.6.3"

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.25.0" }

starknet = "2.7.0-rc.0"
[tool.snforge]
fuzzer_runs = 1000
# exit_first = true # Exit on first error.
Expand Down
15 changes: 10 additions & 5 deletions src/libraries/currency_delta.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ mod CurrencyDelta {
use starknet::ContractAddress;
use clober_cairo::alexandria::i257::i257;
use clober_cairo::alexandria::i257::I257Impl;
use starknet::storage::Map;
use core::starknet::storage::StoragePointerReadAccess;
use core::starknet::storage::StoragePathEntry;

#[storage]
struct Storage {
currency_delta: LegacyMap::<(ContractAddress, ContractAddress), (bool, u256)>
currency_delta: Map<(ContractAddress, ContractAddress), (u256, bool)>
}

#[generate_trait]
Expand All @@ -18,7 +21,7 @@ mod CurrencyDelta {
locker: ContractAddress,
currency: ContractAddress,
) -> i257 {
let (sign, abs) = self.currency_delta.read((locker, currency));
let (abs, sign) = self.currency_delta.read((locker, currency));
I257Impl::new(abs, sign)
}

Expand All @@ -27,10 +30,12 @@ mod CurrencyDelta {
locker: ContractAddress,
currency: ContractAddress,
mut delta: i257,
) {
let (sign, abs): (bool, u256) = self.currency_delta.read((locker, currency));
) -> i257 {
let entry = self.currency_delta.entry((locker, currency));
let (abs, sign) = entry.read();
delta += I257Impl::new(abs, sign);
self.currency_delta.write((locker, currency), (delta.is_negative(), delta.abs()))
entry.write((delta.abs(), delta.is_negative()));
delta
}
}
}
7 changes: 4 additions & 3 deletions src/libraries/lockers.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#[starknet::component]
mod Lockers {
use starknet::ContractAddress;
use starknet::storage::Map;

#[storage]
struct Storage {
lockers: LegacyMap::<u128, ContractAddress>, // use Array<ContractAddress>,
lock_callers: LegacyMap::<u128, ContractAddress>,
lockers: Map<u128, ContractAddress>, // use Array<ContractAddress>,
lock_callers: Map<u128, ContractAddress>,
// optimistic storage
length: u128,
non_zero_delta_count: u128
Expand Down Expand Up @@ -33,7 +34,7 @@ mod Lockers {
// let locker = self.lockers.read(length);
// let lock_caller = self.lock_callers.read(length);
self.length.write(length - 1);
// check if it's better to reset locker and lock_caller
// check if it's better to reset locker and lock_caller
}

fn lock_data(ref self: ComponentState<TContractState>) -> (u128, u128) {
Expand Down
1 change: 0 additions & 1 deletion src/libraries/significant_bit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ const DEBRUIJN_INDEX: [

#[generate_trait]
pub impl SignificantBitImpl of SignificantBitTrait {

fn least_significant_bit(x: u256) -> u8 {
assert!(x != 0, "x must be non-zero");
let (mul, _) = u256_overflow_mul(x & (~x + 1), DEBRUIJN_SEQ);
Expand Down

0 comments on commit e9d84f6

Please sign in to comment.