Skip to content

Commit

Permalink
rename to PooledDepositsVault
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Apr 12, 2024
1 parent 610fa1a commit f77f43d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 54 deletions.
13 changes: 6 additions & 7 deletions script/DeployPooledDepositsVaults.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

// SPDX-License-Identifier: BSD 3-Clause License
pragma solidity ^0.8.24;

import {TransparentUpgradeableProxy} from "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin} from "lib/openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {BaseScript} from "script/BaseScript.s.sol";
import {PooledDeposits} from "src/PooledDeposits.sol";
import {PooledDepositsVault} from "src/PooledDepositsVault.sol"; // Renamed from PooledDeposits to PooledDepositsVault
import {ActorAddresses} from "script/Actors.sol";
import {console} from "lib/forge-std/src/console.sol";

Expand All @@ -18,21 +17,21 @@ contract Upgrade is BaseScript {
// ynETH.sol ROLES
ActorAddresses.Actors memory actors = getActors();

PooledDeposits[] memory pooledDepositsVaults = new PooledDeposits[](5);
PooledDepositsVault[] memory pooledDepositsVaults = new PooledDepositsVault[](5); // Renamed from PooledDeposits to PooledDepositsVault
vm.startBroadcast(deployerPrivateKey);

PooledDeposits pooledDepositsVaultImplementation = new PooledDeposits();
PooledDepositsVault pooledDepositsVaultImplementation = new PooledDepositsVault(); // Renamed from PooledDeposits to PooledDepositsVault
for (uint i = 0; i < 5; i++) {
bytes memory initData = abi.encodeWithSelector(PooledDeposits.initialize.selector, actors.POOLED_DEPOSITS_OWNER);
bytes memory initData = abi.encodeWithSelector(PooledDepositsVault.initialize.selector, actors.POOLED_DEPOSITS_OWNER); // Renamed from PooledDeposits to PooledDepositsVault
TransparentUpgradeableProxy pooledDepositsVaultProxy = new TransparentUpgradeableProxy(address(pooledDepositsVaultImplementation), actors.PROXY_ADMIN_OWNER, initData);
PooledDeposits pooledDepositsVault = PooledDeposits(payable(address(pooledDepositsVaultProxy)));
PooledDepositsVault pooledDepositsVault = PooledDepositsVault(payable(address(pooledDepositsVaultProxy))); // Renamed from PooledDeposits to PooledDepositsVault
pooledDepositsVaults[i] = pooledDepositsVault;
}
savePooledDepositsDeployment(pooledDepositsVaults);
vm.stopBroadcast();
}

