Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/test/CREATE3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ contract CREATE3Test is DSTestPlus {
bytes32 salt = keccak256(bytes("A salt!"));
Factory factory = new Factory();

MockERC20 deployed = MockERC20(
factory.deploy(salt)
);

MockERC20 deployed = MockERC20(factory.deploy(salt));

assertEq(address(deployed), CREATE3.getDeployed(salt, address(factory)));
assertTrue(address(deployed) != CREATE3.getDeployed(salt));

Expand Down
12 changes: 12 additions & 0 deletions src/tokens/ERC4626.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ abstract contract ERC4626 is ERC20 {
// Check for rounding error since we round down in previewDeposit.
require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

beforeDeposit(assets, shares);

// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), assets);

Expand All @@ -60,6 +62,8 @@ abstract contract ERC4626 is ERC20 {
function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) {
assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.

beforeDeposit(assets, shares);

// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), assets);

Expand Down Expand Up @@ -90,6 +94,8 @@ abstract contract ERC4626 is ERC20 {
emit Withdraw(msg.sender, receiver, owner, assets, shares);

asset.safeTransfer(receiver, assets);

afterWithdraw(assets, shares);
}

function redeem(
Expand All @@ -113,6 +119,8 @@ abstract contract ERC4626 is ERC20 {
emit Withdraw(msg.sender, receiver, owner, assets, shares);

asset.safeTransfer(receiver, assets);

afterWithdraw(assets, shares);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -177,7 +185,11 @@ abstract contract ERC4626 is ERC20 {
INTERNAL HOOKS LOGIC
//////////////////////////////////////////////////////////////*/

function beforeDeposit(uint256 assets, uint256 shares) internal virtual {}

function beforeWithdraw(uint256 assets, uint256 shares) internal virtual {}

function afterDeposit(uint256 assets, uint256 shares) internal virtual {}

function afterWithdraw(uint256 assets, uint256 shares) internal virtual {}
}
6 changes: 3 additions & 3 deletions src/utils/SafeTransferLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ library SafeTransferLib {
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}

Expand Down Expand Up @@ -84,7 +84,7 @@ library SafeTransferLib {
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ library SafeTransferLib {
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data and token has code.
if and(iszero(and(eq(mload(0), 1), gt(returndatasize(), 31))), success) {
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
success := iszero(or(iszero(extcodesize(token)), returndatasize()))
}
}

Expand Down