Skip to content

Commit

Permalink
run forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xhad committed Oct 18, 2024
1 parent 03b43e4 commit e8d6877
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 68 deletions.
4 changes: 1 addition & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import "lib/forge-std/src/Script.sol";
import {VaultFactory} from "src/VaultFactory.sol";
import {IVaultFactory} from "src/interface/IVaultFactory.sol";
import {IActors, MainnetActors, HoleskyActors} from "script/Actors.sol";
import {MainnetContracts,HoleskyContracts} from "script/Contracts.sol";
import {MainnetContracts, HoleskyContracts} from "script/Contracts.sol";
import {SingleVault} from "src/SingleVault.sol";
import {TransparentUpgradeableProxy, TimelockController} from "src/Common.sol";

contract DeployVaultFactory is Script {

function run() public {

if (block.chainid == 17000) {
vm.startBroadcast();
HoleskyActors actors = new HoleskyActors();
Expand Down
36 changes: 9 additions & 27 deletions src/SingleVault.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.24;

import {
ERC4626Upgradeable,
AccessControlUpgradeable,
ReentrancyGuardUpgradeable,
IERC20,
Math
} from "src/Common.sol";
import {ERC4626Upgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable, IERC20, Math} from "src/Common.sol";

import {ISingleVault} from "src/interface/ISingleVault.sol";

/* ynETH Pre-Launch Vault */

contract SingleVault is ISingleVault,
ERC4626Upgradeable,
AccessControlUpgradeable,
ReentrancyGuardUpgradeable
{
contract SingleVault is ISingleVault, ERC4626Upgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable {
using Math for uint256;

constructor() {
_disableInitializers();
}

function initialize(
IERC20 asset_,
string memory name_,
string memory symbol_,
address admin_
) public initializer {
function initialize(IERC20 asset_, string memory name_, string memory symbol_, address admin_) public initializer {
_verifyParamsAreValid(asset_, name_, symbol_, admin_);
__ERC20_init(name_, symbol_);
__ERC4626_init(asset_);
Expand All @@ -38,20 +23,19 @@ contract SingleVault is ISingleVault,
_grantRole(DEFAULT_ADMIN_ROLE, admin_);
}

receive() external payable nonReentrant() {
receive() external payable nonReentrant {
if (msg.value > 0) {
_mintSharesForETH(msg.value);
}
}

fallback() external payable nonReentrant() {
fallback() external payable nonReentrant {
if (msg.value > 0) {
_mintSharesForETH(msg.value);
}
}

function _mintSharesForETH(uint256 amount) private {

IERC20 weth = _retrieveERC4626Storage()._asset;

(bool success,) = address(weth).call{value: amount}("");
Expand All @@ -62,12 +46,10 @@ contract SingleVault is ISingleVault,
}
}

function _verifyParamsAreValid(
IERC20 asset_,
string memory name_,
string memory symbol_,
address admin_
) internal pure {
function _verifyParamsAreValid(IERC20 asset_, string memory name_, string memory symbol_, address admin_)
internal
pure
{
if (asset_ == IERC20(address(0))) revert AssetZeroAddress();
if (bytes(name_).length == 0) revert NameEmpty();
if (bytes(symbol_).length == 0) revert SymbolEmpty();
Expand Down
20 changes: 10 additions & 10 deletions src/VaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ contract VaultFactory is IVaultFactory, AccessControlUpgradeable {
* @param admin The address of the administrator.
* @param timelock_ The Vault admin for proxy upgrades
*/
function initialize(address singleVaultImpl_, address admin, address timelock_, address weth_) external initializer {
function initialize(address singleVaultImpl_, address admin, address timelock_, address weth_)
external
initializer
{
_grantRole(DEFAULT_ADMIN_ROLE, admin);
// NOTES: There are two timelocks. This timelock is for vault upgrades but
// the vault is the second timelock controller, which has the same proposers and executors
Expand All @@ -50,20 +53,17 @@ contract VaultFactory is IVaultFactory, AccessControlUpgradeable {
* @param admin_ The address of the timelock.
* @return address The address of the newly created vault.
*/
function createSingleVault(
IERC20 asset_,
string memory name_,
string memory symbol_,
address admin_
) public onlyRole(DEFAULT_ADMIN_ROLE) returns (address) {
function createSingleVault(IERC20 asset_, string memory name_, string memory symbol_, address admin_)
public
onlyRole(DEFAULT_ADMIN_ROLE)
returns (address)
{
string memory funcSig = "initialize(address,string,string,address)";

if (address(asset_) != address(weth)) revert InvalidWethAddress();

TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
singleVaultImpl,
timelock,
abi.encodeWithSignature(funcSig, asset_, name_, symbol_, admin_)
singleVaultImpl, timelock, abi.encodeWithSignature(funcSig, asset_, name_, symbol_, admin_)
);

// bootstrap 1 ether of weth to prevent donation attacks
Expand Down
9 changes: 2 additions & 7 deletions src/interface/ISingleVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ interface ISingleVault is IERC20, IERC4626, IAccessControl {
error SymbolEmpty();
error AdminZeroAddress();
error DepositFailed();

function initialize(
IERC20 asset_,
string calldata name_,
string calldata symbol_,
address admin_
) external;

function initialize(IERC20 asset_, string calldata name_, string calldata symbol_, address admin_) external;
}
9 changes: 3 additions & 6 deletions src/interface/IVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ interface IVaultFactory is IAccessControl {

function initialize(address singleVaultImpl_, address admin, address timelock_, address weth_) external;

function createSingleVault(
IERC20 asset_,
string memory name_,
string memory symbol_,
address admin_
) external returns (address);
function createSingleVault(IERC20 asset_, string memory name_, string memory symbol_, address admin_)
external
returns (address);
}
1 change: 0 additions & 1 deletion test/factory/create.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contract CreateTest is Test, LocalActors, TestConstants {
Etches etches = new Etches();
etches.mockWETH9();


proposers = [PROPOSER_1];
executors = [EXECUTOR_1];

Expand Down
1 change: 0 additions & 1 deletion test/helpers/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {MainnetContracts} from "script/Contracts.sol";
import "forge-std/Test.sol";

contract AssetHelper is Test {

function get_weth(address user, uint256 amount) public {
IWETH weth = IWETH(payable(MainnetContracts.WETH));
deal(address(this), amount);
Expand Down
7 changes: 1 addition & 6 deletions test/helpers/Setup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ contract SetupHelper is Test, LocalActors, TestConstants {
IWETH(payable(MainnetContracts.WETH)).deposit{value: 1 ether}();
IERC20(MainnetContracts.WETH).transfer(address(factory), 1 ether);

address vaultAddress = factory.createSingleVault(
IERC20(MainnetContracts.WETH),
VAULT_NAME,
VAULT_SYMBOL,
ADMIN
);
address vaultAddress = factory.createSingleVault(IERC20(MainnetContracts.WETH), VAULT_NAME, VAULT_SYMBOL, ADMIN);
vault = SingleVault(payable(vaultAddress));
vm.stopPrank();
}
Expand Down
6 changes: 1 addition & 5 deletions test/single/unit/deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ contract DepositTest is Test, LocalActors, TestConstants {
assertEq(shares, previewAmount, "Shares should be equal to the amount deposited");
assertEq(vault.balanceOf(USER), shares, "Balance of the user should be updated");
assertEq(asset.balanceOf(address(vault)), amount + 1 ether, "Vault should have received the asset");
assertEq(
vault.totalAssets(),
amount + 1 ether,
"Vault totalAsset should be amount deposited"
);
assertEq(vault.totalAssets(), amount + 1 ether, "Vault totalAsset should be amount deposited");
assertEq(vault.totalSupply(), totalShares, "Vault totalSupply should be amount deposited");
}

Expand Down
2 changes: 1 addition & 1 deletion test/single/unit/invariants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.24;

import {SingleVault} from "src/SingleVault.sol";
import {WETH9} from "test/mocks/MockWETH.sol";
import {Math,IERC20} from "src/Common.sol";
import {Math, IERC20} from "src/Common.sol";
import {SetupHelper} from "test/helpers/Setup.sol";
import {Etches} from "test/helpers/Etches.sol";
import {TestConstants} from "test/helpers/Constants.sol";
Expand Down
2 changes: 1 addition & 1 deletion test/single/unit/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract WithdrawTest is Test, LocalActors, TestConstants {
address USER = address(33);
vm.startPrank(USER);
uint256 amount = 100 * 10 ** 18;
deal(USER,amount);
deal(USER, amount);
asset.deposit{value: amount}();
asset.approve(address(vault), amount);

Expand Down

0 comments on commit e8d6877

Please sign in to comment.