Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mortimr committed Dec 1, 2022
1 parent 8755878 commit 2ef85ce
Show file tree
Hide file tree
Showing 13 changed files with 679 additions and 2,352 deletions.
5 changes: 2 additions & 3 deletions src/contracts/ConsensusLayerFeeDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ contract ConsensusLayerFeeDispatcher is IFeeDispatcher {
/// @notice Retrieve the assigned withdrawer for the given public key root
/// @param _publicKeyRoot Public key root to get the owner
function getWithdrawer(bytes32 _publicKeyRoot) external view returns (address) {
IStakingContractFeeDetails stakingContract = IStakingContractFeeDetails(
STAKING_CONTRACT_ADDRESS_SLOT.getAddress()
);
IStakingContractFeeDetails stakingContract =
IStakingContractFeeDetails(STAKING_CONTRACT_ADDRESS_SLOT.getAddress());
return stakingContract.getWithdrawerFromPublicKeyRoot(_publicKeyRoot);
}

Expand Down
19 changes: 5 additions & 14 deletions src/contracts/ExecutionLayerFeeDispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ contract ExecutionLayerFeeDispatcher is IFeeDispatcher {
if (balance == 0) {
revert ZeroBalanceWithdrawal();
}
IStakingContractFeeDetails stakingContract = IStakingContractFeeDetails(
STAKING_CONTRACT_ADDRESS_SLOT.getAddress()
);
IStakingContractFeeDetails stakingContract =
IStakingContractFeeDetails(STAKING_CONTRACT_ADDRESS_SLOT.getAddress());
address withdrawer = stakingContract.getWithdrawerFromPublicKeyRoot(_publicKeyRoot);
address operator = stakingContract.getOperatorFeeRecipient(_publicKeyRoot);
address treasury = stakingContract.getTreasury();
Expand All @@ -86,14 +85,7 @@ contract ExecutionLayerFeeDispatcher is IFeeDispatcher {
revert TreasuryReceiveError(data);
}
}
emit Withdrawal(
withdrawer,
operator,
_publicKeyRoot,
balance - globalFee,
operatorFee,
globalFee - operatorFee
);
emit Withdrawal(withdrawer, operator, _publicKeyRoot, balance - globalFee, operatorFee, globalFee - operatorFee);
}

