test-isol-01 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,38 +2,44 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
- import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
6
5
  import "../adapter/TransferAuthorize.sol";
7
6
  import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
8
7
 
9
- /**
10
- * @title ERC20WrappedWithAuthorize
11
- * @notice ERC20 wrapper that allows wrapping any existing ERC20 token
12
- * and adds EIP-712 off-chain authorization functions.
13
- * @dev Inherits ERC20, ERC20Wrapper, and ERC20TransferWithAuthorize:
14
- * - ERC20: standard token functionality
15
- * - ERC20Wrapper: depositFor/withdrawTo underlying tokens
16
- * - ERC20TransferWithAuthorize: transferWithAuthorize and receiveWithAuthorize
17
- */
18
- abstract contract WrapERC20xTransferWithAuthorize is ERC20, ERC20Wrapper, TransferAuthorize, ReentrancyGuard {
19
-
20
- /**
21
- * @notice Construct a wrapped ERC20 with authorization support
22
- * @param _underlyingToken Address of the ERC20 token to wrap. Users deposit this token to receive the wrapped token.
23
- * @param _name Name of the wrapped token (ERC20 metadata and EIP-712 domain name)
24
- * @param _symbol Symbol of the wrapped token (ERC20 metadata)
25
- * @param _version Version string for EIP-712 domain (e.g. "1")
26
- */
27
- constructor(
28
- address _underlyingToken,
29
- string memory _name,
30
- string memory _symbol,
31
- string memory _version
32
- )
33
- ERC20(_name, _symbol)
34
- ERC20Wrapper(IERC20(_underlyingToken))
35
- TransferAuthorize(_name, _version)
8
+ /// @title ERC20TransferWithAuthorize
9
+ /// @notice ERC20 extension that supports EIP-712 based `transferWithAuthorize` and `receiveWithAuthorize` flows
10
+ /// @dev `receiveWithAuthorize` restricts the caller to the `to` address (recipient submits the proof). `transferWithAuthorize` is open to relayers.
11
+ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, ReentrancyGuard {
12
+ /// @param name EIP-712 domain name
13
+ /// @param version EIP-712 domain version
14
+ constructor(string memory name, string memory version)
15
+ TransferAuthorize(name, version)
36
16
  {}
17
+
18
+ /// @notice Recipient-triggered transfer using an off-chain signature by `from`.
19
+ /// @dev The caller must be the recipient `to` to match the semantics of "receive with authorization".
20
+ function receiveWithAuthorize(
21
+ address from,
22
+ address to,
23
+ uint256 value,
24
+ uint256 validAfter,
25
+ uint256 validBefore,
26
+ bytes32 nonce,
27
+ bytes calldata signature
28
+ ) external override nonReentrant {
29
+ require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
30
+ address signer = _verifyReceive(
31
+ from,
32
+ to,
33
+ value,
34
+ validAfter,
35
+ validBefore,
36
+ nonce,
37
+ signature
38
+ );
39
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
40
+ _useAuthorize(from, nonce);
41
+ _transfer(from, to, value);
42
+ }
37
43
 
38
44
  /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
39
45
  /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
@@ -86,6 +92,31 @@ abstract contract WrapERC20xTransferWithAuthorize is ERC20, ERC20Wrapper, Transf
86
92
  _transfer(from, to, value);
87
93
  }
88
94
 
95
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
96
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
97
+ function approveWithAuthorize(
98
+ address from,
99
+ address to,
100
+ uint256 value,
101
+ uint256 validAfter,
102
+ uint256 validBefore,
103
+ bytes32 nonce,
104
+ bytes calldata signature
105
+ ) external override nonReentrant {
106
+ address signer = _verifyApprove(
107
+ from,
108
+ to,
109
+ value,
110
+ validAfter,
111
+ validBefore,
112
+ nonce,
113
+ signature
114
+ );
115
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
116
+ _useAuthorize(from, nonce);
117
+ _approve(from, to, value);
118
+ }
119
+
89
120
  /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
90
121
  /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
91
122
  function burnWithAuthorize(
@@ -110,19 +141,4 @@ abstract contract WrapERC20xTransferWithAuthorize is ERC20, ERC20Wrapper, Transf
110
141
  _useAuthorize(from, nonce);
111
142
  _burn(from, value);
112
143
  }
113
-
114
- /**
115
- * @notice Returns the token decimals
116
- * @dev Overrides both ERC20 and ERC20Wrapper decimals function
117
- * @return uint8 decimals of the token (usually matches underlying token)
118
- */
119
- function decimals()
120
- public
121
- view
122
- virtual
123
- override(ERC20, ERC20Wrapper)
124
- returns (uint8)
125
- {
126
- return super.decimals();
127
- }
128
144
  }
