Skip to content

Commit

Permalink
Merge pull request #15 from GenerationSoftware/gen-292-c4-issue-384
Browse files Browse the repository at this point in the history
fix(permit): remove mintWithPermit
  • Loading branch information
asselstine authored Aug 15, 2023
2 parents 22d87f3 + c068705 commit 797b633
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 134 deletions.
26 changes: 0 additions & 26 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -507,32 +507,6 @@ contract Vault is ERC4626, ERC20Permit, ILiquidationSource, Ownable {
return _assets;
}

/**
* @notice Approve underlying asset with permit, deposit into the Vault and mint Vault shares to `_receiver`.
* @param _shares Amount of shares to mint to `_receiver`
* @param _receiver Address of the receiver of the vault shares
* @param _deadline Timestamp after which the approval is no longer valid
* @param _v V part of the secp256k1 signature
* @param _r R part of the secp256k1 signature
* @param _s S part of the secp256k1 signature
* @return uint256 Amount of assets deposited into the Vault.
*/
function mintWithPermit(
uint256 _shares,
address _receiver,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
) external returns (uint256) {
uint256 _assets = _convertToAssets(_shares, Math.Rounding.Up);

_permit(IERC20Permit(asset()), msg.sender, address(this), _assets, _deadline, _v, _r, _s);
_deposit(msg.sender, _receiver, _assets, _shares);

return _assets;
}

/**
* @notice Deposit assets into the Vault and delegate to the sponsorship address.
* @param _assets Amount of assets to deposit
Expand Down
24 changes: 0 additions & 24 deletions test/unit/Vault/Deposit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,6 @@ Feature: Deposit
Then the YieldVault must mint to the Vault an amount of shares equivalent to the amount of underlying assets deposited
Then the Vault `totalSupply` must be equal to 1,000

# Mint with permit
Scenario: Alice mints with permit from the Vault
Given Alice owns 0 Vault shares
When Alice signs her transaction and mints 1,000 underlying assets
Then Alice must receive the amount of Vault shares requested
Then Alice `balance` must be equal to 1,000
Then Alice `delegateBalance` must be equal to 1,000
Then the YieldVault balance of underlying assets must increase by 1,000
Then the YieldVault must mint to the Vault an amount of shares equivalent to the amount of underlying assets deposited
Then the Vault `totalSupply` must be equal to 1,000

Scenario: Alice mints with permit from the Vault on behalf of Bob
Given Alice owns 0 Vault shares and Bob owns 0 Vault shares
When Alice signs her transaction and mints 1,000 shares
Then Bob must receive 1,000 Vault shares
Then Alice must not receive any Vault shares
Then Alice `balance` must be equal to 0
Then Alice `delegateBalance` must be equal to 0
Then Bob `balance` must be equal to 1,000
Then Bob `delegateBalance` must be equal to 1,000
Then the YieldVault balance of underlying assets must increase by 1,000
Then the YieldVault must mint to the Vault an amount of shares equivalent to the amount of underlying assets deposited
Then the Vault `totalSupply` must be equal to 1,000

# Mint - Errors
Scenario: Alice mints shares from the Vault
Given Alice owns 0 Vault shares
Expand Down
56 changes: 0 additions & 56 deletions test/unit/Vault/Deposit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -353,62 +353,6 @@ contract VaultDepositTest is UnitBaseSetup, BrokenToken {
vm.stopPrank();
}

function testMintWithPermit() external {
vm.startPrank(alice);

uint256 _amount = 1000e18;
underlyingAsset.mint(alice, _amount);

vm.expectEmit();
emit Transfer(address(0), alice, _amount);

vm.expectEmit();
emit Deposit(alice, alice, _amount, _amount);

_mintWithPermit(underlyingAsset, vault, _amount, alice, alice, alicePrivateKey);

assertEq(vault.balanceOf(alice), _amount);

assertEq(twabController.balanceOf(address(vault), alice), _amount);
assertEq(twabController.delegateBalanceOf(address(vault), alice), _amount);

assertEq(underlyingAsset.balanceOf(address(yieldVault)), _amount);
assertEq(yieldVault.balanceOf(address(vault)), _amount);
assertEq(yieldVault.totalSupply(), _amount);

vm.stopPrank();
}

function testMintWithPermitOnBehalf() external {
vm.startPrank(alice);

uint256 _amount = 1000e18;
underlyingAsset.mint(alice, _amount);

vm.expectEmit();
emit Transfer(address(0), bob, _amount);

vm.expectEmit();
emit Deposit(alice, bob, _amount, _amount);

_mintWithPermit(underlyingAsset, vault, _amount, bob, alice, alicePrivateKey);

assertEq(vault.balanceOf(alice), 0);
assertEq(vault.balanceOf(bob), _amount);

assertEq(twabController.balanceOf(address(vault), alice), 0);
assertEq(twabController.delegateBalanceOf(address(vault), alice), 0);

assertEq(twabController.balanceOf(address(vault), bob), _amount);
assertEq(twabController.delegateBalanceOf(address(vault), bob), _amount);

assertEq(underlyingAsset.balanceOf(address(yieldVault)), _amount);
assertEq(yieldVault.balanceOf(address(vault)), _amount);
assertEq(yieldVault.totalSupply(), _amount);

vm.stopPrank();
}

/* ============ Mint - Errors ============ */
function testMintMoreThanMax() external {
vm.startPrank(alice);
Expand Down
28 changes: 0 additions & 28 deletions test/utils/Helpers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,6 @@ contract Helpers is Test {
return _vault.mint(_shares, _user);
}

function _mintWithPermit(
IERC20Permit _underlyingAsset,
Vault _vault,
uint256 _shares,
address _user,
address _owner,
uint256 _ownerPrivateKey
) internal returns (uint256) {
uint256 _nonce = _underlyingAsset.nonces(_owner);
uint256 _assets = _vault.convertToAssets(_shares);
address _vaultAddress = address(_vault);

(uint8 _v, bytes32 _r, bytes32 _s) = vm.sign(
_ownerPrivateKey,
keccak256(
abi.encodePacked(
"\x19\x01",
_underlyingAsset.DOMAIN_SEPARATOR(),
keccak256(
abi.encode(_PERMIT_TYPEHASH, _owner, _vaultAddress, _assets, _nonce, block.timestamp)
)
)
)
);

return _vault.mintWithPermit(_shares, _user, block.timestamp, _v, _r, _s);
}

/* ============ Sponsor ============ */
function _sponsor(
IERC20 _underlyingAsset,
Expand Down

0 comments on commit 797b633

Please sign in to comment.