/// @notice Retrieve the staking contract address
Expand All @@ -104,9 +96,8 @@ contract ExecutionLayerFeeDispatcher is IFeeDispatcher {
/// @notice Retrieve the assigned withdrawer for the given public key root
/// @param _publicKeyRoot Public key root to get the owner
function getWithdrawer(bytes32 _publicKeyRoot) external view returns (address) {
IStakingContractFeeDetails stakingContract = IStakingContractFeeDetails(
STAKING_CONTRACT_ADDRESS_SLOT.getAddress()
);
IStakingContractFeeDetails stakingContract =
IStakingContractFeeDetails(STAKING_CONTRACT_ADDRESS_SLOT.getAddress());
return stakingContract.getWithdrawerFromPublicKeyRoot(_publicKeyRoot);
}

Expand Down
170 changes: 67 additions & 103 deletions src/contracts/StakingContract.sol

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/contracts/TUPProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ contract TUPProxy is TransparentUpgradeableProxy {

error CallWhenPaused();

constructor(
address _logic,
address admin_,
bytes memory _data
) payable TransparentUpgradeableProxy(_logic, admin_, _data) {}
constructor(address _logic, address admin_, bytes memory _data)
payable
TransparentUpgradeableProxy(_logic, admin_, _data)
{}

/// @dev Retrieves Paused state
/// @return Paused state
Expand Down
8 changes: 2 additions & 6 deletions src/contracts/Treasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ contract Treasury {
uint256[] public percents;
uint256 internal locked = 1;

constructor(
address _admin,
address[] memory _beneficiaries,
uint256[] memory _percents
) {
constructor(address _admin, address[] memory _beneficiaries, uint256[] memory _percents) {
if (_beneficiaries.length != _percents.length) {
revert InvalidArrayLengths();
}
Expand Down Expand Up @@ -104,7 +100,7 @@ contract Treasury {
/// @param _percents List of percents
function _checkPercents(uint256[] memory _percents) internal pure {
uint256 sum;
for (uint256 idx = 0; idx < _percents.length; ) {
for (uint256 idx = 0; idx < _percents.length;) {
sum += _percents[idx];
unchecked {
++idx;
Expand Down
18 changes: 4 additions & 14 deletions src/contracts/libs/BytesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,10 @@ library BytesLib {
// length of the arrays.
end := add(mc, length)

for {
let cc := add(_postBytes, 0x20)
} lt(mc, end) {
for { let cc := add(_postBytes, 0x20) } lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
mstore(mc, mload(cc))
}
} { mstore(mc, mload(cc)) }

// Update the free-memory pointer by padding our last write location
// to 32 bytes: add 31 bytes to the end of tempBytes to move to the
Expand All @@ -94,11 +90,7 @@ library BytesLib {
return tempBytes;
}

function slice(
bytes memory _bytes,
uint256 _start,
uint256 _length
) internal pure returns (bytes memory) {
function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) {
require(_length + 31 >= _length, "slice_overflow");
require(_bytes.length >= _start + _length, "slice_outOfBounds");

Expand Down Expand Up @@ -135,9 +127,7 @@ library BytesLib {
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
mstore(mc, mload(cc))
}
} { mstore(mc, mload(cc)) }

mstore(tempBytes, _length)

Expand Down
14 changes: 4 additions & 10 deletions src/contracts/libs/StakingContractStorageLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ library StakingContractStorageLib {
vfi.funded = uint32(value >> 32);
}

function setValidatorsFundingInfo(
uint256 _index,
uint32 _availableKeys,
uint32 _funded
) internal {
function setValidatorsFundingInfo(uint256 _index, uint32 _availableKeys, uint32 _funded) internal {
UintToUintMappingSlot storage p;
bytes32 slot = VALIDATORS_FUNDING_INFO_SLOT;

Expand All @@ -173,9 +169,8 @@ library StakingContractStorageLib {

uint256 slotIndex = _index >> 2;
uint256 innerIndex = (_index & 3) << 6;
p.value[slotIndex] =
(p.value[slotIndex] & (~(uint256(0xFFFFFFFFFFFFFFFF) << innerIndex))) |
((uint256(_availableKeys) | (uint256(_funded) << 32)) << innerIndex);
p.value[slotIndex] = (p.value[slotIndex] & (~(uint256(0xFFFFFFFFFFFFFFFF) << innerIndex)))
| ((uint256(_availableKeys) | (uint256(_funded) << 32)) << innerIndex);
}

/* ========================================
Expand Down Expand Up @@ -222,8 +217,7 @@ library StakingContractStorageLib {
mapping(bytes32 => OperatorIndex) value;
}

bytes32 internal constant OPERATOR_INDEX_PER_VALIDATOR_SLOT =
keccak256("StakingContract.operatorIndexPerValidator");
bytes32 internal constant OPERATOR_INDEX_PER_VALIDATOR_SLOT = keccak256("StakingContract.operatorIndexPerValidator");

function getOperatorIndexPerValidator() internal pure returns (OperatorIndexPerValidatorSlot storage p) {
bytes32 slot = OPERATOR_INDEX_PER_VALIDATOR_SLOT;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ConsensusLayerFeeDispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ contract ConsensusLayerFeeDispatcherTest {
function testSendFundsWithCall() external {
vm.deal(bob, 1 ether);
vm.startPrank(bob);
(bool status, ) = address(cld).call{value: 1 ether}("");
(bool status,) = address(cld).call{value: 1 ether}("");
require(status == false);
vm.stopPrank();
}

function testFallbackError() external {
vm.deal(bob, 1 ether);
vm.startPrank(bob);
(bool status, ) = address(cld).call{value: 1 ether}(abi.encodeWithSignature("thisMethodIsNotAvailable()"));
(bool status,) = address(cld).call{value: 1 ether}(abi.encodeWithSignature("thisMethodIsNotAvailable()"));
require(status == false);
vm.stopPrank();
}
Expand Down
13 changes: 4 additions & 9 deletions src/test/ExecutionLayerFeeDispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ contract ExecutionLayerFeeDispatcherTest {
function testSendFundsWithCall() external {
vm.deal(bob, 1 ether);
vm.startPrank(bob);
(bool status, ) = address(eld).call{value: 1 ether}("");
(bool status,) = address(eld).call{value: 1 ether}("");
require(status == false);
vm.stopPrank();
}

function testFallbackError() external {
vm.deal(bob, 1 ether);
vm.startPrank(bob);
(bool status, ) = address(eld).call{value: 1 ether}(abi.encodeWithSignature("thisMethodIsNotAvailable()"));
(bool status,) = address(eld).call{value: 1 ether}(abi.encodeWithSignature("thisMethodIsNotAvailable()"));
require(status == false);
vm.stopPrank();
}
Expand Down Expand Up @@ -146,13 +146,8 @@ contract ExecutionLayerFeeDispatcherTest {
assert(address(0).balance == 0);
vm.expectEmit(true, true, true, true);
emit Withdrawal(
address(0),
operator,
bytes32(keccak256(bytes("another public key"))),
0.9 ether,
0.02 ether,
0.08 ether
);
address(0), operator, bytes32(keccak256(bytes("another public key"))), 0.9 ether, 0.02 ether, 0.08 ether
);
eld.dispatch{value: 1 ether}(bytes32(keccak256(bytes("another public key"))));
assert(bob.balance == 0);
assert(operator.balance == 0.02 ether);
Expand Down
4 changes: 2 additions & 2 deletions src/test/FeeRecipient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract FeeRecipientTest {
address receiver = uint256(_publicKeyRoot) % 2 == 0 ? bob : alice;

vm.deal(address(this), _amount);
(bool status, ) = address(feeRecipient).call{value: _amount}("");
(bool status,) = address(feeRecipient).call{value: _amount}("");
assert(status == true);

assert(receiver.balance == 0);
Expand All @@ -93,7 +93,7 @@ contract FeeRecipientTest {
address receiver = uint256(_publicKeyRoot) % 2 == 0 ? bob : alice;

vm.deal(address(this), _amount);
(bool status, ) = address(feeRecipient).call{value: _amount}(abi.encodeWithSignature("pay()"));
(bool status,) = address(feeRecipient).call{value: _amount}(abi.encodeWithSignature("pay()"));
assert(status == true);

assert(receiver.balance == 0);
Expand Down
Loading

0 comments on commit 2ef85ce

Please sign in to comment.