Skip to content

Commit 4ae86a7

Browse files
author
yakuhito
committed
thanks again shark0der
1 parent 179bb5d commit 4ae86a7

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ Gas consumption (estimate):
66
·------------------------------|---------------------------|-------------|-----------------------------·
77
| Solc version: 0.8.7 · Optimizer enabled: true · Runs: 200 · Block limit: 30000000 gas │
88
·······························|···························|·············|······························
9-
| Methods · 100 gwei/gas · 3417.01 usd/eth │
9+
| Methods · 100 gwei/gas · 3406.79 usd/eth │
1010
··············|················|·············|·············|·············|···············|··············
1111
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
1212
··············|················|·············|·············|·············|···············|··············
13-
| TestToken · approve · 46239 · 46251 · 46250 · 12 · 15.80
13+
| TestToken · approve · 46239 · 46251 · 46250 · 12 · 15.76
1414
··············|················|·············|·············|·············|···············|··············
15-
| YakuSwap · cancelSwap · - · - · 40105 · 2 · 13.70
15+
| YakuSwap · cancelSwap · - · - · 41126 · 2 · 14.01
1616
··············|················|·············|·············|·············|···············|··············
17-
| YakuSwap · completeSwap · 86298 · 86310 · 86306 · 6 · 29.49
17+
| YakuSwap · completeSwap · 87304 · 87316 · 87312 · 6 · 29.75
1818
··············|················|·············|·············|·············|···············|··············
19-
| YakuSwap · createSwap · 84508 · 84520 · 84519 · 24 · 28.88
19+
| YakuSwap · createSwap · 85628 · 85640 · 85639 · 24 · 29.18
2020
··············|················|·············|·············|·············|···············|··············
21-
| YakuSwap · withdrawFees · 36483 · 52383 · 47083 · 3 · 16.09
21+
| YakuSwap · withdrawFees · 37507 · 53407 · 48107 · 3 · 16.39
2222
··············|················|·············|·············|·············|···············|··············
2323
| Deployments · · % of limit · │
2424
·······························|·············|·············|·············|···············|··············
25-
| TestToken · - · - · 641308 · 2.1 % · 219.14
25+
| TestToken · - · - · 641308 · 2.1 % · 218.48
2626
·······························|·············|·············|·············|···············|··············
27-
| YakuSwap · - · - · 902396 · 3 % · 308.35
27+
| YakuSwap · - · - · 932806 · 3.1 % · 317.79
2828
·------------------------------|-------------|-------------|-------------|---------------|-------------·
2929
```
3030

contracts/YakuSwap.sol

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
pragma solidity ^0.8.0;
33

44
import "@openzeppelin/contracts/access/Ownable.sol";
5-
6-
interface IERC20 {
7-
function transferFrom(address _from, address _to, uint256 _amount) external returns (bool);
8-
function transfer(address _to, uint256 _amount) external returns (bool);
9-
}
5+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
107

118
contract YakuSwap is Ownable {
9+
using SafeERC20 for IERC20;
1210

1311
// Uninitialized - Default status (if swaps[index] doesn't exist, status will get this value)
1412
// Created - the swap was created, but the mone is still in the contract
@@ -79,7 +77,7 @@ contract YakuSwap is Ownable {
7977
);
8078

8179
require(swaps[swapHash] == SwapStatus.Uninitialized, "Invalid swap status");
82-
require(IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount), "Could not transfer tokens");
80+
IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), amount);
8381

8482
swaps[swapHash] = SwapStatus.Created;
8583
emit SwapCreated(
@@ -118,7 +116,7 @@ contract YakuSwap is Ownable {
118116
uint swapAmount = amount * 993 / 1000;
119117
totalFees[tokenAddress] += amount - swapAmount;
120118

121-
require(IERC20(tokenAddress).transfer(toAddress, swapAmount), "Transfer failed");
119+
IERC20(tokenAddress).safeTransfer(toAddress, swapAmount);
122120
}
123121

124122
function cancelSwap(
@@ -141,13 +139,13 @@ contract YakuSwap is Ownable {
141139
require(block.number >= blockNumber + MAX_BLOCK_HEIGHT, "MAX_BLOCK_HEIGHT not exceeded");
142140

143141
swaps[swapHash] = SwapStatus.Cancelled;
144-
require(IERC20(tokenAddress).transfer(msg.sender, amount), "Transfer failed");
142+
IERC20(tokenAddress).safeTransfer(msg.sender, amount);
145143
}
146144

147145
function withdrawFees(address tokenAddress) external onlyOwner {
148146
uint feesToWithdraw = totalFees[tokenAddress];
149147
totalFees[tokenAddress] = 0;
150148

151-
require(IERC20(tokenAddress).transfer(msg.sender, feesToWithdraw), "Transfer failed");
149+
IERC20(tokenAddress).safeTransfer(msg.sender, feesToWithdraw);
152150
}
153151
}

0 commit comments

Comments
 (0)