test-isol-01 0.0.23 → 0.0.24

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.
@@ -4,18 +4,18 @@ pragma solidity ^0.8.0;
4
4
  import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
5
  import "../adapter/TransferAuthorize.sol";
6
6
  import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
7
+ import "@openzeppelin/contracts/access/Ownable.sol";
7
8
 
8
9
  /// @title ERC20TransferWithAuthorize
9
10
  /// @notice ERC20 extension that supports EIP-712 based `transferWithAuthorize` and `receiveWithAuthorize` flows
10
11
  /// @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
+ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, ReentrancyGuard, Ownable {
12
13
 
13
- constructor(string memory name, string memory symbol, uint256 initialSupply)
14
+ constructor(string memory name, string memory symbol, string memory _name, string memory _version)
14
15
  ERC20(name, symbol)
15
- TransferAuthorize("ERC20TransferWithAuthorize", "ERC20TransferWithAuthorize")
16
- {
17
- _mint(msg.sender, initialSupply * 10 ** decimals());
18
- }
16
+ TransferAuthorize(_name, _version)
17
+ Ownable(msg.sender)
18
+ {}
19
19
 
20
20
  /// @notice Recipient-triggered transfer using an off-chain signature by `from`.
21
21
  /// @dev The caller must be the recipient `to` to match the semantics of "receive with authorization".
@@ -0,0 +1,148 @@
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
+ import "@openzeppelin/contracts/access/Ownable.sol";
8
+
9
+ /// @title ERC20xTransferWithAuthorize
10
+ /// @notice ERC20 extension that supports EIP-712 based `transferWithAuthorize` and `receiveWithAuthorize` flows
11
+ /// @dev `receiveWithAuthorize` restricts the caller to the `to` address (recipient submits the proof). `transferWithAuthorize` is open to relayers.
12
+ abstract contract ERC20xTransferWithAuthorize is ERC20, TransferAuthorize, ReentrancyGuard, Ownable {
13
+
14
+ constructor(string memory name, string memory symbol, uint256 initialSupply)
15
+ ERC20(name, symbol)
16
+ TransferAuthorize("ERC20xTransferWithAuthorize", "ERC20xTransferWithAuthorize")
17
+ Ownable(msg.sender)
18
+ {
19
+ _mint(msg.sender, initialSupply * 10 ** decimals());
20
+ }
21
+
22
+ /// @notice Recipient-triggered transfer using an off-chain signature by `from`.
23
+ /// @dev The caller must be the recipient `to` to match the semantics of "receive with authorization".
24
+ function receiveWithAuthorize(
25
+ address from,
26
+ address to,
27
+ uint256 value,
28
+ uint256 validAfter,
29
+ uint256 validBefore,
30
+ bytes32 nonce,
31
+ bytes calldata signature
32
+ ) external override nonReentrant {
33
+ require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
34
+ address signer = _verifyReceive(
35
+ from,
36
+ to,
37
+ value,
38
+ validAfter,
39
+ validBefore,
40
+ nonce,
41
+ signature
42
+ );
43
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
44
+ _useAuthorize(from, nonce);
45
+ _transfer(from, to, value);
46
+ }
47
+
48
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
49
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
50
+ function transferWithAuthorize(
51
+ address from,
52
+ address to,
53
+ uint256 value,
54
+ uint256 validAfter,
55
+ uint256 validBefore,
56
+ bytes32 nonce,
57
+ bytes calldata signature
58
+ ) external override nonReentrant {
59
+ address signer = _verifyTransfer(
60
+ from,
61
+ to,
62
+ value,
63
+ validAfter,
64
+ validBefore,
65
+ nonce,
66
+ signature
67
+ );
68
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
69
+ _useAuthorize(from, nonce);
70
+ _transfer(from, to, value);
71
+ }
72
+
73
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
74
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
75
+ function transferFromWithAuthorize(
76
+ address from,
77
+ address to,
78
+ uint256 value,
79
+ uint256 validAfter,
80
+ uint256 validBefore,
81
+ bytes32 nonce,
82
+ bytes calldata signature
83
+ ) external override nonReentrant {
84
+ address signer = _verifyTransferFrom(
85
+ from,
86
+ to,
87
+ value,
88
+ validAfter,
89
+ validBefore,
90
+ nonce,
91
+ signature
92
+ );
93
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
94
+ _useAuthorize(from, nonce);
95
+ _spendAllowance(from, to, value);
96
+ _transfer(from, to, value);
97
+ }
98
+
99
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
100
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
101
+ function approveWithAuthorize(
102
+ address from,
103
+ address to,
104
+ uint256 value,
105
+ uint256 validAfter,
106
+ uint256 validBefore,
107
+ bytes32 nonce,
108
+ bytes calldata signature
109
+ ) external override nonReentrant {
110
+ address signer = _verifyApprove(
111
+ from,
112
+ to,
113
+ value,
114
+ validAfter,
115
+ validBefore,
116
+ nonce,
117
+ signature
118
+ );
119
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
120
+ _useAuthorize(from, nonce);
121
+ _approve(from, to, value);
122
+ }
123
+
124
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
125
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
126
+ function burnWithAuthorize(
127
+ address from,
128
+ address to,
129
+ uint256 value,
130
+ uint256 validAfter,
131
+ uint256 validBefore,
132
+ bytes32 nonce,
133
+ bytes calldata signature
134
+ ) external override nonReentrant {
135
+ address signer = _verifyBurn(
136
+ from,
137
+ to,
138
+ value,
139
+ validAfter,
140
+ validBefore,
141
+ nonce,
142
+ signature
143
+ );
144
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
145
+ _useAuthorize(from, nonce);
146
+ _burn(from, value);
147
+ }
148
+ }
@@ -1,12 +1,12 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.0;
3
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";
4
+ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
+ import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
6
+ import "../adapter/ERC20TransferWithAuthorize.sol";
7
7
 
8
8
  /**
9
- * @title ERC20WrappedWithAuthorize
9
+ * @title WrapERC20xWithAuthorize
10
10
  * @notice ERC20 wrapper that allows wrapping any existing ERC20 token
11
11
  * and adds EIP-712 off-chain authorization functions.
12
12
  * @dev Inherits ERC20, ERC20Wrapper, and ERC20TransferWithAuthorize:
@@ -14,24 +14,15 @@ import { ERC20TransferWithAuthorize } from "./ERC20TransferWithAuthorize.sol";
14
14
  * - ERC20Wrapper: depositFor/withdrawTo underlying tokens
15
15
  * - ERC20TransferWithAuthorize: transferWithAuthorize and receiveWithAuthorize
16
16
  */
17
- abstract contract ERC20WrappedWithAuthorize is ERC20, ERC20Wrapper, ERC20TransferWithAuthorize {
17
+ abstract contract WrapERC20xWithAuthorize is ERC20Wrapper, ERC20TransferWithAuthorize {
18
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
19
  constructor(
27
20
  address _underlyingToken,
28
21
  string memory _name,
29
- string memory _symbol,
30
- string memory _version
22
+ string memory _symbol
31
23
  )
32
- ERC20(_name, _symbol)
33
24
  ERC20Wrapper(IERC20(_underlyingToken))
34
- ERC20TransferWithAuthorize(_name, _version)
25
+ ERC20TransferWithAuthorize(_name, _symbol, "WrapERC20xWithAuthorize", "WrapERC20xWithAuthorize")
35
26
  {}
36
27
 
37
28
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {
@@ -1,67 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.19;
3
-
4
- import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
5
- import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
6
- import "./IERC3009.sol";
7
-
8
- abstract contract ERC3009 is IERC3009, EIP712 {
9
- using ECDSA for bytes32;
10
-
11
- constructor(string memory name, string memory version)
12
- EIP712(name, version)
13
- {}
14
-
15
- mapping(address => mapping(bytes32 => bool)) private _authorizationState;
16
-
17
- bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH =
18
- keccak256("ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
19
-
20
- bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH =
21
- keccak256("TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
22
-
23
- function authorizationState(address authorizer, bytes32 nonce)
24
- public
25
- view
26
- override
27
- returns (bool)
28
- {
29
- return _authorizationState[authorizer][nonce];
30
- }
31
-
32
- function _useAuthorization(address authorizer, bytes32 nonce) internal {
33
- require(!_authorizationState[authorizer][nonce], "ERC3009: authorization already used");
34
- _authorizationState[authorizer][nonce] = true;
35
- emit AuthorizationUsed(authorizer, nonce);
36
- }
37
-
38
- function _verify(
39
- bytes32 typehash,
40
- address from,
41
- address to,
42
- uint256 value,
43
- uint256 validAfter,
44
- uint256 validBefore,
45
- bytes32 nonce,
46
- uint8 v,
47
- bytes32 r,
48
- bytes32 s
49
- ) internal view returns (address signer) {
50
- require(block.timestamp > validAfter, "ERC3009: not yet valid");
51
- require(block.timestamp < validBefore, "ERC3009: expired");
52
-
53
- bytes32 structHash = keccak256(
54
- abi.encode(
55
- typehash,
56
- from,
57
- to,
58
- value,
59
- validAfter,
60
- validBefore,
61
- nonce
62
- )
63
- );
64
-
65
- signer = _hashTypedDataV4(structHash).recover(v, r, s);
66
- }
67
- }
@@ -1,35 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.19;
3
-
4
- interface IERC3009 {
5
- event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce);
6
-
7
- function authorizationState(address authorizer, bytes32 nonce)
8
- external
9
- view
10
- returns (bool);
11
-
12
- function receiveWithAuthorization(
13
- address from,
14
- address to,
15
- uint256 value,
16
- uint256 validAfter,
17
- uint256 validBefore,
18
- bytes32 nonce,
19
- uint8 v,
20
- bytes32 r,
21
- bytes32 s
22
- ) external;
23
-
24
- function transferWithAuthorization(
25
- address from,
26
- address to,
27
- uint256 value,
28
- uint256 validAfter,
29
- uint256 validBefore,
30
- bytes32 nonce,
31
- uint8 v,
32
- bytes32 r,
33
- bytes32 s
34
- ) external;
35
- }