Skip to content

Commit

Permalink
Allowance check added
Browse files Browse the repository at this point in the history
  • Loading branch information
advock committed Apr 20, 2023
1 parent 2001af4 commit 203a651
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/mixins/ERC4626.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ abstract contract ERC4626 is ERC20 {

ERC20 public immutable asset;

constructor(
ERC20 _asset,
string memory _name,
string memory _symbol
) ERC20(_name, _symbol, _asset.decimals()) {
constructor(ERC20 _asset, string memory _name, string memory _symbol) ERC20(_name, _symbol, _asset.decimals()) {
asset = _asset;
}

Expand Down Expand Up @@ -70,17 +66,16 @@ abstract contract ERC4626 is ERC20 {
afterDeposit(assets, shares);
}

function withdraw(
uint256 assets,
address receiver,
address owner
) public virtual returns (uint256 shares) {
function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256 shares) {
shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up.

if (msg.sender != owner) {
uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.

if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares;
if (allowed != type(uint256).max) {
require(assets <= allowance[owner][msg.sender], "amount to be withdraw is more than allowed");

This comment has been minimized.

Copy link
@advock

advock Apr 20, 2023

Author

check for amount is less than or equal to the allowed amount

allowance[owner][msg.sender] = allowed - shares;
}
}

beforeWithdraw(assets, shares);
Expand All @@ -92,11 +87,7 @@ abstract contract ERC4626 is ERC20 {
asset.safeTransfer(receiver, assets);
}

function redeem(
uint256 shares,
address receiver,
address owner
) public virtual returns (uint256 assets) {
function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256 assets) {
if (msg.sender != owner) {
uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.

Expand Down

1 comment on commit 203a651

@advock
Copy link
Author

@advock advock commented on 203a651 Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowance check is added. This is based on issue 362

Please sign in to comment.