Skip to content

Commit

Permalink
thanks again shark0der
Browse files Browse the repository at this point in the history
  • Loading branch information
yakuhito committed Sep 12, 2021
1 parent 179bb5d commit 4ae86a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ Gas consumption (estimate):
·------------------------------|---------------------------|-------------|-----------------------------·
| Solc version: 0.8.7 · Optimizer enabled: true · Runs: 200 · Block limit: 30000000 gas │
·······························|···························|·············|······························
| Methods · 100 gwei/gas · 3417.01 usd/eth │
| Methods · 100 gwei/gas · 3406.79 usd/eth │
··············|················|·············|·············|·············|···············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
··············|················|·············|·············|·············|···············|··············
| TestToken · approve · 46239 · 46251 · 46250 · 12 · 15.80
| TestToken · approve · 46239 · 46251 · 46250 · 12 · 15.76
··············|················|·············|·············|·············|···············|··············
| YakuSwap · cancelSwap · - · - · 40105 · 2 · 13.70
| YakuSwap · cancelSwap · - · - · 41126 · 2 · 14.01
··············|················|·············|·············|·············|···············|··············
| YakuSwap · completeSwap · 86298 · 86310 · 86306 · 6 · 29.49
| YakuSwap · completeSwap · 87304 · 87316 · 87312 · 6 · 29.75
··············|················|·············|·············|·············|···············|··············
| YakuSwap · createSwap · 84508 · 84520 · 84519 · 24 · 28.88
| YakuSwap · createSwap · 85628 · 85640 · 85639 · 24 · 29.18
··············|················|·············|·············|·············|···············|··············
| YakuSwap · withdrawFees · 36483 · 52383 · 47083 · 3 · 16.09
| YakuSwap · withdrawFees · 37507 · 53407 · 48107 · 3 · 16.39
··············|················|·············|·············|·············|···············|··············
| Deployments · · % of limit · │
·······························|·············|·············|·············|···············|··············
| TestToken · - · - · 641308 · 2.1 % · 219.14
| TestToken · - · - · 641308 · 2.1 % · 218.48
·······························|·············|·············|·············|···············|··············
| YakuSwap · - · - · 902396 · 3 % · 308.35
| YakuSwap · - · - · 932806 · 3.1 % · 317.79
·------------------------------|-------------|-------------|-------------|---------------|-------------·
```

Expand Down
16 changes: 7 additions & 9 deletions contracts/YakuSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

interface IERC20 {
function transferFrom(address _from, address _to, uint256 _amount) external returns (bool);
function transfer(address _to, uint256 _amount) external returns (bool);
}
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract YakuSwap is Ownable {
using SafeERC20 for IERC20;

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

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

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

require(IERC20(tokenAddress).transfer(toAddress, swapAmount), "Transfer failed");
IERC20(tokenAddress).safeTransfer(toAddress, swapAmount);
}

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

swaps[swapHash] = SwapStatus.Cancelled;
require(IERC20(tokenAddress).transfer(msg.sender, amount), "Transfer failed");
IERC20(tokenAddress).safeTransfer(msg.sender, amount);
}

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

require(IERC20(tokenAddress).transfer(msg.sender, feesToWithdraw), "Transfer failed");
IERC20(tokenAddress).safeTransfer(msg.sender, feesToWithdraw);
}
}

0 comments on commit 4ae86a7

Please sign in to comment.