Skip to content

Commit

Permalink
feat: create NO and add validator with permit (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko authored Oct 12, 2023
1 parent ab9c487 commit 6fe09e2
Show file tree
Hide file tree
Showing 3 changed files with 462 additions and 1 deletion.
279 changes: 279 additions & 0 deletions src/CommunityStakingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,82 @@ contract CommunityStakingModule is IStakingModule, CommunityStakingModuleBase {
emit NodeOperatorAdded(id, _name, _rewardAddress);
}

function addNodeOperatorStETHWithPermit(
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addNodeOperatorStETHWithPermit(
msg.sender,
_name,
_rewardAddress,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function addNodeOperatorStETHWithPermit(
address _from,
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addNodeOperatorStETHWithPermit(
_from,
_name,
_rewardAddress,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function _addNodeOperatorStETHWithPermit(
address _from,
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) internal {
// TODO sanity checks
_onlyValidNodeOperatorName(_name);

uint256 id = nodeOperatorsCount;
NodeOperator storage no = nodeOperators[id];
nodeOperatorIdsByName.set(_name, id);
no.name = _name;
no.rewardAddress = _rewardAddress;
no.active = true;
nodeOperatorsCount++;
activeNodeOperatorsCount++;

_bondManager().depositStETHWithPermit(
_from,
id,
_lido().getPooledEthByShares(
_bondManager().getRequiredBondSharesForKeys(_keysCount)
),
_permit
);

_addSigningKeys(id, _keysCount, _publicKeys, _signatures);

emit NodeOperatorAdded(id, _name, _rewardAddress);
}

function addNodeOperatorWstETH(
string calldata _name,
address _rewardAddress,
Expand Down Expand Up @@ -229,6 +305,84 @@ contract CommunityStakingModule is IStakingModule, CommunityStakingModuleBase {
emit NodeOperatorAdded(id, _name, _rewardAddress);
}

function addNodeOperatorWstETHWithPermit(
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addNodeOperatorWstETHWithPermit(
msg.sender,
_name,
_rewardAddress,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function addNodeOperatorWstETHWithPermit(
address _from,
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addNodeOperatorWstETHWithPermit(
_from,
_name,
_rewardAddress,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function _addNodeOperatorWstETHWithPermit(
address _from,
string calldata _name,
address _rewardAddress,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) internal {
// TODO sanity checks
_onlyValidNodeOperatorName(_name);

uint256 id = nodeOperatorsCount;
NodeOperator storage no = nodeOperators[id];
nodeOperatorIdsByName.set(_name, id);
no.name = _name;
no.rewardAddress = _rewardAddress;
no.active = true;
nodeOperatorsCount++;
activeNodeOperatorsCount++;

uint256 requiredEth = _lido().getPooledEthByShares(
_bondManager().getRequiredBondSharesForKeys(_keysCount)
);

_bondManager().depositWstETHWithPermit(
_from,
id,
_lido().getSharesByPooledEth(requiredEth), // to get wstETH amount
_permit
);

_addSigningKeys(id, _keysCount, _publicKeys, _signatures);

emit NodeOperatorAdded(id, _name, _rewardAddress);
}

function addValidatorKeysETH(
uint256 _nodeOperatorId,
uint256 _keysCount,
Expand Down Expand Up @@ -280,6 +434,69 @@ contract CommunityStakingModule is IStakingModule, CommunityStakingModuleBase {
_addSigningKeys(_nodeOperatorId, _keysCount, _publicKeys, _signatures);
}

function addValidatorKeysStETHWithPermit(
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addValidatorKeysStETHWithPermit(
msg.sender,
_nodeOperatorId,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function addValidatorKeysStETHWithPermit(
address _from,
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addValidatorKeysStETHWithPermit(
_from,
_nodeOperatorId,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function _addValidatorKeysStETHWithPermit(
address _from,
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) internal onlyExistingNodeOperator(_nodeOperatorId) {
// TODO sanity checks
// TODO store keys

_bondManager().depositStETHWithPermit(
_from,
_nodeOperatorId,
_lido().getPooledEthByShares(
_bondManager().getRequiredBondShares(
_nodeOperatorId,
_keysCount
)
),
_permit
);

_addSigningKeys(_nodeOperatorId, _keysCount, _publicKeys, _signatures);
}

function addValidatorKeysWstETH(
uint256 _nodeOperatorId,
uint256 _keysCount,
Expand All @@ -302,6 +519,68 @@ contract CommunityStakingModule is IStakingModule, CommunityStakingModuleBase {
_addSigningKeys(_nodeOperatorId, _keysCount, _publicKeys, _signatures);
}

function addValidatorKeysWstETHWithPermit(
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addValidatorKeysWstETHWithPermit(
msg.sender,
_nodeOperatorId,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function addValidatorKeysWstETHWithPermit(
address _from,
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) external {
return
_addValidatorKeysWstETHWithPermit(
_from,
_nodeOperatorId,
_keysCount,
_publicKeys,
_signatures,
_permit
);
}

function _addValidatorKeysWstETHWithPermit(
address _from,
uint256 _nodeOperatorId,
uint256 _keysCount,
bytes calldata _publicKeys,
bytes calldata _signatures,
ICommunityStakingBondManager.PermitInput calldata _permit
) internal onlyExistingNodeOperator(_nodeOperatorId) {
// TODO sanity checks
// TODO store keys

uint256 requiredEth = _lido().getPooledEthByShares(
_bondManager().getRequiredBondShares(_nodeOperatorId, _keysCount)
);

_bondManager().depositWstETHWithPermit(
_from,
_nodeOperatorId,
_lido().getSharesByPooledEth(requiredEth), // to get wstETH amount
_permit
);

_addSigningKeys(_nodeOperatorId, _keysCount, _publicKeys, _signatures);
}

function setNodeOperatorName(
uint256 _nodeOperatorId,
string memory _name
Expand Down
34 changes: 34 additions & 0 deletions src/interfaces/ICommunityStakingBondManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,37 @@
pragma solidity 0.8.21;

interface ICommunityStakingBondManager {
struct PermitInput {
uint256 value;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}

function getBondShares(
uint256 nodeOperatorId
) external view returns (uint256);

function getBondEth(uint256 nodeOperatorId) external view returns (uint256);

function depositWstETHWithPermit(
uint256 nodeOperatorId,
uint256 wstETHAmount,
PermitInput calldata permit
) external returns (uint256);

function depositWstETH(
uint256 nodeOperatorId,
uint256 wstETHAmount
) external returns (uint256);

function depositStETHWithPermit(
uint256 nodeOperatorId,
uint256 stETHAmount,
PermitInput calldata permit
) external returns (uint256);

function depositStETH(
uint256 nodeOperatorId,
uint256 stETHAmount
Expand All @@ -24,12 +44,26 @@ interface ICommunityStakingBondManager {
uint256 nodeOperatorId
) external payable returns (uint256);

function depositWstETHWithPermit(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount,
PermitInput calldata permit
) external returns (uint256);

function depositWstETH(
address from,
uint256 nodeOperatorId,
uint256 wstETHAmount
) external returns (uint256);

function depositStETHWithPermit(
address from,
uint256 nodeOperatorId,
uint256 stETHAmount,
PermitInput calldata permit
) external returns (uint256);

function depositStETH(
address from,
uint256 nodeOperatorId,
Expand Down
Loading

0 comments on commit 6fe09e2

Please sign in to comment.