Skip to content

Commit

Permalink
complete tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
teddy-nodeset committed Apr 23, 2024
1 parent 21eb43e commit 7c73012
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 46 deletions.
1 change: 1 addition & 0 deletions contracts/Operator/NodeAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ contract NodeAccount is UpgradeableBase, Errors {
}

function _createMinipool(ValidatorConfig calldata _config, bytes memory _sig) internal {
vaf.validateSigUsedSigUsed(_sig);
if (vaf.preSignedExitMessageCheck()) {
console.log('_createMinipool: message hash');
console.logBytes32(
Expand Down
6 changes: 6 additions & 0 deletions contracts/Operator/NodeAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract NodeAccountFactory is UpgradeableBase, Errors {

bool public preSignedExitMessageCheck;

mapping(bytes => bool) public sigsUsed;
mapping(address => address) public minipoolNodeAccountMap;

/**
Expand Down Expand Up @@ -130,6 +131,11 @@ contract NodeAccountFactory is UpgradeableBase, Errors {
lockUpTime = _newLockUpTime;
}

function validateSigUsedSigUsed(bytes memory _sig) external onlyProtocol {
require(!sigsUsed[_sig], "sig already used");
sigsUsed[_sig] = true;
}

function setImplementation(address _implementationAddress) external {
if (!_directory.hasRole(Constants.ADMIN_ROLE, msg.sender)) {
revert BadRole(Constants.ADMIN_ROLE, msg.sender);
Expand Down
31 changes: 8 additions & 23 deletions contracts/Operator/OperatorDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,14 @@ contract OperatorDistributor is UpgradeableBase, Errors {
}
// stakeRPLOnBehalfOf
// transfer RPL to deposit pool
IERC20(_directory.getRPLAddress()).transfer(
_directory.getDepositPoolAddress(),
_requiredStake
);
IERC20(_directory.getRPLAddress()).transfer(_directory.getDepositPoolAddress(), _requiredStake);
FundRouter(_directory.getDepositPoolAddress()).stakeRPLFor(_NodeAccount, _requiredStake);
} else {
if (currentRplBalance == 0) {
return;
}
// stake what we have
IERC20(_directory.getRPLAddress()).transfer(
_directory.getDepositPoolAddress(),
currentRplBalance
);
IERC20(_directory.getRPLAddress()).transfer(_directory.getDepositPoolAddress(), currentRplBalance);
FundRouter(_directory.getDepositPoolAddress()).stakeRPLFor(_NodeAccount, currentRplBalance);
}
}
Expand Down Expand Up @@ -359,7 +353,7 @@ contract OperatorDistributor is UpgradeableBase, Errors {
* @dev Processes a single minipool by performing RPL top-up and distributing balance if certain conditions are met.
*/
function _processNextMinipool() internal {
if(nextMinipoolHavestIndex > minipoolAddresses.length - 1) {
if (nextMinipoolHavestIndex > minipoolAddresses.length - 1) {
nextMinipoolHavestIndex = 0;
}

Expand All @@ -383,19 +377,11 @@ contract OperatorDistributor is UpgradeableBase, Errors {
console.log('_processNextMinipool.ethStaked', ethStaked);

rebalanceRplStake(nodeAddress, ethStaked);
//performTopDown(nodeAddress, ethStaked);


uint256 balance = minipool.getNodeDepositBalance();
// TODO: Talk to Mike: used to pass balance >= 8 ether but whent this is true, it will always revert
if (balance >= 8 ether) {
//minipool.distributeBalance(false);
NodeAccount(
NodeAccountFactory(_directory.getNodeAccountFactoryAddress()).minipoolNodeAccountMap(
address(minipool)
)
).distributeBalance(false, address(minipool));
}

uint256 totalBalance = address(minipool).balance - minipool.getNodeRefundBalance();
NodeAccount(
NodeAccountFactory(_directory.getNodeAccountFactoryAddress()).minipoolNodeAccountMap(address(minipool))
).distributeBalance(totalBalance < 8 ether, address(minipool));

nextMinipoolHavestIndex++;
}
Expand Down Expand Up @@ -424,7 +410,6 @@ contract OperatorDistributor is UpgradeableBase, Errors {
nodeOperatorEthStaked[_nodeOperator] -= _bond;
}


/**
* @notice Retrieves the list of minipool addresses managed by the contract.
* @dev This function provides a way to fetch all the current minipool addresses in memory.
Expand Down
3 changes: 3 additions & 0 deletions contracts/Whitelist/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ contract Whitelist is UpgradeableBase {
mapping(address => Operator) public nodeMap;
mapping(uint256 => address) public nodeIndexMap;
mapping(address => uint256) public reverseNodeIndexMap;
mapping(bytes => bool) public sigsUsed;

uint256 public numOperators;

Expand Down Expand Up @@ -111,6 +112,8 @@ contract Whitelist is UpgradeableBase {
/// @param _operator The address of the operator to be added.
/// @return An Operator struct containing details about the newly added operator.
function _addOperator(address _operator, bytes memory _sig) internal returns (Operator memory) {
require(!sigsUsed[_sig], 'sig already used');
sigsUsed[_sig] = true;
bytes32 messageHash = keccak256(abi.encodePacked(_operator, address(this)));
console.log('_addOperator: message hash');
console.logBytes32(messageHash);
Expand Down
Loading

0 comments on commit 7c73012

Please sign in to comment.