Skip to content

Commit

Permalink
Merge pull request #18 from euler-xyz/67-self-allowance
Browse files Browse the repository at this point in the history
Cantina 67: allow calls to set allowance for self
  • Loading branch information
dglowinski authored Jul 30, 2024
2 parents 5824544 + e8f5374 commit 6d8747e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/EVault/shared/BalanceUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ abstract contract BalanceUtils is Base {
// Allowance

function setAllowance(address owner, address spender, uint256 amount) internal {
if (spender == owner) revert E_SelfApproval();
if (spender == owner) return;

vaultStorage.users[owner].eTokenAllowance[spender] = amount;
emit Approval(owner, spender, amount);
Expand Down
1 change: 0 additions & 1 deletion src/EVault/shared/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pragma solidity ^0.8.0;
contract Errors {
error E_Initialized();
error E_ProxyMetadata();
error E_SelfApproval();
error E_SelfTransfer();
error E_InsufficientAllowance();
error E_InsufficientCash();
Expand Down
12 changes: 5 additions & 7 deletions test/unit/evault/modules/Token/actions.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ contract ERC20Test_Actions is EVaultTestBase {
}

function test_Approve_RevertsWhen_SelfApproval(uint256 allowance) public {
vm.expectRevert(Errors.E_SelfApproval.selector);
vm.prank(alice);
eTST.approve(alice, allowance);
// no-op
assertEq(eTST.allowance(alice, alice), 0);
}

function test_Approve_RevertsWhen_EVCOnBehalfOfAccountNotAuthenticated(uint256 allowance) public {
Expand All @@ -323,8 +324,7 @@ contract ERC20Test_Actions is EVaultTestBase {
assertEq(eTST.allowance(alice, alice), 0);

startHoax(alice);
// revert on self-approve of eVault
vm.expectRevert(Errors.E_SelfApproval.selector);
// no-op
eTST.approve(alice, 10);

assertEq(eTST.allowance(alice, alice), 0);
Expand All @@ -337,8 +337,7 @@ contract ERC20Test_Actions is EVaultTestBase {
assertEq(eTST.allowance(alice, alice), 0);

startHoax(alice);
// revert on self-approve of eVault
vm.expectRevert(Errors.E_SelfApproval.selector);
// no-op
eTST.approve(alice, 0);

assertEq(eTST.allowance(alice, alice), 0);
Expand All @@ -351,8 +350,7 @@ contract ERC20Test_Actions is EVaultTestBase {
assertEq(eTST.allowance(alice, alice), 0);

startHoax(alice);
// revert on self-approve of eVault
vm.expectRevert(Errors.E_SelfApproval.selector);
// no-op
eTST.approve(alice, type(uint256).max);

assertEq(eTST.allowance(alice, alice), 0);
Expand Down

0 comments on commit 6d8747e

Please sign in to comment.