Skip to content

Commit

Permalink
UniswapV2Swap: replace revert with require.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariaKt committed Aug 19, 2024
1 parent 33e5a8d commit e673cde
Showing 1 changed file with 7 additions and 28 deletions.
35 changes: 7 additions & 28 deletions test/examples/swaps/UniswapV2Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -463,21 +463,12 @@ contract USDCMock {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
error ERC20InvalidSender(address sender);
error ERC20InvalidReceiver(address receiver);
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
error ERC20InvalidApprover(address approver);
error ERC20InvalidSpender(address spender);

function decimals() external returns (uint8) {
return 18;
}

function mint(address account, uint256 value) public {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
require(account != address(0), "USDC: invalid receiver");
_update(address(0), account, value);
}

Expand Down Expand Up @@ -509,12 +500,8 @@ contract USDCMock {
}

function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
require(from != address(0), "USDC: invalid sender");
require(to != address(0), "USDC: invalid receiver");
_update(from, to, value);
}

Expand All @@ -523,9 +510,7 @@ contract USDCMock {
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
require(fromBalance >= value, "USDC: insufficient balance");
_balances[from] = fromBalance - value;

}
Expand All @@ -542,12 +527,8 @@ contract USDCMock {


function _approve(address owner, address spender, uint256 value, bool emitEvent) internal {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
require(owner != address(0), "USDC: invalid approver");
require(spender != address(0), "USDC: invalid spender");
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
Expand All @@ -557,9 +538,7 @@ contract USDCMock {
function _spendAllowance(address owner, address spender, uint256 value) internal {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
require(currentAllowance >= value, "USDC: insufficient allowance");
_approve(owner, spender, currentAllowance - value, false);

}
Expand Down

0 comments on commit e673cde

Please sign in to comment.