test-isol-01 0.0.21 → 0.0.22

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {
@@ -1,35 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
3
-
4
- interface ITransferAuthorize {
5
- event AuthorizeUsed(address indexed authorizer, bytes32 indexed nonce);
6
-
7
- function authorizeState(address authorizer, bytes32 nonce)
8
- external
9
- view
10
- returns (bool);
11
-
12
- function receiveWithAuthorize(
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 transferWithAuthorize(
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
- }
@@ -1,67 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
3
-
4
- import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
5
- import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
6
- import "./ITransferAuthorize.sol";
7
-
8
- abstract contract TransferAuthorize is ITransferAuthorize, 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 _authorizeState;
16
-
17
- bytes32 public constant RECEIVE_TYPEHASH =
18
- keccak256("ReceiveWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
19
-
20
- bytes32 public constant TRANSFER_TYPEHASH =
21
- keccak256("TransferWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
22
-
23
- function authorizeState(address authorizer, bytes32 nonce)
24
- public
25
- view
26
- override
27
- returns (bool)
28
- {
29
- return _authorizeState[authorizer][nonce];
30
- }
31
-
32
- function _useAuthorize(address authorizer, bytes32 nonce) internal {
33
- require(!_authorizeState[authorizer][nonce], "TransferAuthorize: authorization already used");
34
- _authorizeState[authorizer][nonce] = true;
35
- emit AuthorizeUsed(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, "TransferAuthorize: not yet valid");
51
- require(block.timestamp <= validBefore, "TransferAuthorize: 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,71 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
3
-
4
- import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
- import ".././adapter/TransferAuth.sol";
6
-
7
- abstract contract ERC20TransferAuth is ERC20, TransferAuth {
8
- constructor(string memory name, string memory version)
9
- TransferAuth(name, version)
10
- {}
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 override {
23
- require(msg.sender == to, "ERC20TransferAuth: caller != payee");
24
-
25
- address signer = _verify(
26
- RECEIVE_WITH_AUTHORIZATION_TYPEHASH,
27
- from,
28
- to,
29
- value,
30
- validAfter,
31
- validBefore,
32
- nonce,
33
- v,
34
- r,
35
- s
36
- );
37
- require(signer == from, "ERC20TransferAuth: invalid signature");
38
-
39
- _useAuthorization(from, nonce);
40
- _transfer(from, to, value);
41
- }
42
-
43
- function transferWithAuthorization(
44
- address from,
45
- address to,
46
- uint256 value,
47
- uint256 validAfter,
48
- uint256 validBefore,
49
- bytes32 nonce,
50
- uint8 v,
51
- bytes32 r,
52
- bytes32 s
53
- ) external override {
54
- address signer = _verify(
55
- TRANSFER_WITH_AUTHORIZATION_TYPEHASH,
56
- from,
57
- to,
58
- value,
59
- validAfter,
60
- validBefore,
61
- nonce,
62
- v,
63
- r,
64
- s
65
- );
66
- require(signer == from, "ERC20TransferAuth: invalid signature");
67
-
68
- _useAuthorization(from, nonce);
69
- _transfer(from, to, value);
70
- }
71
- }
@@ -1,88 +0,0 @@
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 TransferWithAuthorize
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 TransferWithAuthorize 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)
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
- uint8 v,
28
- bytes32 r,
29
- bytes32 s
30
- ) external override nonReentrant {
31
- // Only the recipient should be able to call this helper
32
- require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
33
-
34
- // Recover signer and validate
35
- address signer = _verify(
36
- RECEIVE_TYPEHASH,
37
- from,
38
- to,
39
- value,
40
- validAfter,
41
- validBefore,
42
- nonce,
43
- v,
44
- r,
45
- s
46
- );
47
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
48
-
49
- // Mark nonce as used
50
- _useAuthorize(from, nonce);
51
- // Execute the token transfer
52
- _transfer(from, to, value);
53
- }
54
-
55
- /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
56
- /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
57
- function transferWithAuthorize(
58
- address from,
59
- address to,
60
- uint256 value,
61
- uint256 validAfter,
62
- uint256 validBefore,
63
- bytes32 nonce,
64
- uint8 v,
65
- bytes32 r,
66
- bytes32 s
67
- ) external override nonReentrant {
68
- // Recover signer and validate
69
- address signer = _verify(
70
- TRANSFER_TYPEHASH,
71
- from,
72
- to,
73
- value,
74
- validAfter,
75
- validBefore,
76
- nonce,
77
- v,
78
- r,
79
- s
80
- );
81
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
82
-
83
- // Mark nonce as used
84
- _useAuthorize(from, nonce);
85
- // Execute the token transfer
86
- _transfer(from, to, value);
87
- }
88
- }
@@ -1,144 +0,0 @@
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 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)
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
- }
43
-
44
- /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
45
- /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
46
- function transferWithAuthorize(
47
- address from,
48
- address to,
49
- uint256 value,
50
- uint256 validAfter,
51
- uint256 validBefore,
52
- bytes32 nonce,
53
- bytes calldata signature
54
- ) external override nonReentrant {
55
- address signer = _verifyTransfer(
56
- from,
57
- to,
58
- value,
59
- validAfter,
60
- validBefore,
61
- nonce,
62
- signature
63
- );
64
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
65
- _useAuthorize(from, nonce);
66
- _transfer(from, to, value);
67
- }
68
-
69
- /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
70
- /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
71
- function transferFromWithAuthorize(
72
- address from,
73
- address to,
74
- uint256 value,
75
- uint256 validAfter,
76
- uint256 validBefore,
77
- bytes32 nonce,
78
- bytes calldata signature
79
- ) external override nonReentrant {
80
- address signer = _verifyTransferFrom(
81
- from,
82
- to,
83
- value,
84
- validAfter,
85
- validBefore,
86
- nonce,
87
- signature
88
- );
89
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
90
- _useAuthorize(from, nonce);
91
- _spendAllowance(from, to, value);
92
- _transfer(from, to, value);
93
- }
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
-
120
- /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
121
- /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
122
- function burnWithAuthorize(
123
- address from,
124
- address to,
125
- uint256 value,
126
- uint256 validAfter,
127
- uint256 validBefore,
128
- bytes32 nonce,
129
- bytes calldata signature
130
- ) external override nonReentrant {
131
- address signer = _verifyBurn(
132
- from,
133
- to,
134
- value,
135
- validAfter,
136
- validBefore,
137
- nonce,
138
- signature
139
- );
140
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
141
- _useAuthorize(from, nonce);
142
- _burn(from, value);
143
- }
144
- }
@@ -1,51 +0,0 @@
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
- }
@@ -1,71 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
3
-
4
- import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
- import ".././adapter/TransferAuth.sol";
6
-
7
- abstract contract ERC20TransferAuth is ERC20, TransferAuth {
8
- constructor(string memory name, string memory version)
9
- TransferAuth(name, version)
10
- {}
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 override {
23
- require(msg.sender == to, "ERC20TransferAuth: caller != payee");
24
-
25
- address signer = _verify(
26
- RECEIVE_WITH_AUTHORIZATION_TYPEHASH,
27
- from,
28
- to,
29
- value,
30
- validAfter,
31
- validBefore,
32
- nonce,
33
- v,
34
- r,
35
- s
36
- );
37
- require(signer == from, "ERC20TransferAuth: invalid signature");
38
-
39
- _useAuthorization(from, nonce);
40
- _transfer(from, to, value);
41
- }
42
-
43
- function transferWithAuthorization(
44
- address from,
45
- address to,
46
- uint256 value,
47
- uint256 validAfter,
48
- uint256 validBefore,
49
- bytes32 nonce,
50
- uint8 v,
51
- bytes32 r,
52
- bytes32 s
53
- ) external override {
54
- address signer = _verify(
55
- TRANSFER_WITH_AUTHORIZATION_TYPEHASH,
56
- from,
57
- to,
58
- value,
59
- validAfter,
60
- validBefore,
61
- nonce,
62
- v,
63
- r,
64
- s
65
- );
66
- require(signer == from, "ERC20TransferAuth: invalid signature");
67
-
68
- _useAuthorization(from, nonce);
69
- _transfer(from, to, value);
70
- }
71
- }
@@ -1,71 +0,0 @@
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
-
7
- abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize {
8
- constructor(string memory name, string memory version)
9
- TransferAuthorize(name, version)
10
- {}
11
-
12
- function receiveWithAuthorize(
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 override {
23
- require(msg.sender == to, "ERC20TransferAuthorize: caller must sender");
24
-
25
- address signer = _verify(
26
- RECEIVE_TYPEHASH,
27
- from,
28
- to,
29
- value,
30
- validAfter,
31
- validBefore,
32
- nonce,
33
- v,
34
- r,
35
- s
36
- );
37
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
38
-
39
- _useAuthorize(from, nonce);
40
- _transfer(from, to, value);
41
- }
42
-
43
- function transferWithAuthorize(
44
- address from,
45
- address to,
46
- uint256 value,
47
- uint256 validAfter,
48
- uint256 validBefore,
49
- bytes32 nonce,
50
- uint8 v,
51
- bytes32 r,
52
- bytes32 s
53
- ) external override {
54
- address signer = _verify(
55
- TRANSFER_TYPEHASH,
56
- from,
57
- to,
58
- value,
59
- validAfter,
60
- validBefore,
61
- nonce,
62
- v,
63
- r,
64
- s
65
- );
66
- require(signer == from, "ERC20TransferAuthorize: invalid signature");
67
-
68
- _useAuthorize(from, nonce);
69
- _transfer(from, to, value);
70
- }
71
- }