Skip to content

Commit 203a651

Browse files
committed
Allowance check added
1 parent 2001af4 commit 203a651

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/mixins/ERC4626.sol

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ abstract contract ERC4626 is ERC20 {
3131

3232
ERC20 public immutable asset;
3333

34-
constructor(
35-
ERC20 _asset,
36-
string memory _name,
37-
string memory _symbol
38-
) ERC20(_name, _symbol, _asset.decimals()) {
34+
constructor(ERC20 _asset, string memory _name, string memory _symbol) ERC20(_name, _symbol, _asset.decimals()) {
3935
asset = _asset;
4036
}
4137

@@ -70,17 +66,16 @@ abstract contract ERC4626 is ERC20 {
7066
afterDeposit(assets, shares);
7167
}
7268

73-
function withdraw(
74-
uint256 assets,
75-
address receiver,
76-
address owner
77-
) public virtual returns (uint256 shares) {
69+
function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256 shares) {
7870
shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up.
7971

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

83-
if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares;
75+
if (allowed != type(uint256).max) {
76+
require(assets <= allowance[owner][msg.sender], "amount to be withdraw is more than allowed");
77+
allowance[owner][msg.sender] = allowed - shares;
78+
}
8479
}
8580

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

95-
function redeem(
96-
uint256 shares,
97-
address receiver,
98-
address owner
99-
) public virtual returns (uint256 assets) {
90+
function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256 assets) {
10091
if (msg.sender != owner) {
10192
uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals.
10293

0 commit comments

Comments
 (0)