From 8c0ae3f0076fcbc6129272abc7ea85fbf9c61ea4 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 28 Jun 2024 08:48:49 +0300 Subject: [PATCH 1/3] add v3.1 contracts interfaces --- contracts/interfaces/IDispenserProvider.sol | 21 ++++++++ contracts/interfaces/IInvestProvider.sol | 47 +++++++++++++++++ contracts/interfaces/IInvestedProvider.sol | 14 +++++ contracts/interfaces/IWhiteListRouter.sol | 58 +++++++++++++++++++++ contracts/interfaces/IWhiteListV2.sol | 21 ++++++++ 5 files changed, 161 insertions(+) create mode 100644 contracts/interfaces/IDispenserProvider.sol create mode 100644 contracts/interfaces/IInvestProvider.sol create mode 100644 contracts/interfaces/IInvestedProvider.sol create mode 100644 contracts/interfaces/IWhiteListRouter.sol create mode 100644 contracts/interfaces/IWhiteListV2.sol diff --git a/contracts/interfaces/IDispenserProvider.sol b/contracts/interfaces/IDispenserProvider.sol new file mode 100644 index 0000000..41b3dfb --- /dev/null +++ b/contracts/interfaces/IDispenserProvider.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./ISimpleProvider.sol"; + +interface IDispenserProvider is ISimpleProvider { + function dispenseLock( + uint256 poolId, + uint256 validUntil, + address owner, + Builder[] calldata data, + bytes calldata signature + ) external; + + struct Builder { + ISimpleProvider simpleProvider; + uint256[] params; + } + + event TokensDispensed(uint256 poolId, address user, uint256 amountTaken, uint256 leftAmount); +} diff --git a/contracts/interfaces/IInvestProvider.sol b/contracts/interfaces/IInvestProvider.sol new file mode 100644 index 0000000..fa51790 --- /dev/null +++ b/contracts/interfaces/IInvestProvider.sol @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./IInvestedProvider.sol"; +import "./IProvider.sol"; + +interface IInvestProvider is IProvider { + /// @notice Invest in a IDO pool + /// @param poolId - the ID of the pool + /// @param amount - the amount of tokens to invest + function invest(uint256 poolId, uint256 amount, bytes calldata data) external; + + function createNewPool( + Pool calldata pool, + bytes calldata data, + uint256 sourcePoolId + ) external returns (uint256 poolId); + + struct IDO { + Pool pool; + uint256 leftAmount; + } + + struct Pool { + uint256 maxAmount; + uint256 whiteListId; + IInvestedProvider investedProvider; + } + + event Invested( + uint256 indexed poolId, + address indexed user, + uint256 amount + ); + event NewPoolCreated(uint256 indexed poolId, IDO pool); + + error InvalidLockDealNFT(); + error InvalidInvestedProvider(); + error InvalidProvider(); + error InvalidPoolId(); + error OnlyLockDealNFT(); + error NoZeroAddress(); + error NoZeroAmount(); + error ExceededLeftAmount(); + /// @dev Error thrown when the length of parameters is invalid + error InvalidParamsLength(uint256 paramsLength, uint256 minLength); +} diff --git a/contracts/interfaces/IInvestedProvider.sol b/contracts/interfaces/IInvestedProvider.sol new file mode 100644 index 0000000..a767854 --- /dev/null +++ b/contracts/interfaces/IInvestedProvider.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./IProvider.sol"; + +interface IInvestedProvider is IProvider { + function onCreation(uint256 poolId, bytes calldata data) external; + + function onInvest( + uint256 poolId, + uint256 amount, + bytes calldata data + ) external; +} diff --git a/contracts/interfaces/IWhiteListRouter.sol b/contracts/interfaces/IWhiteListRouter.sol new file mode 100644 index 0000000..ba02eec --- /dev/null +++ b/contracts/interfaces/IWhiteListRouter.sol @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./IWhiteListV2.sol"; + +interface IWhiteListRouter { + function handleInvestment( + address user, + uint256 whiteListId, + uint256 amount + ) external; + + function setWhiteListStatus(IWhiteListV2 whiteList, bool status) external; + + function createNewWhiteList( + WhiteListSetup[] calldata data, + DictionaryItems[] calldata dictionary, + address consumer + ) external; + + struct Permissions { + address consumer; + address owner; + } + + struct WhiteListSettings { + WhiteListSetup setup; + uint256 whiteListId; + } + + struct WhiteListSetup { + IWhiteListV2 whiteList; + uint256 startTime; + uint256 endTime; + } + + struct DictionaryItems { + address[] users; + uint256[] amounts; + } + + event UpdateWhiteListStatus(IWhiteListV2 indexed whiteList, bool status); + event HandleInvestment( + address indexed user, + uint256 whiteListId, + uint256 amount + ); + + error ZeroAddress(); + error InvalidConsumer(); + error ZeroAmount(); + error AlreadySet(); + error InvalidTime(); + error WhiteListNotFound(); + error InvalidWhiteListContract(); + error LengthMismatch(uint256 dictionaryLength, uint256 dataLength); + error ZeroArrayLength(); +} diff --git a/contracts/interfaces/IWhiteListV2.sol b/contracts/interfaces/IWhiteListV2.sol new file mode 100644 index 0000000..7a44979 --- /dev/null +++ b/contracts/interfaces/IWhiteListV2.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IWhiteListV2 { + function createManualWhiteList( + uint256 changeUntil, + address contractAddress + ) external payable returns (uint256 id); + + function addAddress( + uint256 id, + address[] calldata users, + uint256[] calldata amounts + ) external; + + function removeAddress(uint256 id, address[] calldata users) external; + + function register(address subject, uint256 id, uint256 amount) external; + + function lastRoundRegister(address subject, uint256 id) external; +} From 55f61026dc8e8b3fbda871cbaff9c1f564e95a72 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Fri, 28 Jun 2024 08:51:54 +0300 Subject: [PATCH 2/3] fix import --- contracts/interfaces/IInvestProvider.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/interfaces/IInvestProvider.sol b/contracts/interfaces/IInvestProvider.sol index fa51790..43c53e3 100644 --- a/contracts/interfaces/IInvestProvider.sol +++ b/contracts/interfaces/IInvestProvider.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.0; import "./IInvestedProvider.sol"; -import "./IProvider.sol"; interface IInvestProvider is IProvider { /// @notice Invest in a IDO pool From 2becbe6e5edc34deac14df8f65fa00268f3faf2b Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Thu, 5 Dec 2024 07:12:34 +0200 Subject: [PATCH 3/3] update interfaces, dispenser and invest providers --- contracts/interfaces/IDispenserProvider.sol | 25 +++++++ contracts/interfaces/IInvestProvider.sol | 81 +++++++++++++++------ contracts/interfaces/IInvestedProvider.sol | 14 ---- contracts/interfaces/IWhiteListRouter.sol | 58 --------------- contracts/interfaces/IWhiteListV2.sol | 21 ------ package-lock.json | 4 +- package.json | 2 +- 7 files changed, 87 insertions(+), 118 deletions(-) delete mode 100644 contracts/interfaces/IInvestedProvider.sol delete mode 100644 contracts/interfaces/IWhiteListRouter.sol delete mode 100644 contracts/interfaces/IWhiteListV2.sol diff --git a/contracts/interfaces/IDispenserProvider.sol b/contracts/interfaces/IDispenserProvider.sol index 41b3dfb..710afda 100644 --- a/contracts/interfaces/IDispenserProvider.sol +++ b/contracts/interfaces/IDispenserProvider.sol @@ -3,7 +3,17 @@ pragma solidity ^0.8.0; import "./ISimpleProvider.sol"; +/// @title IDispenserProvider +/// @dev Interface for the Dispenser provider, responsible for dispensing tokens from a pool +/// and interacting with simple providers for NFT handling. interface IDispenserProvider is ISimpleProvider { + /// @notice Dispenses tokens from the pool to the specified user. + /// @dev Validates the provider, checks the signature, and processes the dispensation logic for the given pool. + /// @param poolId The unique identifier for the pool. + /// @param validUntil The timestamp until which the dispense is valid. + /// @param owner The address of the owner requesting to dispense tokens. + /// @param data The array of Builder structs containing provider and parameters data. + /// @param signature The cryptographic signature verifying the validity of the transaction. function dispenseLock( uint256 poolId, uint256 validUntil, @@ -12,10 +22,25 @@ interface IDispenserProvider is ISimpleProvider { bytes calldata signature ) external; + /// @dev Represents the data required to handle a token dispensation. + /// @param simpleProvider The provider that handles the token dispensation logic. + /// @param params Additional parameters required for dispensing the tokens. struct Builder { ISimpleProvider simpleProvider; uint256[] params; } + /// @notice Emitted when tokens are dispensed from the pool to a user. + /// @param poolId The unique identifier for the pool. + /// @param user The address of the user receiving the tokens. + /// @param amountTaken The amount of tokens dispensed from the pool. + /// @param leftAmount The remaining amount of tokens in the pool after dispensation. event TokensDispensed(uint256 poolId, address user, uint256 amountTaken, uint256 leftAmount); + + error CallerNotApproved(address caller, address owner, uint256 poolId); + error InvalidTime(uint256 currentTime, uint256 validUntil); + error InvalidSignature(uint256 poolId, address owner); + error TokensAlreadyTaken(uint256 poolId, address owner); + error AmountMustBeGreaterThanZero(); + error NotEnoughTokensInPool(uint256 requestedAmount, uint256 availableAmount); } diff --git a/contracts/interfaces/IInvestProvider.sol b/contracts/interfaces/IInvestProvider.sol index 43c53e3..28c842d 100644 --- a/contracts/interfaces/IInvestProvider.sol +++ b/contracts/interfaces/IInvestProvider.sol @@ -1,46 +1,83 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "./IInvestedProvider.sol"; +import "./IProvider.sol"; +/** + * @title IInvestProvider + * @dev Interface for managing investment pools, including investment actions and pool creation. + * It extends the IProvider interface and defines additional functionality specific to investment pools. + */ interface IInvestProvider is IProvider { - /// @notice Invest in a IDO pool - /// @param poolId - the ID of the pool - /// @param amount - the amount of tokens to invest - function invest(uint256 poolId, uint256 amount, bytes calldata data) external; + /** + * @notice Allows an address to invest in a specific IDO (Initial DEX Offering) pool. + * @dev The function is used to transfer a specified amount of tokens into the pool. + * @param poolId The ID of the pool where the investment will occur. + * @param amount The amount of tokens to be invested in the pool. + */ + function invest(uint256 poolId, uint256 amount, uint256 validUntil, bytes calldata signature) external; + /** + * @notice Creates a new investment pool. + * @dev This function is used to create a new pool with the specified parameters, copying the settings of an existing source pool. + * It will initialize the new pool with the given details and return its poolId. + * @param poolAmount The maximum amount of tokens that can be invested in the pool. + * @param investSigner The address of the signer for investments. + * @param dispenserSigner The address of the signer for dispenses. + * @param sourcePoolId The ID of the source pool to copy settings from. + * @return poolId The ID of the newly created pool. + */ function createNewPool( - Pool calldata pool, - bytes calldata data, + uint256 poolAmount, + address investSigner, + address dispenserSigner, uint256 sourcePoolId ) external returns (uint256 poolId); - struct IDO { - Pool pool; - uint256 leftAmount; - } + /** + * @notice Creates a new investment pool. + * @dev This function is used to create a new pool with the specified parameters, copying the settings of an existing source pool. + * It will initialize the new pool with the given details and return its poolId. + * @param poolAmount The maximum amount of tokens that can be invested in the pool. + * @param sourcePoolId The ID of the source pool to copy settings from. + * @return poolId The ID of the newly created pool. + */ + function createNewPool(uint256 poolAmount, uint256 sourcePoolId) external returns (uint256 poolId); + /** + * @dev Struct that represents an IDO pool, which contains the pool's configuration and the remaining investment amount. + */ struct Pool { - uint256 maxAmount; - uint256 whiteListId; - IInvestedProvider investedProvider; + uint256 maxAmount; // The maximum amount of tokens that can be invested in the pool + uint256 leftAmount; // The amount of tokens left to invest in the pool } - event Invested( - uint256 indexed poolId, - address indexed user, - uint256 amount - ); - event NewPoolCreated(uint256 indexed poolId, IDO pool); + /** + * @notice Emitted when a user successfully invests in a pool. + * @param poolId The ID of the pool where the investment was made. + * @param user The address of the user who made the investment. + * @param amount The amount of tokens that were invested. + */ + event Invested(uint256 indexed poolId, address indexed user, uint256 amount); + + /** + * @notice Emitted when a new pool is created. + * @param poolId The ID of the newly created pool. + * @param owner The address of the user who created the pool. + * @param poolAmount The maximum amount of tokens that can be invested in the pool. + */ + event NewPoolCreated(uint256 indexed poolId, address indexed owner, uint256 poolAmount); error InvalidLockDealNFT(); - error InvalidInvestedProvider(); error InvalidProvider(); error InvalidPoolId(); error OnlyLockDealNFT(); error NoZeroAddress(); + error InvalidParams(); error NoZeroAmount(); error ExceededLeftAmount(); - /// @dev Error thrown when the length of parameters is invalid error InvalidParamsLength(uint256 paramsLength, uint256 minLength); + error InvalidSignature(uint256 poolId, address owner); + error InvalidTime(uint256 currentTime, uint256 validUntil); + error InvalidSourcePoolId(uint256 sourcePoolId); } diff --git a/contracts/interfaces/IInvestedProvider.sol b/contracts/interfaces/IInvestedProvider.sol deleted file mode 100644 index a767854..0000000 --- a/contracts/interfaces/IInvestedProvider.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "./IProvider.sol"; - -interface IInvestedProvider is IProvider { - function onCreation(uint256 poolId, bytes calldata data) external; - - function onInvest( - uint256 poolId, - uint256 amount, - bytes calldata data - ) external; -} diff --git a/contracts/interfaces/IWhiteListRouter.sol b/contracts/interfaces/IWhiteListRouter.sol deleted file mode 100644 index ba02eec..0000000 --- a/contracts/interfaces/IWhiteListRouter.sol +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "./IWhiteListV2.sol"; - -interface IWhiteListRouter { - function handleInvestment( - address user, - uint256 whiteListId, - uint256 amount - ) external; - - function setWhiteListStatus(IWhiteListV2 whiteList, bool status) external; - - function createNewWhiteList( - WhiteListSetup[] calldata data, - DictionaryItems[] calldata dictionary, - address consumer - ) external; - - struct Permissions { - address consumer; - address owner; - } - - struct WhiteListSettings { - WhiteListSetup setup; - uint256 whiteListId; - } - - struct WhiteListSetup { - IWhiteListV2 whiteList; - uint256 startTime; - uint256 endTime; - } - - struct DictionaryItems { - address[] users; - uint256[] amounts; - } - - event UpdateWhiteListStatus(IWhiteListV2 indexed whiteList, bool status); - event HandleInvestment( - address indexed user, - uint256 whiteListId, - uint256 amount - ); - - error ZeroAddress(); - error InvalidConsumer(); - error ZeroAmount(); - error AlreadySet(); - error InvalidTime(); - error WhiteListNotFound(); - error InvalidWhiteListContract(); - error LengthMismatch(uint256 dictionaryLength, uint256 dataLength); - error ZeroArrayLength(); -} diff --git a/contracts/interfaces/IWhiteListV2.sol b/contracts/interfaces/IWhiteListV2.sol deleted file mode 100644 index 7a44979..0000000 --- a/contracts/interfaces/IWhiteListV2.sol +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -interface IWhiteListV2 { - function createManualWhiteList( - uint256 changeUntil, - address contractAddress - ) external payable returns (uint256 id); - - function addAddress( - uint256 id, - address[] calldata users, - uint256[] calldata amounts - ) external; - - function removeAddress(uint256 id, address[] calldata users) external; - - function register(address subject, uint256 id, uint256 amount) external; - - function lastRoundRegister(address subject, uint256 id) external; -} diff --git a/package-lock.json b/package-lock.json index fd4f171..8720da9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@poolzfinance/poolz-helper-v2", - "version": "3.0.0", + "version": "3.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@poolzfinance/poolz-helper-v2", - "version": "3.0.0", + "version": "3.0.2", "license": "MIT", "dependencies": { "@ethersproject/bignumber": "^5.7.0", diff --git a/package.json b/package.json index dad17b3..efb6dbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poolzfinance/poolz-helper-v2", - "version": "3.0.0", + "version": "3.0.2", "description": "A single source of truth of helper contracts used by Poolz.", "main": "dist/index.js", "types": "dist/index.d.ts",