test-isol-01 0.0.9 → 0.0.11

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.
@@ -0,0 +1,146 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "../adapter/TransferAuthorize.sol";
6
+ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
7
+
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 ERC20xTransferWithAuthorize is ERC20, TransferAuthorize, ReentrancyGuard {
12
+
13
+ // constructor(string memory name, string memory version)
14
+ // TransferAuthorize(name, version)
15
+ // {}
16
+ constructor()
17
+ TransferAuthorize("ERC20xTransferWithAuthorize", "ERC20xTransferWithAuthorize")
18
+ {}
19
+
20
+ /// @notice Recipient-triggered transfer using an off-chain signature by `from`.
21
+ /// @dev The caller must be the recipient `to` to match the semantics of "receive with authorization".
22
+ function receiveWithAuthorize(
23
+ address from,
24
+ address to,
25
+ uint256 value,
26
+ uint256 validAfter,
27
+ uint256 validBefore,
28
+ bytes32 nonce,
29
+ bytes calldata signature
30
+ ) external override nonReentrant {
31
+ require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
32
+ address signer = _verifyReceive(
33
+ from,
34
+ to,
35
+ value,
36
+ validAfter,
37
+ validBefore,
38
+ nonce,
39
+ signature
40
+ );
41
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
42
+ _useAuthorize(from, nonce);
43
+ _transfer(from, to, value);
44
+ }
45
+
46
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
47
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
48
+ function transferWithAuthorize(
49
+ address from,
50
+ address to,
51
+ uint256 value,
52
+ uint256 validAfter,
53
+ uint256 validBefore,
54
+ bytes32 nonce,
55
+ bytes calldata signature
56
+ ) external override nonReentrant {
57
+ address signer = _verifyTransfer(
58
+ from,
59
+ to,
60
+ value,
61
+ validAfter,
62
+ validBefore,
63
+ nonce,
64
+ signature
65
+ );
66
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
67
+ _useAuthorize(from, nonce);
68
+ _transfer(from, to, value);
69
+ }
70
+
71
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
72
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
73
+ function transferFromWithAuthorize(
74
+ address from,
75
+ address to,
76
+ uint256 value,
77
+ uint256 validAfter,
78
+ uint256 validBefore,
79
+ bytes32 nonce,
80
+ bytes calldata signature
81
+ ) external override nonReentrant {
82
+ address signer = _verifyTransferFrom(
83
+ from,
84
+ to,
85
+ value,
86
+ validAfter,
87
+ validBefore,
88
+ nonce,
89
+ signature
90
+ );
91
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
92
+ _useAuthorize(from, nonce);
93
+ _spendAllowance(from, to, value);
94
+ _transfer(from, to, value);
95
+ }
96
+
97
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
98
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
99
+ function approveWithAuthorize(
100
+ address from,
101
+ address to,
102
+ uint256 value,
103
+ uint256 validAfter,
104
+ uint256 validBefore,
105
+ bytes32 nonce,
106
+ bytes calldata signature
107
+ ) external override nonReentrant {
108
+ address signer = _verifyApprove(
109
+ from,
110
+ to,
111
+ value,
112
+ validAfter,
113
+ validBefore,
114
+ nonce,
115
+ signature
116
+ );
117
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
118
+ _useAuthorize(from, nonce);
119
+ _approve(from, to, value);
120
+ }
121
+
122
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
123
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
124
+ function burnWithAuthorize(
125
+ address from,
126
+ address to,
127
+ uint256 value,
128
+ uint256 validAfter,
129
+ uint256 validBefore,
130
+ bytes32 nonce,
131
+ bytes calldata signature
132
+ ) external override nonReentrant {
133
+ address signer = _verifyBurn(
134
+ from,
135
+ to,
136
+ value,
137
+ validAfter,
138
+ validBefore,
139
+ nonce,
140
+ signature
141
+ );
142
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
143
+ _useAuthorize(from, nonce);
144
+ _burn(from, value);
145
+ }
146
+ }
@@ -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 { ERC20xTransferWithAuthorize } from "./ERC20xTransferWithAuthorize.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 WrapERC20xTransferWithAuthorize is ERC20, ERC20Wrapper, ERC20xTransferWithAuthorize {
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
+ ERC20xTransferWithAuthorize(_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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {