Skip to content

Commit

Permalink
perf: add allowance pre-check to transferFrom()
Browse files Browse the repository at this point in the history
  • Loading branch information
CT committed Mar 3, 2025
1 parent 6a6fdb7 commit 1806ea5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion contracts/token/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,14 @@ contract Token is IToken, AgentRoleUpgradeable, TokenStorage, IERC165, TokenPerm

uint256 balance = balanceOf(_from) - (_frozenTokens[_from]);
require(_amount <= balance, ERC20InsufficientBalance(_from, balance, _amount));

if (!_defaultAllowances[msg.sender] || _defaultAllowanceOptOuts[_from]) {
uint256 allowance = _allowances[_from][msg.sender];
require(allowance >= _amount, ERC20InsufficientAllowance(msg.sender, allowance, _amount));
}

if (_tokenIdentityRegistry.isVerified(_to) && _tokenCompliance.canTransfer(_from, _to, _amount)) {
if (!_defaultAllowances[msg.sender] || _defaultAllowanceOptOuts[_from]) {
unchecked {
_approve(_from, msg.sender, _allowances[_from][msg.sender] - (_amount));
}
_transfer(_from, _to, _amount);
Expand Down

0 comments on commit 1806ea5

Please sign in to comment.