Skip to content

Commit fbaa1a6

Browse files
support USDT transfers (#34)
1 parent 33b491e commit fbaa1a6

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

contracts/ISwapTokens.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ interface ISwapTokens {
166166
*/
167167
error SwapIsInThePast();
168168

169-
/**
170-
* @dev Thrown when the token transfer failed.
171-
*/
172-
error TokenTransferFailed(address tokenAddress, uint256);
173-
174169
/**
175170
* @dev Thrown when the initiator in the config does not match the msg.sender.
176171
* @param expected The expected initiator address.

contracts/NonCancunTokenSwapper.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pragma solidity 0.8.20;
33

44
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
55
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7+
68
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
79
import { ISwapTokens } from "./ISwapTokens.sol";
810
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
@@ -489,9 +491,7 @@ contract NonCancunTokenSwapper is ISwapTokens, ReentrancyGuard {
489491
address _tokenOwner,
490492
address _recipient
491493
) internal {
492-
if (!IERC20(_tokenAddress).transferFrom(_tokenOwner, _recipient, _tokenQuantity)) {
493-
revert TokenTransferFailed(_tokenAddress, _tokenQuantity);
494-
}
494+
SafeERC20.safeTransferFrom(IERC20(_tokenAddress), _tokenOwner, _recipient, _tokenQuantity);
495495
}
496496

497497
/**

contracts/TokenSwapper.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pragma solidity 0.8.26;
33

44
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
55
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7+
68
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
79
import { ISwapTokens } from "./ISwapTokens.sol";
810
import { TransientStorage } from "./TransientStorage.sol";
@@ -489,9 +491,7 @@ contract TokenSwapper is ISwapTokens {
489491
address _tokenOwner,
490492
address _recipient
491493
) internal {
492-
if (!IERC20(_tokenAddress).transferFrom(_tokenOwner, _recipient, _tokenQuantity)) {
493-
revert TokenTransferFailed(_tokenAddress, _tokenQuantity);
494-
}
494+
SafeERC20.safeTransferFrom(IERC20(_tokenAddress), _tokenOwner, _recipient, _tokenQuantity);
495495
}
496496

497497
/**

test/NonCanunTokenSwapperERC20.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ describe("tokenSwapper erc20 testing", function () {
877877
await erc20B.connect(swapper2).approve(tokenSwapperAddress, 500n);
878878

879879
await expect(tokenSwapper.connect(denyListedAccount).completeSwap(1, defaultSwap, { value: GENERIC_SWAP_ETH }))
880-
.to.be.revertedWithCustomError(tokenSwapper, "TokenTransferFailed")
881-
.withArgs(erc20BAddress, 500n);
880+
.to.be.revertedWithCustomError(tokenSwapper, "SafeERC20FailedOperation")
881+
.withArgs(erc20BAddress);
882882
});
883883
});
884884
});

test/TokenSwapperERC20.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ describe("tokenSwapper erc20 testing", function () {
877877
await erc20B.connect(swapper2).approve(tokenSwapperAddress, 500n);
878878

879879
await expect(tokenSwapper.connect(denyListedAccount).completeSwap(1, defaultSwap, { value: GENERIC_SWAP_ETH }))
880-
.to.be.revertedWithCustomError(tokenSwapper, "TokenTransferFailed")
881-
.withArgs(erc20BAddress, 500n);
880+
.to.be.revertedWithCustomError(tokenSwapper, "SafeERC20FailedOperation")
881+
.withArgs(erc20BAddress);
882882
});
883883
});
884884
});

0 commit comments

Comments
 (0)