-
Notifications
You must be signed in to change notification settings - Fork 2
Create: Allo strategy contract to accept donations to allo pool and allocate them to Hyperfund and Hyperstaker #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request introduces a new Allo protocol submodule along with its corresponding commit, updates the Solidity compiler configuration via a new configuration file and enhanced remappings in the foundry settings, and adds two new smart contracts: one for HyperStrategy and another for its factory. Additionally, it updates an interface’s Solidity version and introduces a new interface for hyperfund interactions. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant F as HyperStrategyFactory
participant HS as HyperStrategy
U->>F: createHyperstrategy(_allo, _name)
F->>HS: Deploy new HyperStrategy
F->>HS: Set hypercertMinter approval
F->>U: Return new HyperStrategy address
sequenceDiagram
participant M as Manager
participant HS as HyperStrategy
M->>HS: initialize(_poolId, _data)
HS->>HS: Decode data & assign MANAGER_ROLE
HS->>M: Emit Initialized event
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
.gitmodules (1)
10-12
: Fix indentation inconsistency with tabsThe new submodule entry uses spaces for indentation while the existing entries use tabs. Consider maintaining consistency by using tabs for all entries.
[submodule "lib/allo-v2.1"] - path = lib/allo-v2.1 - url = https://github.com/allo-protocol/allo-v2.1.git + path = lib/allo-v2.1 + url = https://github.com/allo-protocol/allo-v2.1.gitsrc/HyperstrategyFactory.sol (1)
7-16
: Consider markinghypercertMinter
as immutable
SincehypercertMinter
is only assigned once in the constructor, marking it as immutable can reduce gas usage and prevent reassignments.src/HyperStrategy.sol (2)
45-61
: Add a reentrancy safeguard if this function can hold large funds
While_allocate(...)
is restricted to theMANAGER_ROLE
, consider adding a reentrancy guard (nonReentrant
) if this function will be handling substantial token transfers or if it calls external contracts. This helps protect against complex reentrancy patterns.
104-109
: Double-check split logic for minted fractions
By subtractingunits
from the existing fraction balance and assigning the remainder tonewallocations[0]
, this function effectively splits one fraction into two parts. Ensure that any subsequent usage or tracking of both fractions is fully accounted for in the hypercert token’s internal logic.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
.gitmodules
(1 hunks)compiler_config.json
(1 hunks)foundry.toml
(1 hunks)lib/allo-v2.1
(1 hunks)src/HyperStrategy.sol
(1 hunks)src/HyperstrategyFactory.sol
(1 hunks)src/interfaces/IHypercertToken.sol
(1 hunks)src/interfaces/IHyperfund.sol
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Foundry project
🔇 Additional comments (8)
lib/allo-v2.1 (1)
1-1
: Submodule Commit Pointer AddedThe new submodule commit pointer (
Subproject commit 258f3c6aa2823577e3e1f95b1dbed8b6d9482a1d
) has been added as expected. Please ensure that the corresponding entries in.gitmodules
and any remappings infoundry.toml
correctly reference this submodule version.src/interfaces/IHypercertToken.sol (1)
2-2
:❓ Verification inconclusive
Verify Solidity version downgrade is necessary
The Solidity version was downgraded from a higher version (likely 0.8.28) to 0.8.18. This is probably for compatibility with the Allo protocol, but it's worth confirming this is intentional and documenting the reason.
🏁 Script executed:
#!/bin/bash # Check what Solidity version the Allo protocol uses grep -r "pragma solidity" lib/allo-v2.1/ | sort | uniqLength of output: 56
Action Required: Manually Confirm Solidity Version Downgrade Rationale
The change in the Solidity version (downgraded to ^0.8.18 in
src/interfaces/IHypercertToken.sol
) appears to be intended for compatibility—possibly with the Allo protocol. However, our automated check against files inlib/allo-v2.1
did not return any Solidity version details, so we couldn’t automatically verify the intended compatibility.Next Steps:
- Manual Verification: Please confirm that the downgrade to ^0.8.18 is indeed required for Allo protocol compatibility (or another dependency) and document the rationale accordingly if it is intentional.
- Documentation: Add a comment or commit note explaining why the version change was made, ensuring future maintainers can understand its necessity.
foundry.toml (1)
10-16
: LGTM!The new remappings are correctly configured to integrate with the Allo protocol libraries. This will allow importing from the Allo protocol's contracts directly.
src/interfaces/IHyperfund.sol (1)
6-6
: Clarify the use of negative multipliersThe
tokenMultipliers
function returns anint256
value, which allows for negative multipliers. Consider documenting how negative multipliers should be interpreted and handled by consumers of this interface.Could you explain the intended use case for negative multipliers? This is unusual for multiplier values and could lead to unexpected behavior if not handled carefully.
compiler_config.json (1)
1-36
: Optimizer and output selection look good
These settings are standard for production-grade deployments, withruns=200
typically balancing deployment size and runtime efficiency.src/HyperstrategyFactory.sol (1)
19-28
: Confirm if unrestricted creation of HyperStrategy instances is intentional
Anyone can currently callcreateHyperstrategy(...).
If limiting who can create new strategies is desired, add an access control modifier (e.g.,onlyOwner
oronlyRole
).src/HyperStrategy.sol (2)
63-78
: Verify rounding for negative multipliers
Here, a positive multiplier scales the units up by multiplication, while a negative multiplier scales down by division. Integer division may cause subtle rounding issues if_amount
is not an exact multiple of-multiplier
. Confirm that losing fractional units is acceptable or implement a rounding strategy (ceil/floor) as needed.
92-93
: Implement_isValidAllocator
or confirm it is intentionally empty
This function is defined but currently lacks logic. If you need to validate allocators, implement the checks. Otherwise, remove or comment its no-op state explicitly.
interface IHyperfund { | ||
function hypercertId() external view returns (uint256); | ||
function tokenMultipliers(address token) external view returns (int256); | ||
function hypercertMinter() external view returns (address); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add documentation to explain interface functions
The interface lacks documentation explaining the purpose and expected behavior of each function. Consider adding NatSpec comments to improve code readability and maintainability.
interface IHyperfund {
+ /**
+ * @notice Returns the ID of the hypercert associated with this fund
+ * @return The hypercert ID
+ */
function hypercertId() external view returns (uint256);
+
+ /**
+ * @notice Returns the multiplier for a given token
+ * @param token The address of the token
+ * @return The multiplier value for the token (can be negative)
+ */
function tokenMultipliers(address token) external view returns (int256);
+
+ /**
+ * @notice Returns the address of the hypercert minter contract
+ * @return The address of the hypercert minter
+ */
function hypercertMinter() external view returns (address);
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
interface IHyperfund { | |
function hypercertId() external view returns (uint256); | |
function tokenMultipliers(address token) external view returns (int256); | |
function hypercertMinter() external view returns (address); | |
} | |
interface IHyperfund { | |
/** | |
* @notice Returns the ID of the hypercert associated with this fund | |
* @return The hypercert ID | |
*/ | |
function hypercertId() external view returns (uint256); | |
/** | |
* @notice Returns the multiplier for a given token | |
* @param token The address of the token | |
* @return The multiplier value for the token (can be negative) | |
*/ | |
function tokenMultipliers(address token) external view returns (int256); | |
/** | |
* @notice Returns the address of the hypercert minter contract | |
* @return The address of the hypercert minter | |
*/ | |
function hypercertMinter() external view returns (address); | |
} |
function initialize(uint256 _poolId, bytes memory _data) external virtual override { | ||
(address _manager, address _hyperfund) = abi.decode(_data, (address, address)); | ||
|
||
hyperfund = IHyperfund(_hyperfund); | ||
hypercertMinter = IHypercertToken(hyperfund.hypercertMinter()); | ||
|
||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
_grantRole(MANAGER_ROLE, _manager); | ||
__BaseStrategy_init(_poolId); | ||
emit Initialized(_poolId, _data); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Prevent multiple calls to initialize(...)
You’re using a standalone initialize
function, but there’s no safeguard against being called more than once. To avoid re-initialization issues and maintain security, consider using initializer
modifiers (e.g., from OpenZeppelin) or adding a guard to ensure it’s invoked only once.
Summary by CodeRabbit