@@ -4,7 +4,6 @@ pragma solidity ^0.8.0;
44import { IERC20 } from "openzeppelin/interfaces/IERC20.sol " ;
55import { IERC721 } from "openzeppelin/interfaces/IERC721.sol " ;
66import { IERC1155 } from "openzeppelin/interfaces/IERC1155.sol " ;
7- import { IERC20Permit } from "openzeppelin/token/ERC20/extensions/IERC20Permit.sol " ;
87import { SafeERC20 } from "openzeppelin/token/ERC20/utils/SafeERC20.sol " ;
98import { ERC165Checker } from "openzeppelin/utils/introspection/ERC165Checker.sol " ;
109import { SafeCast } from "openzeppelin/utils/math/SafeCast.sol " ;
@@ -101,53 +100,53 @@ library Permit2MultiToken {
101100 |*----------------------------------------------------------*/
102101
103102 /**
104- * @notice Wrapping function for `transferFrom` calls on various token interfaces .
103+ * @notice Wrapping function for `transferFrom` calls.
105104 * @dev If `source` is `address(this)`, function `transfer` is called instead of `transferFrom` for ERC20 category.
106105 * @param asset Struct defining all necessary context of a token.
107106 * @param permit2 Address of the Permit2 contract to be used for transferring ERC20 tokens.
108107 * @param source Account/address that provided the allowance.
109108 * @param dest Destination address.
110109 */
111110 function transferAssetFrom (Asset memory asset , address permit2 , address source , address dest ) internal {
112- _transferAssetFrom (asset, permit2, source, dest, false );
111+ if (asset.category != Category.ERC20 ) {
112+ revert ("MultiToken: Unsupported category " );
113+ }
114+
115+ if (source == address (this )) {
116+ IERC20 (asset.assetAddress).safeTransfer (dest, asset.amount);
117+ } else {
118+ IPermit2Like (permit2).transferFrom (source, dest, asset.amount.toUint160 (), asset.assetAddress);
119+ }
113120 }
114121
115122 /**
116- * @notice Wrapping function for `safeTransferFrom ` calls on various token interfaces .
123+ * @notice Wrapping function for `transferFrom ` calls.
117124 * @dev If `source` is `address(this)`, function `transfer` is called instead of `transferFrom` for ERC20 category.
118125 * @param asset Struct defining all necessary context of a token.
119126 * @param permit2 Address of the Permit2 contract to be used for transferring ERC20 tokens.
120127 * @param source Account/address that provided the allowance.
121128 * @param dest Destination address.
129+ * @param permit PermitTransferFrom struct containing the signed permit data.
130+ * @param signature Signature to verify the permit.
122131 */
123- function safeTransferAssetFrom (Asset memory asset , address permit2 , address source , address dest ) internal {
124- _transferAssetFrom (asset, permit2, source, dest, true );
125- }
126-
127- function _transferAssetFrom (Asset memory asset , address permit2 , address source , address dest , bool isSafe ) private {
128- if (asset.category == Category.ERC20 ) {
129- if (source == address (this ))
130- IERC20 (asset.assetAddress).safeTransfer (dest, asset.amount);
131- else
132- IPermit2Like (permit2).transferFrom (source, dest, asset.amount.toUint160 (), asset.assetAddress);
133-
134- } else if (asset.category == Category.ERC721 ) {
135- if (! isSafe)
136- IERC721 (asset.assetAddress).transferFrom (source, dest, asset.id);
137- else
138- IERC721 (asset.assetAddress).safeTransferFrom (source, dest, asset.id, "" );
139-
140- } else if (asset.category == Category.ERC1155 ) {
141- IERC1155 (asset.assetAddress).safeTransferFrom (source, dest, asset.id, asset.amount == 0 ? 1 : asset.amount, "" );
142-
143- } else if (asset.category == Category.CryptoKitties) {
144- if (source == address (this ))
145- ICryptoKitties (asset.assetAddress).transfer (dest, asset.id);
146- else
147- ICryptoKitties (asset.assetAddress).transferFrom (source, dest, asset.id);
132+ function permitTransferAssetFrom (
133+ Asset memory asset ,
134+ address permit2 ,
135+ address source ,
136+ address dest ,
137+ IPermit2Like.PermitTransferFrom memory permit ,
138+ bytes memory signature
139+ ) internal {
140+ if (asset.category != Category.ERC20 ) {
141+ revert ("MultiToken: Unsupported category " );
142+ }
148143
144+ if (source == address (this )) {
145+ IERC20 (asset.assetAddress).safeTransfer (dest, asset.amount);
149146 } else {
150- revert ("MultiToken: Unsupported category " );
147+ IPermit2Like (permit2).permitTransferFrom (
148+ permit, IPermit2Like.SignatureTransferDetails (dest, asset.amount), source, signature
149+ );
151150 }
152151 }
153152
0 commit comments