function savePooledDepositsDeployment(PooledDeposits[] memory pooledDepositsVaults) internal {
function savePooledDepositsDeployment(PooledDepositsVault[] memory pooledDepositsVaults) internal { // Renamed from PooledDeposits to PooledDepositsVault
string memory json = "pooledDepositsVaultsDeployment";
for (uint i = 0; i < pooledDepositsVaults.length; i++) {
vm.serializeAddress(json, vm.toString(i), address(pooledDepositsVaults[i]));
Expand Down
2 changes: 1 addition & 1 deletion src/PooledDeposits.sol → src/PooledDepositsVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "./interfaces/IynETH.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract PooledDeposits is Initializable, OwnableUpgradeable {
contract PooledDepositsVault is Initializable, OwnableUpgradeable {

error DepositMustBeGreaterThanZero();
error YnETHIsSet();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
pragma solidity ^0.8.24;

import "forge-std/Test.sol";
import "../../src/PooledDeposits.sol";
import "../../src/PooledDepositsVault.sol";
import "../../src/interfaces/IynETH.sol";
import "test/integration/IntegrationBaseTest.sol";

contract PooledDepositsTest is IntegrationBaseTest {
contract PooledDepositsVaultTest is IntegrationBaseTest {

function createPooledDeposits() internal returns (PooledDeposits pooledDeposits, address owner) {
PooledDeposits implementation = new PooledDeposits();
bytes memory initData = abi.encodeWithSelector(PooledDeposits.initialize.selector, address(this));
function createPooledDeposits() internal returns (PooledDepositsVault pooledDepositsVault, address owner) {
PooledDepositsVault implementation = new PooledDepositsVault();
bytes memory initData = abi.encodeWithSelector(PooledDepositsVault.initialize.selector, address(this));
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(address(implementation), address(this), initData);
pooledDeposits = PooledDeposits(payable(address(proxy)));
pooledDepositsVault = PooledDepositsVault(payable(address(proxy)));
owner = address(this);
return (pooledDeposits, owner);
return (pooledDepositsVault, owner);
}

function testDepositFuzz(uint256 depositAmount) public {
// Fuzz input
vm.assume(depositAmount > 0.01 ether && depositAmount <= 100 ether); // Assuming a reasonable range for deposit amounts
// Arrange
(PooledDeposits pooledDeposits, ) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, ) = createPooledDeposits();
address depositor = address(this);

// Act
vm.deal(depositor, depositAmount);
vm.startPrank(depositor);
pooledDeposits.deposit{value: depositAmount}();
pooledDepositsVault.deposit{value: depositAmount}();
vm.stopPrank();

// Assert
assertEq(pooledDeposits.balances(depositor), depositAmount, "Deposit amount should be recorded in the depositor's balance");
assertEq(pooledDepositsVault.balances(depositor), depositAmount, "Deposit amount should be recorded in the depositor's balance");
}
function testMultipleSequentialDepositsForSameUserFuzz(uint256 depositAmount1) public {
// Fuzz inputs
vm.assume(depositAmount1 > 0.01 ether && depositAmount1 <= 100 ether); // Assuming a reasonable range for the first deposit amount
uint256 depositAmount2 = depositAmount1 + 100 ether;

// Arrange
(PooledDeposits pooledDeposits, ) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, ) = createPooledDeposits();
address depositor = address(this);
uint256 expectedBalanceAfterFirstDeposit = depositAmount1;
uint256 expectedBalanceAfterSecondDeposit = depositAmount1 + depositAmount2;

// Act and Assert
vm.deal(depositor, expectedBalanceAfterSecondDeposit);
vm.startPrank(depositor);
pooledDeposits.deposit{value: depositAmount1}();
assertEq(pooledDeposits.balances(depositor), expectedBalanceAfterFirstDeposit, "Balance after first deposit incorrect");
pooledDeposits.deposit{value: depositAmount2}();
assertEq(pooledDeposits.balances(depositor), expectedBalanceAfterSecondDeposit, "Balance after second deposit incorrect");
pooledDepositsVault.deposit{value: depositAmount1}();
assertEq(pooledDepositsVault.balances(depositor), expectedBalanceAfterFirstDeposit, "Balance after first deposit incorrect");
pooledDepositsVault.deposit{value: depositAmount2}();
assertEq(pooledDepositsVault.balances(depositor), expectedBalanceAfterSecondDeposit, "Balance after second deposit incorrect");
vm.stopPrank();
}

function testFinalizeDeposits() public {
// Arrange
(PooledDeposits pooledDeposits, address owner) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, address owner) = createPooledDeposits();
address[] memory depositors = new address[](1);
depositors[0] = address(this);
uint256 depositAmount = 1 ether;
vm.deal(address(this), depositAmount);
pooledDeposits.deposit{value: depositAmount}();
pooledDepositsVault.deposit{value: depositAmount}();

// Set ynETH before finalizing deposits
vm.prank(owner);
pooledDeposits.setYnETH(IynETH(address(yneth)));
pooledDepositsVault.setYnETH(IynETH(address(yneth)));

// Act
vm.warp(block.timestamp + 3 days); // Move time forward to allow finalizing deposits
pooledDeposits.finalizeDeposits(depositors);
pooledDepositsVault.finalizeDeposits(depositors);

// Assert
// Assuming ynETH's depositETH function simply mints 1:1 ynETH for ETH deposited
Expand All @@ -82,7 +82,7 @@ contract PooledDepositsTest is IntegrationBaseTest {
vm.assume(baseDepositAmount > 0.01 ether && baseDepositAmount <= 100 ether); // Assuming a reasonable range for deposit amounts

// Arrange
(PooledDeposits pooledDeposits, address owner) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, address owner) = createPooledDeposits();
address[] memory depositors = new address[](depositorsCount);
uint256 totalDepositAmount = 0;
uint256 varyingDepositAmount = baseDepositAmount;
Expand All @@ -92,18 +92,18 @@ contract PooledDepositsTest is IntegrationBaseTest {
depositors[i] = depositor;
vm.deal(depositor, varyingDepositAmount);
vm.prank(depositor);
pooledDeposits.deposit{value: varyingDepositAmount}();
pooledDepositsVault.deposit{value: varyingDepositAmount}();
totalDepositAmount += varyingDepositAmount;
varyingDepositAmount += 1 ether; // Increase the deposit amount by 1 ether for each depositor
}

// Set ynETH before finalizing deposits
vm.prank(owner);
pooledDeposits.setYnETH(IynETH(address(yneth)));
pooledDepositsVault.setYnETH(IynETH(address(yneth)));

// Act
vm.warp(block.timestamp + 3 days); // Move time forward to allow finalizing deposits
pooledDeposits.finalizeDeposits(depositors);
pooledDepositsVault.finalizeDeposits(depositors);

// Assert
// Assuming ynETH's depositETH function simply mints 1:1 ynETH for ETH deposited
Expand All @@ -117,49 +117,49 @@ contract PooledDepositsTest is IntegrationBaseTest {

function testDepositAfterSettingYnETH() public {
// Arrange
(PooledDeposits pooledDeposits, address owner) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, address owner) = createPooledDeposits();
uint256 depositAmount = 1 ether;
vm.deal(address(this), depositAmount);

// Set ynETH before finalizing deposits
vm.prank(owner);
pooledDeposits.setYnETH(IynETH(address(yneth)));
pooledDepositsVault.setYnETH(IynETH(address(yneth)));

// Act & Assert
vm.expectRevert(PooledDeposits.YnETHIsSet.selector);
pooledDeposits.deposit{value: depositAmount}();
vm.expectRevert(PooledDepositsVault.YnETHIsSet.selector);
pooledDepositsVault.deposit{value: depositAmount}();
}

function testFinalizeDepositsBeforeSettingYnETH() public {
// Arrange
(PooledDeposits pooledDeposits,) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault,) = createPooledDeposits();
address[] memory depositors = new address[](1);
depositors[0] = address(this);

// Act & Assert
vm.expectRevert(PooledDeposits.YnETHNotSet.selector);
pooledDeposits.finalizeDeposits(depositors);
vm.expectRevert(PooledDepositsVault.YnETHNotSet.selector);
pooledDepositsVault.finalizeDeposits(depositors);
}

function testDepositZeroAmount() public {
// Arrange
(PooledDeposits pooledDeposits,) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault,) = createPooledDeposits();

// Act & Assert
vm.expectRevert(PooledDeposits.DepositMustBeGreaterThanZero.selector);
pooledDeposits.deposit{value: 0}();
vm.expectRevert(PooledDepositsVault.DepositMustBeGreaterThanZero.selector);
pooledDepositsVault.deposit{value: 0}();
}

function testFinalizeDepositsWithNoDepositors() public {
// Arrange
(PooledDeposits pooledDeposits, address owner) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, address owner) = createPooledDeposits();
address[] memory depositors = new address[](0);

// Set ynETH before finalizing deposits
vm.prank(owner);
pooledDeposits.setYnETH(IynETH(address(yneth)));
pooledDepositsVault.setYnETH(IynETH(address(yneth)));

pooledDeposits.finalizeDeposits(depositors);
pooledDepositsVault.finalizeDeposits(depositors);

// Assert
// No revert means success, but nothing to assert as there were no depositors
Expand All @@ -170,51 +170,51 @@ contract PooledDepositsTest is IntegrationBaseTest {
vm.assume(depositAmount > 0 && depositAmount <= 100 ether);

// Arrange
(PooledDeposits pooledDeposits,) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault,) = createPooledDeposits();
vm.deal(address(this), depositAmount);

// Act
(bool success, ) = address(pooledDeposits).call{value: depositAmount}("");
(bool success, ) = address(pooledDepositsVault).call{value: depositAmount}("");

// Assert
assertTrue(success, "ETH send should succeed");
assertEq(pooledDeposits.balances(address(this)), depositAmount, "Deposit amount should be recorded in balances");
assertEq(pooledDepositsVault.balances(address(this)), depositAmount, "Deposit amount should be recorded in balances");
}

function testFinalizeDepositsMultipleTimesForSameUser() public {
// Arrange
(PooledDeposits pooledDeposits, address owner) = createPooledDeposits();
(PooledDepositsVault pooledDepositsVault, address owner) = createPooledDeposits();
address[] memory depositors = new address[](1);
depositors[0] = address(this);
uint256 depositAmount = 1 ether;
vm.deal(address(this), depositAmount);
pooledDeposits.deposit{value: depositAmount}();
pooledDepositsVault.deposit{value: depositAmount}();

// Set ynETH before finalizing deposits
vm.prank(owner);
pooledDeposits.setYnETH(IynETH(address(yneth)));
pooledDepositsVault.setYnETH(IynETH(address(yneth)));

// Act
vm.warp(block.timestamp + 1 days + 1); // Move time forward to allow finalizing deposits
pooledDeposits.finalizeDeposits(depositors);
pooledDepositsVault.finalizeDeposits(depositors);

// Assert first finalize
uint256 sharesAfterFirstFinalize = IynETH(address(yneth)).balanceOf(address(this));
assertTrue(sharesAfterFirstFinalize > 0, "Shares should be allocated after first finalize");

// Check balance after first finalize
uint256 balanceAfterFirstFinalize = pooledDeposits.balances(address(this));
uint256 balanceAfterFirstFinalize = pooledDepositsVault.balances(address(this));
assertEq(balanceAfterFirstFinalize, 0, "Balance should be 0 after first finalize");

// Attempt to finalize again
pooledDeposits.finalizeDeposits(depositors);
pooledDepositsVault.finalizeDeposits(depositors);

// Assert second finalize
uint256 sharesAfterSecondFinalize = IynETH(address(yneth)).balanceOf(address(this));
assertEq(sharesAfterFirstFinalize, sharesAfterSecondFinalize, "Shares should not change after second finalize");

// Check balance after second finalize
uint256 balanceAfterSecondFinalize = pooledDeposits.balances(address(this));
uint256 balanceAfterSecondFinalize = pooledDepositsVault.balances(address(this));
assertEq(balanceAfterSecondFinalize, 0, "Balance should remain 0 after second finalize");
}

Expand Down

0 comments on commit f77f43d

Please sign in to comment.