Skip to content

Commit

Permalink
extended referral methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Manoj Patra committed Sep 18, 2023
1 parent 0dbe7f1 commit b9070f5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
26 changes: 24 additions & 2 deletions contracts/StaderStakePoolsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 20 additions & 1 deletion contracts/UserWithdrawalManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/interfaces/IStaderStakePoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IUserWithdrawalManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b9070f5

Please sign in to comment.