Skip to content

Commit

Permalink
stop using divmod
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Apr 29, 2024
1 parent 6b3c009 commit b750e43
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/execution_state_test.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use governance::utils::u64_tuple_storage::{ThreeU64TupleStorePacking, TwoU64TupleStorePacking};
[use governance::utils::u64_tuple_storage_test::{assert_pack_unpack};
use governance::utils::u64_tuple_storage_test::{assert_pack_unpack};
use starknet::storage_access::{StorePacking};

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/governor.cairo
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use core::array::{Array};
use core::byte_array::{ByteArray};
use core::integer::{u128_safe_divmod};
use core::option::{Option, OptionTrait};
use core::traits::{Into, TryInto};
use governance::execution_state::{ExecutionState};
use governance::staker::{IStakerDispatcher};
use starknet::account::{Call};
use starknet::{ContractAddress, storage_access::{StorePacking}};


#[derive(Copy, Drop, Serde, starknet::Store, PartialEq, Debug)]
pub struct ProposalInfo {
// the address of the proposer
Expand Down
6 changes: 3 additions & 3 deletions src/utils/u64_tuple_storage.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use core::integer::{u128_safe_divmod};
use starknet::storage_access::{StorePacking};

const TWO_POW_64: u128 = 0x10000000000000000;
const TWO_POW_64_DIVISOR: NonZero<u128> = 0x10000000000000000;

pub(crate) impl TwoU64TupleStorePacking of StorePacking<(u64, u64), u128> {
fn pack(value: (u64, u64)) -> u128 {
let (a, b) = value;
a.into() + b.into() * TWO_POW_64
a.into() + (b.into() * TWO_POW_64)
}

fn unpack(value: u128) -> (u64, u64) {
let (q, r) = u128_safe_divmod(value, TWO_POW_64.try_into().unwrap());
let (q, r) = DivRem::div_rem(value, TWO_POW_64_DIVISOR);
(r.try_into().unwrap(), q.try_into().unwrap())
}
}

0 comments on commit b750e43

Please sign in to comment.