File tree Expand file tree Collapse file tree 2 files changed +23
-16
lines changed
Expand file tree Collapse file tree 2 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,26 @@ abstract contract ERC20BaseInternal is IERC20BaseInternal {
6868 return true ;
6969 }
7070
71+ /**
72+ * @notice decrease spend amount granted by holder to spender
73+ * @param holder address on whose behalf tokens may be spent
74+ * @param spender address whose allowance to decrease
75+ * @param amount quantity by which to decrease allowance
76+ */
77+ function _decreaseAllowance (
78+ address holder ,
79+ address spender ,
80+ uint256 amount
81+ ) internal {
82+ uint256 allowance = _allowance (holder, spender);
83+
84+ require (allowance >= amount, 'ERC20: insufficient allowance ' );
85+
86+ unchecked {
87+ _approve (holder, spender, allowance - amount);
88+ }
89+ }
90+
7191 /**
7292 * @notice mint tokens for given account
7393 * @param account recipient of minted tokens
@@ -151,16 +171,7 @@ abstract contract ERC20BaseInternal is IERC20BaseInternal {
151171 address recipient ,
152172 uint256 amount
153173 ) internal virtual returns (bool ) {
154- uint256 allowance = _allowance (holder, msg .sender );
155-
156- require (
157- allowance >= amount,
158- 'ERC20: transfer amount exceeds allowance '
159- );
160-
161- unchecked {
162- _approve (holder, msg .sender , allowance - amount);
163- }
174+ _decreaseAllowance (holder, msg .sender , amount);
164175
165176 _transfer (holder, recipient, amount);
166177
Original file line number Diff line number Diff line change @@ -47,12 +47,8 @@ abstract contract ERC20ExtendedInternal is
4747 virtual
4848 returns (bool )
4949 {
50- uint256 allowance = _allowance (msg .sender , spender);
51-
52- require (amount <= allowance, 'ERC20Extended: insufficient allowance ' );
50+ _decreaseAllowance (msg .sender , spender, amount);
5351
54- unchecked {
55- return _approve (msg .sender , spender, allowance - amount);
56- }
52+ return true ;
5753 }
5854}
You can’t perform that action at this time.
0 commit comments