From b9070f582b178426c0cf1eaa20f170c53126f870 Mon Sep 17 00:00:00 2001 From: Manoj Patra Date: Mon, 18 Sep 2023 11:15:40 +0530 Subject: [PATCH] extended referral methods --- contracts/StaderStakePoolsManager.sol | 26 +++++++++++++++++-- contracts/UserWithdrawalManager.sol | 21 ++++++++++++++- .../interfaces/IStaderStakePoolManager.sol | 9 +++++++ .../interfaces/IUserWithdrawalManager.sol | 14 ++++++++++ 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/contracts/StaderStakePoolsManager.sol b/contracts/StaderStakePoolsManager.sol index c8fef29e..e84b4944 100644 --- a/contracts/StaderStakePoolsManager.sol +++ b/contracts/StaderStakePoolsManager.sol @@ -165,8 +165,30 @@ contract StaderStakePoolsManager is return _convertToAssets(_shares, Math.Rounding.Down); } - // stake ETH to get equivalent amount of ETHx token based on exchange rate - function deposit(address _receiver) external payable override whenNotPaused returns (uint256) { + /** + * @notice auxiliary method for KOL users/referrals to stake ETH and mints ETHx for _receiver based on exchange rate + * @param _receiver account where ETHx minted are sent + * @param _referralId referral id of KOL + * @return _shares amount of ETHx token minted and sent to receiver + * @dev emits an event with _referralId + */ + function depositViaKOL(address _receiver, string calldata _referralId) + external + payable + override + whenNotPaused + returns (uint256 _shares) + { + _shares = deposit(_receiver); + emit DepositedViaKOL(msg.sender, _receiver, msg.value, _shares, _referralId); + } + + /** + * @notice stake ETH and mints ETHx for _receiver based on exchange rate + * @param _receiver account where ETHx + * @return shares amount of ETHx token minted and sent to receiver + */ + function deposit(address _receiver) public payable override whenNotPaused returns (uint256) { uint256 assets = msg.value; if (assets > maxDeposit() || assets < minDeposit()) { revert InvalidDepositAmount(); diff --git a/contracts/UserWithdrawalManager.sol b/contracts/UserWithdrawalManager.sol index d2e6437a..c2cea43a 100644 --- a/contracts/UserWithdrawalManager.sol +++ b/contracts/UserWithdrawalManager.sol @@ -86,12 +86,31 @@ contract UserWithdrawalManager is emit UpdatedStaderConfig(_staderConfig); } + /** + * @notice auxiliary method to put a withdrawal request + * @param _ethXAmount amount of ethX shares to withdraw + * @param _owner owner of withdraw request to redeem + * @param _referralId referral id of KOL + * @return _requestId + * @dev emits an event with referralId + */ + function requestWithdrawViaKOL( + uint256 _ethXAmount, + address _owner, + string calldata _referralId + ) external override whenNotPaused returns (uint256 _requestId) { + uint256 etherAmount = IStaderStakePoolManager(staderConfig.getStakePoolManager()).previewWithdraw(_ethXAmount); + _requestId = requestWithdraw(_ethXAmount, _owner); + emit WithdrawRequestReceivedViaKOL(msg.sender, _owner, _requestId, _ethXAmount, etherAmount, _referralId); + } + /** * @notice put a withdrawal request * @param _ethXAmount amount of ethX shares to withdraw * @param _owner owner of withdraw request to redeem + * @return requestId */ - function requestWithdraw(uint256 _ethXAmount, address _owner) external override whenNotPaused returns (uint256) { + function requestWithdraw(uint256 _ethXAmount, address _owner) public override whenNotPaused returns (uint256) { if (_owner == address(0)) revert ZeroAddressReceived(); uint256 assets = IStaderStakePoolManager(staderConfig.getStakePoolManager()).previewWithdraw(_ethXAmount); if (assets < staderConfig.getMinWithdrawAmount() || assets > staderConfig.getMaxWithdrawAmount()) { diff --git a/contracts/interfaces/IStaderStakePoolManager.sol b/contracts/interfaces/IStaderStakePoolManager.sol index a6d0fb3e..4ec0428f 100644 --- a/contracts/interfaces/IStaderStakePoolManager.sol +++ b/contracts/interfaces/IStaderStakePoolManager.sol @@ -14,6 +14,13 @@ interface IStaderStakePoolManager { // Events event UpdatedStaderConfig(address staderConfig); + event DepositedViaKOL( + address indexed caller, + address indexed owner, + uint256 assets, + uint256 shares, + string referralId + ); event Deposited(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event ExecutionLayerRewardsReceived(uint256 amount); event AuctionedEthReceived(uint256 amount); @@ -23,6 +30,8 @@ interface IStaderStakePoolManager { event WithdrawVaultUserShareReceived(uint256 amount); event UpdatedExcessETHDepositCoolDown(uint256 excessETHDepositCoolDown); + function depositViaKOL(address _receiver, string calldata _referralId) external payable returns (uint256); + function deposit(address _receiver) external payable returns (uint256); function previewDeposit(uint256 _assets) external view returns (uint256); diff --git a/contracts/interfaces/IUserWithdrawalManager.sol b/contracts/interfaces/IUserWithdrawalManager.sol index f14ab6da..11f2db25 100644 --- a/contracts/interfaces/IUserWithdrawalManager.sol +++ b/contracts/interfaces/IUserWithdrawalManager.sol @@ -19,6 +19,14 @@ interface IUserWithdrawalManager { // Events event UpdatedFinalizationBatchLimit(uint256 paginationLimit); event UpdatedStaderConfig(address staderConfig); + event WithdrawRequestReceivedViaKOL( + address indexed _msgSender, + address _recipient, + uint256 _requestId, + uint256 _sharesAmount, + uint256 _etherAmount, + string referralId + ); event WithdrawRequestReceived( address indexed _msgSender, address _recipient, @@ -62,6 +70,12 @@ interface IUserWithdrawalManager { function updateFinalizationBatchLimit(uint256 _paginationLimit) external; + function requestWithdrawViaKOL( + uint256 _ethXAmount, + address receiver, + string calldata referralId + ) external returns (uint256); + function requestWithdraw(uint256 _ethXAmount, address receiver) external returns (uint256); function finalizeUserWithdrawalRequest() external;