Skip to content

Commit

Permalink
patch: removed ObolRocketPoolStorage references
Browse files Browse the repository at this point in the history
  • Loading branch information
cosminobol committed Aug 10, 2024
1 parent 467b37e commit a817edf
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 195 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/external/rocketPool/IRocketPoolStorage.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

// address internal constant RP_DEPOSIT = 0xDD3f50F8A6CafbE9b31a427582963f465E745AF8;
// address internal constant RP_STORAGE = 0x1d8f8f00cfa6758d7bE78336684788Fb0ee0Fa46;
interface IRocketPoolStorage {
function getAddress(bytes32 _key) external view returns (address r);
function getUint(bytes32 _key) external view returns (uint256 r);
Expand Down
35 changes: 16 additions & 19 deletions src/rocket-pool/ObolRocketPoolRecipient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {Clone} from "solady/utils/Clone.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";

import {ObolRocketPoolStorage} from "./ObolRocketPoolStorage.sol";
import {IRocketPoolMinipoolManager} from "../interfaces/external/rocketPool/IRocketPoolMinipoolManager.sol";
import {IRocketMinipoolDelegate} from "../interfaces/external/rocketPool/IRocketMinipoolDelegate.sol";
import {IRocketMinipoolBase} from "../interfaces/external/rocketPool/IRocketMinipoolBase.sol";
Expand All @@ -31,7 +30,7 @@ contract ObolRocketPoolRecipient is Clone {
error InvalidTokenRecovery_InvalidRecipient();

/// Invalid minipool
error InvalidMinipool_Address();
error Invalid_Address();

/// Invalid distribution
error InvalidDistribution_TooLarge();
Expand Down Expand Up @@ -60,6 +59,7 @@ contract ObolRocketPoolRecipient is Clone {
/// -----------------------------------------------------------------------
/// storage
/// -----------------------------------------------------------------------
IRocketPoolStorage public immutable rpStorage;

/// -----------------------------------------------------------------------
/// storage - constants
Expand All @@ -85,19 +85,13 @@ contract ObolRocketPoolRecipient is Clone {
/// storage - cwia offsets
/// -----------------------------------------------------------------------

uint256 internal constant STORAGE_ADDRESS_OFFSET = 0;

// token (address, 20 bytes), recoveryAddress (address, 20 bytes),
// recoveryAddress (address, 20 bytes),
// tranches (uint256[], numTranches * 32 bytes)

uint256 internal constant RECOVERY_ADDRESS_OFFSET = 20;
// 20 = recoveryAddress_offset (0) + recoveryAddress_size (address, 20
uint256 internal constant RECOVERY_ADDRESS_OFFSET = 0;
// 0 = recoveryAddress_offset (0) + recoveryAddress_size (address, 20
// bytes)
uint256 internal constant TRANCHES_OFFSET = 40;

function rpStorage() public pure returns (address) {
return _getArgAddress(STORAGE_ADDRESS_OFFSET);
}
uint256 internal constant TRANCHES_OFFSET = 20;

/// Address to recover non-OWR tokens to
/// @dev equivalent to address public immutable recoveryAddress;
Expand Down Expand Up @@ -136,7 +130,10 @@ contract ObolRocketPoolRecipient is Clone {

// solhint-disable-next-line no-empty-blocks
/// clone implementation doesn't use constructor
constructor() {}
constructor(address _rpStorage) {
if (_rpStorage == address(0)) revert Invalid_Address();
rpStorage = IRocketPoolStorage(_rpStorage);
}

/// -----------------------------------------------------------------------
/// functions
Expand All @@ -163,9 +160,9 @@ contract ObolRocketPoolRecipient is Clone {
}

function viewRewards(address _miniPool) public view returns (uint256) {
IRocketPoolStorage _rpStorage = IRocketPoolStorage(rpStorage());
address miniPoolManager = _rpStorage.getAddress(keccak256(abi.encodePacked("contract.address", STORAGE_MINIPOOL_MANAGER)));
if (!IRocketPoolMinipoolManager(miniPoolManager).getMinipoolExists(_miniPool)) revert InvalidMinipool_Address();
address miniPoolManager =
rpStorage.getAddress(keccak256(abi.encodePacked("contract.address", STORAGE_MINIPOOL_MANAGER)));
if (!IRocketPoolMinipoolManager(miniPoolManager).getMinipoolExists(_miniPool)) revert Invalid_Address();

uint256 nodeRefundBalance = IRocketMinipoolDelegate(_miniPool).getNodeRefundBalance();
uint256 balance = _miniPool.balance;
Expand Down Expand Up @@ -259,9 +256,9 @@ contract ObolRocketPoolRecipient is Clone {

function _distributeFunds(address _miniPool, bool _rewards, uint256 pullFlowFlag) internal {
{
IRocketPoolStorage _rpStorage = IRocketPoolStorage(rpStorage());
address miniPoolManager = _rpStorage.getAddress(keccak256(abi.encodePacked("contract.address", STORAGE_MINIPOOL_MANAGER)));
if (!IRocketPoolMinipoolManager(miniPoolManager).getMinipoolExists(_miniPool)) revert InvalidMinipool_Address();
address miniPoolManager =
rpStorage.getAddress(keccak256(abi.encodePacked("contract.address", STORAGE_MINIPOOL_MANAGER)));
if (!IRocketPoolMinipoolManager(miniPoolManager).getMinipoolExists(_miniPool)) revert Invalid_Address();
}

IRocketMinipoolDelegate(_miniPool).distributeBalance(_rewards);
Expand Down
14 changes: 7 additions & 7 deletions src/rocket-pool/ObolRocketPoolRecipientFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract ObolRocketPoolRecipientFactory {
error Invalid__ThresholdTooLarge(uint256 threshold);

/// Invalid address
error InvalidAddress();
error Invalid__Address();

/// -----------------------------------------------------------------------
/// events
Expand Down Expand Up @@ -55,14 +55,14 @@ contract ObolRocketPoolRecipientFactory {
/// ObolRocketPoolRecipient implementation address
ObolRocketPoolRecipient public immutable rpRecipientImplementation;

address public immutable obolRpStorage;
address public immutable rpStorage;

constructor(address _rpStorage, string memory _ensName, address _ensReverseRegistrar, address _ensOwner) {
if (_rpStorage == address(0)) revert InvalidAddress();
if (_rpStorage == address(0)) revert Invalid__Address();

obolRpStorage = _rpStorage;
rpStorage = _rpStorage;

rpRecipientImplementation = new ObolRocketPoolRecipient();
rpRecipientImplementation = new ObolRocketPoolRecipient(_rpStorage);
IENSReverseRegistrar(_ensReverseRegistrar).setName(_ensName);
IENSReverseRegistrar(_ensReverseRegistrar).claim(_ensOwner);
}
Expand Down Expand Up @@ -95,12 +95,12 @@ contract ObolRocketPoolRecipientFactory {

// would not exceed contract size limits
// important to not reorder
bytes memory data = abi.encodePacked(obolRpStorage, recoveryAddress, principalData, rewardData);
bytes memory data = abi.encodePacked(recoveryAddress, principalData, rewardData);

rpRecipient = ObolRocketPoolRecipient(address(rpRecipientImplementation).clone(data));

emit CreateObolRocketPoolRecipient(
address(rpRecipient), obolRpStorage, recoveryAddress, principalRecipient, rewardRecipient, amountOfPrincipalStake
address(rpRecipient), rpStorage, recoveryAddress, principalRecipient, rewardRecipient, amountOfPrincipalStake
);
}
}
80 changes: 0 additions & 80 deletions src/rocket-pool/ObolRocketPoolStorage.sol

This file was deleted.

1 change: 0 additions & 1 deletion src/test/rocket-pool/ObolRocketPoolRecipient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import {ObolRocketPoolRecipientFactory} from "src/rocket-pool/ObolRocketPoolRecipientFactory.sol";
import {ObolRocketPoolRecipient} from "src/rocket-pool/ObolRocketPoolRecipient.sol";
import {ObolRocketPoolStorage} from "src/rocket-pool/ObolRocketPoolStorage.sol";
import {RocketPoolTestHelper} from "./RocketPoolTestHelper.t.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {MockERC20} from "../utils/mocks/MockERC20.sol";
Expand Down
7 changes: 3 additions & 4 deletions src/test/rocket-pool/ObolRocketPoolRecipientFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity ^0.8.19;

import "forge-std/Test.sol";
import {ObolRocketPoolStorage} from "src/rocket-pool/ObolRocketPoolStorage.sol";
import {ObolRocketPoolRecipientFactory} from "src/rocket-pool/ObolRocketPoolRecipientFactory.sol";
import {MockERC20} from "../utils/mocks/MockERC20.sol";
import {IENSReverseRegistrar} from "../../interfaces/IENSReverseRegistrar.sol";
import {RocketPoolTestHelper} from "./RocketPoolTestHelper.t.sol";
import {RPStorageMock} from "./mocks/RPStorageMock.sol";

contract ObolRocketPoolRecipientFactoryTest is RocketPoolTestHelper, Test {
event CreateObolRocketPoolRecipient(
Expand All @@ -21,8 +21,8 @@ contract ObolRocketPoolRecipientFactoryTest is RocketPoolTestHelper, Test {
address public ENS_REVERSE_REGISTRAR_GOERLI = 0x084b1c3C81545d370f3634392De611CaaBFf8148;

ObolRocketPoolRecipientFactory rpRecipientFactoryModule;
ObolRocketPoolStorage rpStorage;
MockERC20 mERC20;
RPStorageMock rpStorage;
address public recoveryAddress;
address public principalRecipient;
address public rewardRecipient;
Expand All @@ -32,8 +32,6 @@ contract ObolRocketPoolRecipientFactoryTest is RocketPoolTestHelper, Test {
mERC20 = new MockERC20("Test Token", "TOK", 18);
mERC20.mint(type(uint256).max);

rpStorage = new ObolRocketPoolStorage();

vm.mockCall(
ENS_REVERSE_REGISTRAR_GOERLI,
abi.encodeWithSelector(IENSReverseRegistrar.setName.selector),
Expand All @@ -45,6 +43,7 @@ contract ObolRocketPoolRecipientFactoryTest is RocketPoolTestHelper, Test {
bytes.concat(bytes32(0))
);

rpStorage = new RPStorageMock();
rpRecipientFactoryModule = new ObolRocketPoolRecipientFactory(
address(rpStorage), "demo.obol.eth", ENS_REVERSE_REGISTRAR_GOERLI, address(this)
);
Expand Down
75 changes: 0 additions & 75 deletions src/test/rocket-pool/ObolRocketPoolStorage.t.sol

This file was deleted.

Loading

0 comments on commit a817edf

Please sign in to comment.