---
source: crates/sdk-derive/derive-core/src/storage.rs
assertion_line: 432
expression: formatted
---
impl<SDK> Proxy<SDK> {
    pub const SLOTS: usize = Self::calculate_slots();
    pub fn new(sdk: SDK) -> Self {
        let slot = fluentbase_sdk::U256::from(0);
        let offset = 0u8;
        let mut current_slot = slot;
        let mut current_offset: u8 = offset;
        let owner_layout = {
            let bytes = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES as u8;
            let slots = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            let layout = if slots == 0 {
                if current_offset + bytes <= 32 {
                    let actual_offset = 32 - current_offset - bytes;
                    let result = (current_slot, actual_offset);
                    current_offset += bytes;
                    result
                } else {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    let actual_offset = 32 - bytes;
                    current_offset = bytes;
                    (current_slot, actual_offset)
                }
            } else {
                if current_offset > 0 {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    current_offset = 0;
                }
                let result = (current_slot, 0);
                current_slot = current_slot + fluentbase_sdk::U256::from(slots);
                current_offset = 0;
                result
            };
            layout
        };
        let implementation_layout = (
            fluentbase_sdk::U256::from(
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbcu128,
            ),
            0u8,
        );
        let counter_layout = {
            let bytes = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES as u8;
            let slots = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            let layout = if slots == 0 {
                if current_offset + bytes <= 32 {
                    let actual_offset = 32 - current_offset - bytes;
                    let result = (current_slot, actual_offset);
                    current_offset += bytes;
                    result
                } else {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    let actual_offset = 32 - bytes;
                    current_offset = bytes;
                    (current_slot, actual_offset)
                }
            } else {
                if current_offset > 0 {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    current_offset = 0;
                }
                let result = (current_slot, 0);
                current_slot = current_slot + fluentbase_sdk::U256::from(slots);
                current_offset = 0;
                result
            };
            layout
        };
        Self {
            sdk,
            owner: <<StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                owner_layout.0,
                owner_layout.1,
            ),
            implementation: <<StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                implementation_layout.0,
                implementation_layout.1,
            ),
            counter: <<StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                counter_layout.0,
                counter_layout.1,
            ),
        }
    }
    pub fn new_at(sdk: SDK, slot: fluentbase_sdk::U256, offset: u8) -> Self {
        let mut current_slot = slot;
        let mut current_offset: u8 = offset;
        let owner_layout = {
            let bytes = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES as u8;
            let slots = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            let layout = if slots == 0 {
                if current_offset + bytes <= 32 {
                    let actual_offset = 32 - current_offset - bytes;
                    let result = (current_slot, actual_offset);
                    current_offset += bytes;
                    result
                } else {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    let actual_offset = 32 - bytes;
                    current_offset = bytes;
                    (current_slot, actual_offset)
                }
            } else {
                if current_offset > 0 {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    current_offset = 0;
                }
                let result = (current_slot, 0);
                current_slot = current_slot + fluentbase_sdk::U256::from(slots);
                current_offset = 0;
                result
            };
            layout
        };
        let implementation_layout = (
            fluentbase_sdk::U256::from(
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbcu128,
            ),
            0u8,
        );
        let counter_layout = {
            let bytes = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES as u8;
            let slots = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            let layout = if slots == 0 {
                if current_offset + bytes <= 32 {
                    let actual_offset = 32 - current_offset - bytes;
                    let result = (current_slot, actual_offset);
                    current_offset += bytes;
                    result
                } else {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    let actual_offset = 32 - bytes;
                    current_offset = bytes;
                    (current_slot, actual_offset)
                }
            } else {
                if current_offset > 0 {
                    current_slot = current_slot + fluentbase_sdk::U256::from(1);
                    current_offset = 0;
                }
                let result = (current_slot, 0);
                current_slot = current_slot + fluentbase_sdk::U256::from(slots);
                current_offset = 0;
                result
            };
            layout
        };
        Self {
            sdk,
            owner: <<StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                owner_layout.0,
                owner_layout.1,
            ),
            implementation: <<StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                implementation_layout.0,
                implementation_layout.1,
            ),
            counter: <<StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::Descriptor as fluentbase_sdk::storage::StorageDescriptor>::new(
                counter_layout.0,
                counter_layout.1,
            ),
        }
    }
    const fn calculate_slots() -> usize {
        let mut current_slot: usize = 0;
        let mut current_offset: usize = 0;
        {
            let bytes = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES;
            let slots = <StoragePrimitive<
                Address,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            if slots == 0 {
                if current_offset + bytes <= 32 {
                    current_offset += bytes;
                } else {
                    current_slot += 1;
                    current_offset = bytes;
                }
            } else {
                if current_offset > 0 {
                    current_slot += 1;
                    current_offset = 0;
                }
                current_slot += slots;
                current_offset = 0;
            }
        }
        {
            let bytes = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::BYTES;
            let slots = <StoragePrimitive<
                U256,
            > as fluentbase_sdk::storage::StorageLayout>::SLOTS;
            if slots == 0 {
                if current_offset + bytes <= 32 {
                    current_offset += bytes;
                } else {
                    current_slot += 1;
                    current_offset = bytes;
                }
            } else {
                if current_offset > 0 {
                    current_slot += 1;
                    current_offset = 0;
                }
                current_slot += slots;
                current_offset = 0;
            }
        }
        if current_offset > 0 { current_slot + 1 } else { current_slot }
    }
    ///Returns an accessor for the owner field
    #[inline]
    pub fn owner_accessor(
        &self,
    ) -> <StoragePrimitive<
        Address,
    > as fluentbase_sdk::storage::StorageLayout>::Accessor {
        <StoragePrimitive<
            Address,
        > as fluentbase_sdk::storage::StorageLayout>::access(self.owner)
    }
    ///Returns an accessor for the implementation field
    #[inline]
    pub fn implementation_accessor(
        &self,
    ) -> <StoragePrimitive<
        Address,
    > as fluentbase_sdk::storage::StorageLayout>::Accessor {
        <StoragePrimitive<
            Address,
        > as fluentbase_sdk::storage::StorageLayout>::access(self.implementation)
    }
    ///Returns an accessor for the counter field
    #[inline]
    pub fn counter_accessor(
        &self,
    ) -> <StoragePrimitive<U256> as fluentbase_sdk::storage::StorageLayout>::Accessor {
        <StoragePrimitive<
            U256,
        > as fluentbase_sdk::storage::StorageLayout>::access(self.counter)
    }
}
