Skip to content

Commit

Permalink
Update NatSpec for Builders (#27)
Browse files Browse the repository at this point in the history
* Update NatSpec for Builders

* fix dublication
  • Loading branch information
YouStillAlive committed Apr 16, 2024
1 parent 48d1870 commit 04ad52d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
23 changes: 21 additions & 2 deletions contracts/Builder/BuilderInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ pragma solidity ^0.8.0;
import "./BuilderModifiers.sol";
import "@poolzfinance/poolz-helper-v2/contracts/interfaces/ISimpleProvider.sol";

/// @title BuilderInternal
/// @notice This contract contains internal functions for Builders
abstract contract BuilderInternal is BuilderModifiers {
///@dev if params is empty, then return [amount]
/// @dev Concatenates an amount with additional parameters
/// @param amount The initial amount
/// @param params Additional parameters to concatenate
/// @return result Concatenated array containing the amount followed by the additional parameters
function _concatParams(uint amount, uint256[] calldata params) internal pure returns (uint256[] memory result) {
uint256 length = params.length;
result = new uint256[](length + 1);
Expand All @@ -18,6 +23,12 @@ abstract contract BuilderInternal is BuilderModifiers {
}
}

/// @dev Creates a new NFT for a user pool
/// @param provider The SimpleProvider (DealProvider, LockProvider or TimedProvider) instance
/// @param tokenPoolId The pool ID of the token
/// @param userData The user pool data
/// @param params The parameters for the SimpleProvider
/// @return amount The amount of tokens in the user pool
function _createNewNFT(
ISimpleProvider provider,
uint256 tokenPoolId,
Expand All @@ -31,6 +42,14 @@ abstract contract BuilderInternal is BuilderModifiers {
lockDealNFT.cloneVaultId(poolId, tokenPoolId);
}

/// @dev Creates the first NFT for a SimpleProvider
/// @param provider The SimpleProvider instance
/// @param token The ERC20 token address
/// @param owner The owner of the NFT
/// @param totalAmount The total amount of tokens
/// @param params The parameters for the SimpleProvider
/// @param signature The cryptographic signature for the transfer
/// @return poolId The pool ID of the created NFT
function _createFirstNFT(
ISimpleProvider provider,
address token,
Expand All @@ -42,4 +61,4 @@ abstract contract BuilderInternal is BuilderModifiers {
poolId = lockDealNFT.safeMintAndTransfer(owner, token, msg.sender, totalAmount, provider, signature);
provider.registerPool(poolId, params);
}
}
}
11 changes: 10 additions & 1 deletion contracts/Builder/BuilderModifiers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,39 @@ pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "./BuilderState.sol";

/// @title BuilderModifiers
/// @notice This contract contains modifiers and error handling for Builders
abstract contract BuilderModifiers is BuilderState {
/// @dev Error thrown when an amount is zero
error NoZeroAmount();
/// @dev Error thrown when the length of parameters is invalid
error InvalidParamsLength(uint256 paramsLength, uint256 minLength);

/// @dev Modifier to ensure an address is not zero
modifier notZeroAddress(address _address) {
_notZeroAddress(_address);
_;
}

/// @dev Modifier to ensure user data is valid
modifier validUserData(UserPool memory userData) {
_notZeroAddress(userData.user);
_notZeroAmount(userData.amount);
_;
}

/// @dev Internal function to check that an amount is not zero
function _notZeroAmount(uint256 amount) internal pure {
if (amount == 0) revert NoZeroAmount();
}

/// @dev Internal function to check that an address is not zero
function _notZeroAddress(address _address) internal pure {
if (_address == address(0)) revert NoZeroAddress();
}

/// @dev Internal function to check the validity of parameter length
function _validParamsLength(uint256 paramsLength, uint256 minLength) internal pure {
if (paramsLength < minLength) revert InvalidParamsLength(paramsLength, minLength);
}
}
}
21 changes: 16 additions & 5 deletions contracts/Builder/BuilderState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,36 @@ pragma solidity ^0.8.0;

import "@poolzfinance/poolz-helper-v2/contracts/interfaces/ILockDealNFT.sol";

/// @title BuilderState
/// @notice This contract contains state variables and events for Builders
contract BuilderState {
/// @dev Instance of the LockDealNFT contract
ILockDealNFT public immutable lockDealNFT;

/// @dev Event emitted when mass pools are created
event MassPoolsCreated(address indexed token, IProvider indexed provider, uint256 firstPoolId, uint256 userLength);

/// @dev Error thrown when an address is zero
error NoZeroAddress();
/// @dev Error thrown when an invalid provider type is detected
error InvalidProviderType();

/// @dev Constructor initializes the contract with the provided instance of LockDealNFT
/// @param _lockDealNFT Instance of the LockDealNFT contract
constructor(ILockDealNFT _lockDealNFT) {
if (address(_lockDealNFT) == address(0)) revert NoZeroAddress();
lockDealNFT = _lockDealNFT;
}

/// @dev Struct to store user pool data
struct Builder {
UserPool[] userPools;
uint256 totalAmount;
UserPool[] userPools; // Array of user pools
uint256 totalAmount; // Total amount of tokens involved
}

/// @dev Struct to represent a user pool
struct UserPool {
address user;
uint256 amount;
address user; // Address of the user
uint256 amount; // Amount of tokens in the pool
}
}
}
11 changes: 8 additions & 3 deletions contracts/SimpleBuilder/SimpleBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import "@ironblocks/firewall-consumer/contracts/FirewallConsumer.sol";
/// @title SimpleBuilder contract
/// @notice This contract is used to create mass lock deals(NFTs)
contract SimpleBuilder is ERC721Holder, BuilderInternal, FirewallConsumer {
/// @dev Constructor to initialize the SimpleBuilder contract with the provided instance of LockDealNFT
/// @param _lockDealNFT Instance of the LockDealNFT contract
constructor(ILockDealNFT _lockDealNFT) BuilderState(_lockDealNFT) {}

/// @dev Error thrown when an invalid user length is detected
error InvalidUserLength();

/// @dev Struct to store local variables for building mass pools
struct MassPoolsLocals {
uint256 totalAmount;
address token;
Expand All @@ -23,8 +27,9 @@ contract SimpleBuilder is ERC721Holder, BuilderInternal, FirewallConsumer {
/// @notice Build mass pools
/// @param addressParams[0] - Provider address
/// @param addressParams[1] - Token address
/// @param userData - Array of user pools
/// @param params - Array of params. May be empty if this is DealProvider
/// @param userData Array of user pools containing user addresses and corresponding token amounts
/// @param params Array of parameters (may be empty if this is a DealProvider)
/// @param signature Cryptographic signature for the transfer
function buildMassPools(
address[] calldata addressParams,
Builder calldata userData,
Expand Down Expand Up @@ -57,4 +62,4 @@ contract SimpleBuilder is ERC721Holder, BuilderInternal, FirewallConsumer {
assert(locals.totalAmount == 0);
emit MassPoolsCreated(locals.token, locals.provider, locals.poolId, userData.userPools.length);
}
}
}
10 changes: 6 additions & 4 deletions contracts/SimpleRefundBuilder/RefundBuilderState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ abstract contract RefundBuilderState is BuilderInternal {
error InvalidAddressLength();
error InvalidRefundPoolId();

// Instance of the refund provider contract
/// @dev Instance of the refund provider contract
IProvider public immutable refundProvider;
// Instance of the collateral provider contract
/// @dev Instance of the collateral provider contract
IProvider public immutable collateralProvider;

constructor(IProvider _refund, IProvider _collateral) {
Expand All @@ -25,6 +25,7 @@ abstract contract RefundBuilderState is BuilderInternal {
collateralProvider = _collateral;
}

/// @dev Struct containing parameters data for building refund pools.
struct ParamsData {
ISimpleProvider provider; // Simple provider instance
address token; // ERC-20 token address
Expand All @@ -33,7 +34,8 @@ abstract contract RefundBuilderState is BuilderInternal {
uint256[] simpleParams; // Parameters for the simple provider
uint256[] refundParams; // Parameters for the refund provider
}


/// @dev Struct containing data for rebuilding refund pools.
struct Rebuilder {
ParamsData paramsData; // Parameters data
Builder userData; // User data (UserPool[] userPools; uint256 totalAmount)
Expand Down Expand Up @@ -86,4 +88,4 @@ abstract contract RefundBuilderState is BuilderInternal {
paramsData.simpleParams = paramsData.provider.getParams(poolId);
paramsData.simpleParams[0] = firstAmount;
}
}
}

0 comments on commit 04ad52d

Please sign in to comment.