@@ -0,0 +1,51 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import { IERC20, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import { ERC20Wrapper } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
6
+ import { ERC20TransferWithAuthorize } from "./ERC20TransferWithAuthorize.sol";
7
+
8
+ /**
9
+ * @title ERC20WrappedWithAuthorize
10
+ * @notice ERC20 wrapper that allows wrapping any existing ERC20 token
11
+ * and adds EIP-712 off-chain authorization functions.
12
+ * @dev Inherits ERC20, ERC20Wrapper, and ERC20TransferWithAuthorize:
13
+ * - ERC20: standard token functionality
14
+ * - ERC20Wrapper: depositFor/withdrawTo underlying tokens
15
+ * - ERC20TransferWithAuthorize: transferWithAuthorize and receiveWithAuthorize
16
+ */
17
+ abstract contract ERC20WrappedWithAuthorize is ERC20, ERC20Wrapper, ERC20TransferWithAuthorize {
18
+
19
+ /**
20
+ * @notice Construct a wrapped ERC20 with authorization support
21
+ * @param _underlyingToken Address of the ERC20 token to wrap. Users deposit this token to receive the wrapped token.
22
+ * @param _name Name of the wrapped token (ERC20 metadata and EIP-712 domain name)
23
+ * @param _symbol Symbol of the wrapped token (ERC20 metadata)
24
+ * @param _version Version string for EIP-712 domain (e.g. "1")
25
+ */
26
+ constructor(
27
+ address _underlyingToken,
28
+ string memory _name,
29
+ string memory _symbol,
30
+ string memory _version
31
+ )
32
+ ERC20(_name, _symbol)
33
+ ERC20Wrapper(IERC20(_underlyingToken))
34
+ ERC20TransferWithAuthorize(_name, _version)
35
+ {}
36
+
37
+ /**
38
+ * @notice Returns the token decimals
39
+ * @dev Overrides both ERC20 and ERC20Wrapper decimals function
40
+ * @return uint8 decimals of the token (usually matches underlying token)
41
+ */
42
+ function decimals()
43
+ public
44
+ view
45
+ virtual
46
+ override(ERC20, ERC20Wrapper)
47
+ returns (uint8)
48
+ {
49
+ return super.decimals();
50
+ }
51
+ }
@@ -0,0 +1,53 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import { IERC20, ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import { ERC20Wrapper } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
6
+ // import { ERC20TransferWithAuthorize } from "./ERC20TransferWithAuthorize.sol";
7
+ import "../adapter/TransferAuthorize.sol";
8
+ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
9
+
10
+ /**
11
+ * @title ERC20WrappedWithAuthorize
12
+ * @notice ERC20 wrapper that allows wrapping any existing ERC20 token
13
+ * and adds EIP-712 off-chain authorization functions.
14
+ * @dev Inherits ERC20, ERC20Wrapper, and ERC20TransferWithAuthorize:
15
+ * - ERC20: standard token functionality
16
+ * - ERC20Wrapper: depositFor/withdrawTo underlying tokens
17
+ * - ERC20TransferWithAuthorize: transferWithAuthorize and receiveWithAuthorize
18
+ */
19
+ abstract contract ERC20WrappedWithAuthorize is ERC20, ERC20Wrapper, TransferAuthorize, ReentrancyGuard {
20
+
21
+ /**
22
+ * @notice Construct a wrapped ERC20 with authorization support
23
+ * @param _underlyingToken Address of the ERC20 token to wrap. Users deposit this token to receive the wrapped token.
24
+ * @param _name Name of the wrapped token (ERC20 metadata and EIP-712 domain name)
25
+ * @param _symbol Symbol of the wrapped token (ERC20 metadata)
26
+ * @param _version Version string for EIP-712 domain (e.g. "1")
27
+ */
28
+ constructor(
29
+ address _underlyingToken,
30
+ string memory _name,
31
+ string memory _symbol,
32
+ string memory _version
33
+ )
34
+ ERC20(_name, _symbol)
35
+ ERC20Wrapper(IERC20(_underlyingToken))
36
+ TransferAuthorize(_name, _version)
37
+ {}
38
+
39
+ /**
40
+ * @notice Returns the token decimals
41
+ * @dev Overrides both ERC20 and ERC20Wrapper decimals function
42
+ * @return uint8 decimals of the token (usually matches underlying token)
43
+ */
44
+ function decimals()
45
+ public
46
+ view
47
+ virtual
48
+ override(ERC20, ERC20Wrapper)
49
+ returns (uint8)
50
+ {
51
+ return super.decimals();
52
+ }
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {