From d123a9a0fa19b19b5574a0687e0ab8b3fb7f7108 Mon Sep 17 00:00:00 2001 From: Olek Date: Thu, 23 Nov 2023 17:16:14 +0100 Subject: [PATCH 1/5] Added invariant error codes --- docs/docs/aleph_zero/collections.md | 4 +-- docs/docs/aleph_zero/entrypoints.md | 8 +++--- docs/docs/aleph_zero/invariant_errors.md | 25 +++++++++++++++++++ ...ure.md => single_contract_optimization.md} | 4 +-- docs/sidebars.js | 2 +- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 docs/docs/aleph_zero/invariant_errors.md rename docs/docs/aleph_zero/{main_structure.md => single_contract_optimization.md} (89%) diff --git a/docs/docs/aleph_zero/collections.md b/docs/docs/aleph_zero/collections.md index 68e88ac8..55289ac8 100644 --- a/docs/docs/aleph_zero/collections.md +++ b/docs/docs/aleph_zero/collections.md @@ -151,7 +151,7 @@ pub fn add_tick(&mut self, key: PoolKey, index: i32, tick: Tick) {} ``` - **Description**: Adds a new tick associated with a specific PoolKey and index. -- **Parameters**: key (PoolKey), index (i32) +- **Parameters**: key (PoolKey), index (i32), tick (Tick) - **Edge Cases**: None ```rust @@ -164,7 +164,7 @@ pub fn update_tick( ``` - **Description**: Updates an existing tick associated with a specific PoolKey and index. -- **Parameters**: key (PoolKey), index (i32) +- **Parameters**: key (PoolKey), index (i32), tick: (&Tick) - **Edge Cases**: Returns an error if the specified tick does not exist. ## Pools diff --git a/docs/docs/aleph_zero/entrypoints.md b/docs/docs/aleph_zero/entrypoints.md index 2c5adf35..ae89776d 100644 --- a/docs/docs/aleph_zero/entrypoints.md +++ b/docs/docs/aleph_zero/entrypoints.md @@ -75,7 +75,7 @@ pub fn get_fee_tier(&self, key: FeeTierKey) -> Option<()> #### Output parameters |Type|Description| |-|-| -|Option<()>|An option that may contain none or an empty unit if the fee tier exists.| +|Option<()>|An option that may contain `None` or an empty unit if the fee tier exists.| This function is used to verify the existence of a specified fee tier. ### Remove fee tier @@ -192,7 +192,7 @@ pub fn transfer_position( |Name|Type|Description| |-|-|-| |index|u32|Index of the position in the user's position list.| -|receiver|i32|Address of the user who will receive the position.| +|receiver|AccountId|Address of the user who will receive the position.| This function changes ownership of an existing position based on the position index in the user's position list. You can only change ownership of positions that you own; otherwise, it will return an error. ### Remove position @@ -245,8 +245,8 @@ pub fn get_position(&mut self, index: u32) -> Option #### Output parameters |Type|Description| |-|-| -|Option|An option that may contain none or a position struct with data if it exists.| -This function returns an option that contains none if the position index is out of range or a position if it actually exists. +|Option|An option that may contain `None` or a position struct with data if it exists.| +This function returns an option that contains `None` if the position index is out of range or a position if it actually exists. ### Get all positions ```rust diff --git a/docs/docs/aleph_zero/invariant_errors.md b/docs/docs/aleph_zero/invariant_errors.md new file mode 100644 index 00000000..990c3724 --- /dev/null +++ b/docs/docs/aleph_zero/invariant_errors.md @@ -0,0 +1,25 @@ +--- +title: Invariant Errors + +slug: /aleph_zero/invariant_errors +--- + +| ErrorCode | Description | +|--------------------------------|---------------------------------------------------------------------------| +| NotAnAdmin | Default user attempts to invoke an admin-only message | +| PoolAlreadyExist | Attempted creation of a pool that already exists | +| PoolNotFound | Unable to retrieve the state of the specified pool | +| InvalidTickIndexOrTickSpacing | Attempt to create a tick with an out-of-bounds index or incorrect spacing | +| PositionNotFound | Unable to retrieve the state of the specified position | +| TickNotFound | Unable to retrieve the state of the specified tick | +| FeeTierNotFound | Unable to retrieve the state of the specified fee tier | +| AmountIsZero | Attempted swap with zero tokens | +| WrongLimit | Attempted swap with an incorrect price limit | +| PriceLimitReached | Swap would exceed the specified limit | +| NoGainSwap | User would receive zero tokens after the swap | +| InvalidTickSpacing | Attempted creation of a fee tier with incorrect tick spacing | +| FeeTierAlreadyAdded | Fee tier is already added | +| NotAFeeReceiver | Default user attempts to withdraw protocol fee | +| ZeroLiquidity | Attempted opening of a position with zero liquidity | +| TransferError | Transfer could not be performed | +| TokensAreTheSame | Attempted creation of a pool with exactly the same tokens | diff --git a/docs/docs/aleph_zero/main_structure.md b/docs/docs/aleph_zero/single_contract_optimization.md similarity index 89% rename from docs/docs/aleph_zero/main_structure.md rename to docs/docs/aleph_zero/single_contract_optimization.md index c965c9e1..cfcf9f3d 100644 --- a/docs/docs/aleph_zero/main_structure.md +++ b/docs/docs/aleph_zero/single_contract_optimization.md @@ -1,7 +1,7 @@ --- -title: Main structure +title: Single Contract Optimization -slug: /aleph_zero/main_structure +slug: /aleph_zero/single_contract_optimization --- In order to maintain minimal fees, we consolidate all data within a single contract. This streamlined approach significantly reduces the expenses associated with creating pools and positions. This efficiency not only minimizes costs but also simplifies the overall process, making it more accessible and user-friendly. By conducting all state changes and positioning all entrypoints exclusively within this one contract, we eliminate the complexities of interacting with and monitoring numerous external contracts. The vast majority of our data is intelligently stored using mapping, which not only preserves precious storage resources but also enhances the overall efficiency of our system. \ No newline at end of file diff --git a/docs/sidebars.js b/docs/sidebars.js index d27eae09..284ffc9d 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -63,7 +63,7 @@ module.exports = { type: 'category', label: 'Aleph Zero', collapsed: true, - items: ['aleph_zero/project_structure', 'aleph_zero/main_structure','aleph_zero/installation','aleph_zero/entrypoints', 'aleph_zero/collections','aleph_zero/storage','aleph_zero/types'] + items: ['aleph_zero/project_structure', 'aleph_zero/single_contract_optimization','aleph_zero/installation','aleph_zero/entrypoints', 'aleph_zero/collections','aleph_zero/storage','aleph_zero/types', 'aleph_zero/invariant_errors'] }, 'faq', 'resources', From ea7618fbaad054ab3bd9901728e3c42be22ec4fc Mon Sep 17 00:00:00 2001 From: Olek Date: Fri, 24 Nov 2023 12:38:58 +0100 Subject: [PATCH 2/5] Added introductions to every section --- docs/docs/aleph_zero/collections.md | 2 ++ docs/docs/aleph_zero/entrypoints.md | 4 ++++ docs/docs/aleph_zero/installation.md | 2 ++ docs/docs/aleph_zero/invariant_errors.md | 2 ++ docs/docs/aleph_zero/project_structure.md | 6 ++++++ docs/docs/aleph_zero/single_contract_optimization.md | 7 ------- docs/docs/aleph_zero/storage.md | 2 ++ docs/docs/aleph_zero/types.md | 1 + docs/sidebars.js | 2 +- 9 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 docs/docs/aleph_zero/single_contract_optimization.md diff --git a/docs/docs/aleph_zero/collections.md b/docs/docs/aleph_zero/collections.md index 55289ac8..9f4457c0 100644 --- a/docs/docs/aleph_zero/collections.md +++ b/docs/docs/aleph_zero/collections.md @@ -4,6 +4,8 @@ title: Collections slug: /aleph_zero/collections --- +This segment explores key storage structures that manage various entities within the Aleph Zero protocol. Understanding these structures is crucial for developers and integrators engaging with the protocol's data. + ## Positions ```rust diff --git a/docs/docs/aleph_zero/entrypoints.md b/docs/docs/aleph_zero/entrypoints.md index ae89776d..d12ac08a 100644 --- a/docs/docs/aleph_zero/entrypoints.md +++ b/docs/docs/aleph_zero/entrypoints.md @@ -4,6 +4,10 @@ title: Entrypoints slug: /aleph_zero/entrypoints --- +This section outlines the core entrypoints for the Aleph Zero smart contract, providing developers with essential methods to interact with the protocol. These entrypoints cover various aspects of the contract, including protocol fee management, fee tier administration, pool creation and management, position handling, and swap functionality. + + + ### Constructor ```rust #[ink(constructor)] diff --git a/docs/docs/aleph_zero/installation.md b/docs/docs/aleph_zero/installation.md index 01891e08..178d9e29 100644 --- a/docs/docs/aleph_zero/installation.md +++ b/docs/docs/aleph_zero/installation.md @@ -4,6 +4,8 @@ title: Installation slug: /aleph_zero/installation --- +This section provides detailed instructions on how to install the Aleph Zero smart contract, including prerequisites and steps for setting up the development environment. + ## Prerequisites * Rust & Cargo ([rustup](https://www.rust-lang.org/tools/install)) diff --git a/docs/docs/aleph_zero/invariant_errors.md b/docs/docs/aleph_zero/invariant_errors.md index 990c3724..27df2478 100644 --- a/docs/docs/aleph_zero/invariant_errors.md +++ b/docs/docs/aleph_zero/invariant_errors.md @@ -4,6 +4,8 @@ title: Invariant Errors slug: /aleph_zero/invariant_errors --- +This section outlines error codes essential for maintaining the integrity of Aleph Zero operations. These codes provide insights into specific issues encountered during interactions with the platform. + | ErrorCode | Description | |--------------------------------|---------------------------------------------------------------------------| | NotAnAdmin | Default user attempts to invoke an admin-only message | diff --git a/docs/docs/aleph_zero/project_structure.md b/docs/docs/aleph_zero/project_structure.md index c86e2fda..7132b519 100644 --- a/docs/docs/aleph_zero/project_structure.md +++ b/docs/docs/aleph_zero/project_structure.md @@ -4,6 +4,12 @@ title: Project Structure slug: /aleph_zero/project_structure --- +This section provides an overview of the structural organization of the Aleph Zero smart contract project. The project is meticulously structured to enhance readability, maintainability, and efficiency. The architecture is designed to consolidate data within a single contract, minimizing fees and simplifying interactions. + +## Contract Architecture + +In order to maintain minimal fees, we consolidate all data within a single contract. This streamlined approach significantly reduces the expenses associated with creating pools and positions. This efficiency not only minimizes costs but also simplifies the overall process, making it more accessible and user-friendly. By conducting all state changes and positioning all entrypoints exclusively within this one contract, we eliminate the complexities of interacting with and monitoring numerous external contracts. The vast majority of our data is intelligently stored using mapping, which not only preserves precious storage resources but also enhances the overall efficiency of our system. + ## Simplified ``` diff --git a/docs/docs/aleph_zero/single_contract_optimization.md b/docs/docs/aleph_zero/single_contract_optimization.md deleted file mode 100644 index cfcf9f3d..00000000 --- a/docs/docs/aleph_zero/single_contract_optimization.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -title: Single Contract Optimization - -slug: /aleph_zero/single_contract_optimization ---- - -In order to maintain minimal fees, we consolidate all data within a single contract. This streamlined approach significantly reduces the expenses associated with creating pools and positions. This efficiency not only minimizes costs but also simplifies the overall process, making it more accessible and user-friendly. By conducting all state changes and positioning all entrypoints exclusively within this one contract, we eliminate the complexities of interacting with and monitoring numerous external contracts. The vast majority of our data is intelligently stored using mapping, which not only preserves precious storage resources but also enhances the overall efficiency of our system. \ No newline at end of file diff --git a/docs/docs/aleph_zero/storage.md b/docs/docs/aleph_zero/storage.md index c6faa61c..60c546e9 100644 --- a/docs/docs/aleph_zero/storage.md +++ b/docs/docs/aleph_zero/storage.md @@ -4,6 +4,8 @@ title: Storage slug: /aleph_zero/storage --- +This section provides an in-depth exploration of key data structures integral to the Aleph Zero protocol's storage mechanism. Understanding these structures is fundamental for developers and integrators working with the protocol. + ## FeeTier ```rust diff --git a/docs/docs/aleph_zero/types.md b/docs/docs/aleph_zero/types.md index a0c8469f..951fcea5 100644 --- a/docs/docs/aleph_zero/types.md +++ b/docs/docs/aleph_zero/types.md @@ -4,6 +4,7 @@ title: Types slug: /aleph_zero/types --- +This segment introduces key data types integral to understanding and working with the Aleph Zero protocol. These types play a pivotal role in expressing and managing various aspects of the protocol's functionality. |Name|Description| |-|-| diff --git a/docs/sidebars.js b/docs/sidebars.js index 284ffc9d..c8358516 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -63,7 +63,7 @@ module.exports = { type: 'category', label: 'Aleph Zero', collapsed: true, - items: ['aleph_zero/project_structure', 'aleph_zero/single_contract_optimization','aleph_zero/installation','aleph_zero/entrypoints', 'aleph_zero/collections','aleph_zero/storage','aleph_zero/types', 'aleph_zero/invariant_errors'] + items: ['aleph_zero/project_structure','aleph_zero/installation','aleph_zero/entrypoints', 'aleph_zero/collections','aleph_zero/storage','aleph_zero/types', 'aleph_zero/invariant_errors'] }, 'faq', 'resources', From 20daaef3f39702f98534a0e5ea2642e76050f2b7 Mon Sep 17 00:00:00 2001 From: Olek Date: Fri, 24 Nov 2023 13:45:13 +0100 Subject: [PATCH 3/5] extended types section --- docs/docs/aleph_zero/types.md | 37 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/docs/docs/aleph_zero/types.md b/docs/docs/aleph_zero/types.md index 951fcea5..f18c8591 100644 --- a/docs/docs/aleph_zero/types.md +++ b/docs/docs/aleph_zero/types.md @@ -6,21 +6,34 @@ slug: /aleph_zero/types This segment introduces key data types integral to understanding and working with the Aleph Zero protocol. These types play a pivotal role in expressing and managing various aspects of the protocol's functionality. -|Name|Description| -|-|-| -|SqrtPrice|Square root of price value| -|FeeGrowth|Accumulated amount of fees| -|FixedPoint|Number with fixed number of decimal places| -|Liquidity|Amount of virtual liquidity| -|Percentage|Represents values as fractions of 100| -|SecondsPerLiquidity|Measures the time inside/outside liquidity| -|TokenAmount|Quantity of specific token| +### Defining Decimal: +```rust +#[decimal(#scale, #big_type)] +pub struct DecimalName { + pub v: #underlying_type +} +``` +- **#scale**: An `integer` that determines the number of decimal places. +- **#big_type**: The type to which it will be extended in intermediate operations (default is U256). +- **DecimalName**: The name of the struct. +- **#underlying_type**: The underlying numeric type. + +|Name|Decimals|Primitive type|Big type|Description| +|-|-|-|-|-| +|SqrtPrice|24|u128|U256|Square root of price value| +|FeeGrowth|28|u128|U256|Accumulated amount of fees| +|FixedPoint|12|u128|U256|Number with fixed number of decimal places| +|Liquidity|6|u128|U256|Amount of virtual liquidity| +|Percentage|12|u64|U256|Represents values as fractions of 100| +|SecondsPerLiquidity|24|u128|U256|Measures the time inside/outside liquidity| +|TokenAmount|0|u128|U256|Quantity of specific token| ## Definitions ### SqrtPrice ```rust +#[decimal(24)] pub struct SqrtPrice { pub v: u128, } @@ -28,35 +41,41 @@ pub struct SqrtPrice { ### FeeGrowth ```rust +#[decimal(28)] pub struct FeeGrowth { pub v: u128, } ``` ### FixedPoint ```rust +#[decimal(12)] pub struct FixedPoint { pub v: u128, } ``` ### Liquidity ```rust +#[decimal(6)] pub struct Liquidity { pub v: u128, } ``` ### Percentage ```rust +#[decimal(12)] pub struct Percentage { pub v: u64, } ``` ### SecondsPerLiquidity ```rust +#[decimal(24)] pub struct SecondsPerLiquidity { pub v: u128, } ``` ### TokenAmount ```rust +#[decimal(0)] pub struct TokenAmount(pub u128); ``` \ No newline at end of file From 6d12450f9d899d92559da6f74fbb34c68fa3c400 Mon Sep 17 00:00:00 2001 From: Olek Date: Fri, 24 Nov 2023 14:35:08 +0100 Subject: [PATCH 4/5] Added external links --- docs/docs/aleph_zero/project_structure.md | 9 ++++++--- docs/docs/aleph_zero/types.md | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/docs/aleph_zero/project_structure.md b/docs/docs/aleph_zero/project_structure.md index 7132b519..94911a4b 100644 --- a/docs/docs/aleph_zero/project_structure.md +++ b/docs/docs/aleph_zero/project_structure.md @@ -25,7 +25,7 @@ In order to maintain minimal fees, we consolidate all data within a single contr ``` ### Contracts -Within this directory, we house our contract structures, collections, and associated logic. These components are pivotal in facilitating the seamless operation of our contract. +Within this directory, we house our contract structures, collections, and associated logic. These components are pivotal in facilitating the seamless operation of our contract. Source code can be found #### Storage The "Storage" directory is home to the essential data structures utilized for contract storage. These structures are instrumental in securely and efficiently storing critical information within our contract. @@ -37,8 +37,7 @@ Our "Collections" directory is dedicated to collections of data that leverage st Contained within the "Decimal" directory is a specialized decimal library. This library serves as the foundation for creating custom data types and executing precise mathematical calculations, ensuring accuracy and reliability in our contract. ### Math -The "Math" directory serves as a repository for core mathematical functions, constants, and custom data types that are meticulously crafted using the Decimal library. These mathematical components are indispensable for performing complex calculations in our contract. - +The "Math" directory serves as a repository for core mathematical functions, constants, and custom data types that are meticulously crafted using the Decimal library. These mathematical components are indispensable for performing complex calculations in our contract. For an in-depth understanding of the mathematical specifications implemented in our project, please refer to our comprehensive [Math Specification Document](https://invariant.app/math-spec-a0.pdf). This document provides detailed insights into the design choices, algorithms, and methodologies underpinning our mathematical components. ### Test Helpers Our "Test Helpers" directory is equipped with macros designed to streamline end-to-end testing processes. These macros are instrumental in simplifying and enhancing the efficiency of our testing procedures, ensuring the robustness of our contract. @@ -48,6 +47,10 @@ The "Token" directory is dedicated to the implementation of a fundamental PSP22 ### Traceable Result In the "Traceable Result" directory, you will find a comprehensive library comprising data structures used in debugging processes. In the event of an error, this library generates a detailed stack trace, providing valuable insights that aid in the identification and resolution of issues, thereby promoting the reliability and stability of our contract. + +### Source Code Access +For a detailed exploration of our contract structures, collections, and associated logic, please refer to the corresponding [Source Code Repository](https://github.com/invariant-labs/protocol-a0). This repository contains the complete and up-to-date implementation of our contract architecture. + ## Extended ``` diff --git a/docs/docs/aleph_zero/types.md b/docs/docs/aleph_zero/types.md index f18c8591..ab079e8d 100644 --- a/docs/docs/aleph_zero/types.md +++ b/docs/docs/aleph_zero/types.md @@ -7,6 +7,7 @@ slug: /aleph_zero/types This segment introduces key data types integral to understanding and working with the Aleph Zero protocol. These types play a pivotal role in expressing and managing various aspects of the protocol's functionality. ### Defining Decimal: +We have implemented a custom decimal system, which is detailed in our repository [here](https://github.com/invariant-labs/decimal). The structure of the decimal is outlined below in Rust syntax: ```rust #[decimal(#scale, #big_type)] pub struct DecimalName { From d765c80ce04bf440c39b057cc65cc0402088d3f6 Mon Sep 17 00:00:00 2001 From: Olek Date: Sun, 26 Nov 2023 10:11:47 +0100 Subject: [PATCH 5/5] Updated error descriptions & added decimal example --- docs/docs/aleph_zero/installation.md | 2 +- docs/docs/aleph_zero/invariant_errors.md | 12 ++++++------ docs/docs/aleph_zero/project_structure.md | 6 +++--- docs/docs/aleph_zero/types.md | 20 +++++++++++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/docs/aleph_zero/installation.md b/docs/docs/aleph_zero/installation.md index 178d9e29..6892cd50 100644 --- a/docs/docs/aleph_zero/installation.md +++ b/docs/docs/aleph_zero/installation.md @@ -4,7 +4,7 @@ title: Installation slug: /aleph_zero/installation --- -This section provides detailed instructions on how to install the Aleph Zero smart contract, including prerequisites and steps for setting up the development environment. +This section provides detailed instructions on how to install the Invariant protocol smart contract on Aleph Zero, including prerequisites and steps for setting up the development environment. ## Prerequisites diff --git a/docs/docs/aleph_zero/invariant_errors.md b/docs/docs/aleph_zero/invariant_errors.md index 27df2478..030e0888 100644 --- a/docs/docs/aleph_zero/invariant_errors.md +++ b/docs/docs/aleph_zero/invariant_errors.md @@ -8,20 +8,20 @@ This section outlines error codes essential for maintaining the integrity of Ale | ErrorCode | Description | |--------------------------------|---------------------------------------------------------------------------| -| NotAnAdmin | Default user attempts to invoke an admin-only message | -| PoolAlreadyExist | Attempted creation of a pool that already exists | +| NotAdmin | Unauthorized user attempts to invoke an admin-only message | +| PoolAlreadyExist | Attempted creation of a pool with same tokens (order does not matter) and same fee tier that already exists | | PoolNotFound | Unable to retrieve the state of the specified pool | | InvalidTickIndexOrTickSpacing | Attempt to create a tick with an out-of-bounds index or incorrect spacing | | PositionNotFound | Unable to retrieve the state of the specified position | | TickNotFound | Unable to retrieve the state of the specified tick | | FeeTierNotFound | Unable to retrieve the state of the specified fee tier | -| AmountIsZero | Attempted swap with zero tokens | +| AmountIsZero | Attempted swap with zero tokens on input or output depending of swap direction| | WrongLimit | Attempted swap with an incorrect price limit | | PriceLimitReached | Swap would exceed the specified limit | | NoGainSwap | User would receive zero tokens after the swap | | InvalidTickSpacing | Attempted creation of a fee tier with incorrect tick spacing | | FeeTierAlreadyAdded | Fee tier is already added | -| NotAFeeReceiver | Default user attempts to withdraw protocol fee | +| NotFeeReceiver | Unauthorized user attempts to withdraw protocol fee | | ZeroLiquidity | Attempted opening of a position with zero liquidity | -| TransferError | Transfer could not be performed | -| TokensAreTheSame | Attempted creation of a pool with exactly the same tokens | +| TransferError | PSP22 token transfer could not be performed | +| TokensAreSame | Attempted creation of a pool with exactly the same tokens | diff --git a/docs/docs/aleph_zero/project_structure.md b/docs/docs/aleph_zero/project_structure.md index 94911a4b..66da9477 100644 --- a/docs/docs/aleph_zero/project_structure.md +++ b/docs/docs/aleph_zero/project_structure.md @@ -4,11 +4,11 @@ title: Project Structure slug: /aleph_zero/project_structure --- -This section provides an overview of the structural organization of the Aleph Zero smart contract project. The project is meticulously structured to enhance readability, maintainability, and efficiency. The architecture is designed to consolidate data within a single contract, minimizing fees and simplifying interactions. +This section provides an overview of the structural organization of the Invariant protocol smart contract project on Aleph Zero. The project is meticulously structured to enhance readability, maintainability, and efficiency. The architecture is designed to consolidate data within a single contract, minimizing fees and simplifying interactions. ## Contract Architecture -In order to maintain minimal fees, we consolidate all data within a single contract. This streamlined approach significantly reduces the expenses associated with creating pools and positions. This efficiency not only minimizes costs but also simplifies the overall process, making it more accessible and user-friendly. By conducting all state changes and positioning all entrypoints exclusively within this one contract, we eliminate the complexities of interacting with and monitoring numerous external contracts. The vast majority of our data is intelligently stored using mapping, which not only preserves precious storage resources but also enhances the overall efficiency of our system. +To optimize cost-effectiveness, we centralize data in a singular contract, reducing expenses tied to pool and position creation. This streamlined approach not only cuts costs but also simplifies processes, enhancing accessibility. By concentrating state changes and entrypoints within this central contract, we eliminate the intricacies of managing external contracts, while smart mapping intelligently conserves storage resources and bolsters system efficiency. ## Simplified @@ -25,7 +25,7 @@ In order to maintain minimal fees, we consolidate all data within a single contr ``` ### Contracts -Within this directory, we house our contract structures, collections, and associated logic. These components are pivotal in facilitating the seamless operation of our contract. Source code can be found +Within this directory, we house our contract structures, collections, and associated logic. These components are pivotal in facilitating the seamless operation of our contract. #### Storage The "Storage" directory is home to the essential data structures utilized for contract storage. These structures are instrumental in securely and efficiently storing critical information within our contract. diff --git a/docs/docs/aleph_zero/types.md b/docs/docs/aleph_zero/types.md index ab079e8d..518a82b4 100644 --- a/docs/docs/aleph_zero/types.md +++ b/docs/docs/aleph_zero/types.md @@ -6,7 +6,7 @@ slug: /aleph_zero/types This segment introduces key data types integral to understanding and working with the Aleph Zero protocol. These types play a pivotal role in expressing and managing various aspects of the protocol's functionality. -### Defining Decimal: +## Defining Decimal: We have implemented a custom decimal system, which is detailed in our repository [here](https://github.com/invariant-labs/decimal). The structure of the decimal is outlined below in Rust syntax: ```rust #[decimal(#scale, #big_type)] @@ -19,6 +19,24 @@ pub struct DecimalName { - **DecimalName**: The name of the struct. - **#underlying_type**: The underlying numeric type. +### Examples + +Creating a custom decimal type with 3 decimal places: + +```rust +#[decimal(3)] +pub struct Decimal { + pub v: u128 +} +``` + +Creating a decimal value: + +```rust +let my_decimal = Decimal::new(12042); +``` +In this example, the result of creation should be interpreted as 12.042, calculated as `12042 * 10^-3`, considering the specified scale of 3. + |Name|Decimals|Primitive type|Big type|Description| |-|-|-|-|-| |SqrtPrice|24|u128|U256|Square root of price value|