Closed credence0x closed 3 months ago
The latest updates on your projects. Learn more about Vercel for Git βοΈ
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
eternum | β Ready (Inspect) | Visit Preview | π¬ Add feedback | Jul 5, 2024 4:32pm |
β±οΈ Estimated effort to review [1-5] | 3 |
π§ͺ Relevant tests | Yes |
π Security concerns | No |
β‘ Key issues to review |
Possible Bug: The removal of the liquidity function and its replacement with total_shares in the mint_shares function may not correctly calculate the shares to mint based on the new logic. This change could affect the market dynamics and should be thoroughly tested, especially under edge cases. |
Refactoring Concern: The removal of the liquidity function simplifies the code but requires careful consideration of all places where this function was used to ensure that the new logic with total_shares maintains the intended behavior. |
Category | Suggestion | Score |
Possible bug |
Add a conditional check to prevent division by zero___ **Replace the direct assignment ofamount to FixedTrait::new_unscaled with a conditional check to ensure amount is non-zero to prevent potential division by zero errors in subsequent calculations.** [contracts/src/models/bank/market.cairo [183]](https://github.com/BibliothecaDAO/eternum/pull/1058/files#diff-0ed7dbca92a513e5ffe5f67ef1f914b92b611abe3bc3972cb39b6254cc1bedf8R183-R183) ```diff -FixedTrait::new_unscaled(amount, false) +FixedTrait::new_unscaled(amount, false) if amount != 0 else FixedTrait::new_unscaled(1, false) ``` Suggestion importance[1-10]: 8Why: This suggestion addresses a potential division by zero error, which is a critical issue that can cause runtime exceptions. The conditional check ensures robustness in the code. | 8 |
Add a check to ensure non-zero value before division___ **Ensure thatquantity_optimal is not zero before proceeding with the division to avoid division by zero errors.** [contracts/src/models/bank/market.cairo [148]](https://github.com/BibliothecaDAO/eternum/pull/1058/files#diff-0ed7dbca92a513e5ffe5f67ef1f914b92b611abe3bc3972cb39b6254cc1bedf8R148-R148) ```diff -if quantity_optimal <= quantity +if quantity_optimal <= quantity and quantity_optimal != 0 ``` Suggestion importance[1-10]: 8Why: This suggestion prevents division by zero errors, which are critical issues that can cause runtime exceptions. Adding this check ensures the code handles edge cases more gracefully. | 8 | |
Best practice |
Use safe math operations to prevent overflow and underflow___ **Replace the direct multiplication and division for share calculation with a function thathandles potential overflow or underflow scenarios.** [contracts/src/models/bank/market.cairo [196]](https://github.com/BibliothecaDAO/eternum/pull/1058/files#diff-0ed7dbca92a513e5ffe5f67ef1f914b92b611abe3bc3972cb39b6254cc1bedf8R196-R196) ```diff -(amount * *self.total_shares) / reserve_amount +safe_div(safe_mul(amount, *self.total_shares), reserve_amount) ``` Suggestion importance[1-10]: 7Why: Using safe math operations is a good practice to prevent overflow and underflow, which can lead to incorrect calculations and potential vulnerabilities. This improves the reliability of the code. | 7 |
Enhancement |
Restore liquidity computation with a new method___ **Replace the removed liquidity calculation with a new method that correctly computesliquidity based on the current state of the market.** [contracts/src/models/bank/market.cairo [336]](https://github.com/BibliothecaDAO/eternum/pull/1058/files#diff-0ed7dbca92a513e5ffe5f67ef1f914b92b611abe3bc3972cb39b6254cc1bedf8R336-R336) ```diff -let initial_liquidity = market.total_shares; +let initial_liquidity = market.compute_liquidity(); ``` Suggestion importance[1-10]: 6Why: Reintroducing a method to compute liquidity can enhance the accuracy of liquidity calculations. However, the necessity of this change depends on the context and usage of liquidity in the code. | 6 |
User description
PR Type
Bug fix, Tests
Description
liquidity
function and updating themint_shares
function.total_shares
instead ofliquidity
.block_number
andclass_hash
values in the manifest files.Changes walkthrough π
manifest.json
Update block number and class hashes in manifest
contracts/manifests/dev/manifest.json
block_number
from 19 to 20.class_hash
andoriginal_class_hash
for aDojoContract
.manifest.toml
Update block number and class hashes in manifest
contracts/manifests/dev/manifest.toml
block_number
from 19 to 20.class_hash
andoriginal_class_hash
for aDojoContract
.market.cairo
Fix liquidity provision and update related tests
contracts/src/models/bank/market.cairo
liquidity
function.mint_shares
function to remove liquidity calculation.total_shares
instead ofliquidity
.