t-isol 0.0.8 → 0.0.9
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.
|
@@ -8,13 +8,13 @@ interface ITransferAuthorize {
|
|
|
8
8
|
/// @notice Emitted when an authorization (nonce) has been consumed for an authorizer
|
|
9
9
|
/// @param authorizer the account that signed the authorization
|
|
10
10
|
/// @param nonce unique nonce used by the authorization
|
|
11
|
-
event AuthorizeUsed(address
|
|
11
|
+
event AuthorizeUsed(address authorizer, bytes32 nonce);
|
|
12
12
|
|
|
13
13
|
/// @notice Emitted when a transfer with authorization is executed
|
|
14
|
-
event TransferWithAuthorize(address sender, address
|
|
14
|
+
event TransferWithAuthorize(address sender, address from, address to, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth);
|
|
15
15
|
|
|
16
16
|
/// @notice Emitted when a burn with authorization is executed
|
|
17
|
-
event BurnWithAuthorize(address
|
|
17
|
+
event BurnWithAuthorize(address sender, address from, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth);
|
|
18
18
|
|
|
19
19
|
/// @notice Returns whether a nonce has been used for a given authorizer
|
|
20
20
|
/// @param authorizer the account that signed the authorization
|
|
@@ -35,30 +35,6 @@ interface ITransferAuthorize {
|
|
|
35
35
|
bytes32 nonce,
|
|
36
36
|
bytes calldata auth
|
|
37
37
|
) external;
|
|
38
|
-
|
|
39
|
-
// ++
|
|
40
|
-
/// @notice Execute a "transfer with authorization" - typically any relayer may submit
|
|
41
|
-
function transferFromWithAuthorize(
|
|
42
|
-
address from,
|
|
43
|
-
address to,
|
|
44
|
-
uint256 value,
|
|
45
|
-
uint256 validAfter,
|
|
46
|
-
uint256 validBefore,
|
|
47
|
-
bytes32 nonce,
|
|
48
|
-
bytes calldata signature
|
|
49
|
-
) external;
|
|
50
|
-
|
|
51
|
-
// ++
|
|
52
|
-
/// @notice Execute a "approve with authorization" - typically any relayer may submit
|
|
53
|
-
function approveWithAuthorize(
|
|
54
|
-
address from,
|
|
55
|
-
address to,
|
|
56
|
-
uint256 value,
|
|
57
|
-
uint256 validAfter,
|
|
58
|
-
uint256 validBefore,
|
|
59
|
-
bytes32 nonce,
|
|
60
|
-
bytes calldata signature
|
|
61
|
-
) external;
|
|
62
38
|
|
|
63
39
|
/// @notice Execute a "approve with authorization" - typically any relayer may submit
|
|
64
40
|
function burnWithAuthorize(
|
|
@@ -17,14 +17,8 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
|
|
|
17
17
|
bytes32 public constant TRANSFER_TYPEHASH =
|
|
18
18
|
keccak256("TransferWithAuthorize(address from,address to,uint256 value,uint256 createTime,uint256 expireTime,bytes32 nonce)");
|
|
19
19
|
|
|
20
|
-
bytes32 public constant TRANSFERFROM_TYPEHASH =
|
|
21
|
-
keccak256("TransferFromWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
|
|
22
|
-
|
|
23
|
-
bytes32 public constant APPROVE_TYPEHASH =
|
|
24
|
-
keccak256("ApproveWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
|
|
25
|
-
|
|
26
20
|
bytes32 public constant BURN_TYPEHASH =
|
|
27
|
-
keccak256("BurnWithAuthorize(address from,uint256 value,uint256
|
|
21
|
+
keccak256("BurnWithAuthorize(address from,uint256 value,uint256 createTime,uint256 expireTime,bytes32 nonce)");
|
|
28
22
|
|
|
29
23
|
/// @param name EIP-712 domain name
|
|
30
24
|
/// @param version EIP-712 domain version
|
|
@@ -61,7 +55,7 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
|
|
|
61
55
|
uint256 expireTime,
|
|
62
56
|
bytes32 nonce,
|
|
63
57
|
bytes calldata auth
|
|
64
|
-
) internal
|
|
58
|
+
) internal returns (address signer) {
|
|
65
59
|
require(block.timestamp >= createTime, "TransferAuthorize: not yet created");
|
|
66
60
|
require(block.timestamp <= expireTime, "TransferAuthorize: not yet expired");
|
|
67
61
|
bytes32 structHash = keccak256(
|
|
@@ -79,81 +73,28 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
|
|
|
79
73
|
emit TransferWithAuthorize(msg.sender, from, to, value, createTime, expireTime, nonce, auth);
|
|
80
74
|
}
|
|
81
75
|
|
|
82
|
-
/// @dev Verify an EIP-712 typed signature for
|
|
83
|
-
function _verifyTransferFrom(
|
|
84
|
-
address from,
|
|
85
|
-
address to,
|
|
86
|
-
uint256 value,
|
|
87
|
-
uint256 validAfter,
|
|
88
|
-
uint256 validBefore,
|
|
89
|
-
bytes32 nonce,
|
|
90
|
-
bytes calldata signature
|
|
91
|
-
) internal view returns (address signer) {
|
|
92
|
-
require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
|
|
93
|
-
require(block.timestamp <= validBefore, "TransferAuthorize: expired");
|
|
94
|
-
bytes32 structHash = keccak256(
|
|
95
|
-
abi.encode(
|
|
96
|
-
TRANSFERFROM_TYPEHASH,
|
|
97
|
-
from,
|
|
98
|
-
to,
|
|
99
|
-
value,
|
|
100
|
-
validAfter,
|
|
101
|
-
validBefore,
|
|
102
|
-
nonce
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/// @dev Verify an EIP-712 typed signature for ApproveWithAuthorize and return the recovered signer
|
|
109
|
-
function _verifyApprove(
|
|
110
|
-
address from,
|
|
111
|
-
address to,
|
|
112
|
-
uint256 value,
|
|
113
|
-
uint256 validAfter,
|
|
114
|
-
uint256 validBefore,
|
|
115
|
-
bytes32 nonce,
|
|
116
|
-
bytes calldata signature
|
|
117
|
-
) internal view returns (address signer) {
|
|
118
|
-
require(block.timestamp >= validAfter, "TransferAuthorize: not yet valid");
|
|
119
|
-
require(block.timestamp <= validBefore, "TransferAuthorize: expired");
|
|
120
|
-
bytes32 structHash = keccak256(
|
|
121
|
-
abi.encode(
|
|
122
|
-
APPROVE_TYPEHASH,
|
|
123
|
-
from,
|
|
124
|
-
to,
|
|
125
|
-
value,
|
|
126
|
-
validAfter,
|
|
127
|
-
validBefore,
|
|
128
|
-
nonce
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
signer = ECDSA.recover(_hashTypedDataV4(structHash), signature);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/// @dev Verify an EIP-712 typed signature for BurnWithAuthorize and return the recovered signer
|
|
76
|
+
/// @dev Verify an EIP-712 typed signature (auth) for BurnWithAuthorize and return the recovered signer
|
|
135
77
|
function _verifyBurn(
|
|
136
78
|
address from,
|
|
137
|
-
// address to,
|
|
138
79
|
uint256 value,
|
|
139
|
-
uint256
|
|
140
|
-
uint256
|
|
80
|
+
uint256 createTime,
|
|
81
|
+
uint256 expireTime,
|
|
141
82
|
bytes32 nonce,
|
|
142
|
-
bytes calldata
|
|
143
|
-
) internal
|
|
144
|
-
require(block.timestamp >=
|
|
145
|
-
require(block.timestamp <=
|
|
83
|
+
bytes calldata auth
|
|
84
|
+
) internal returns (address signer) {
|
|
85
|
+
require(block.timestamp >= createTime, "TransferAuthorize: not yet valid");
|
|
86
|
+
require(block.timestamp <= expireTime, "TransferAuthorize: expired");
|
|
146
87
|
bytes32 structHash = keccak256(
|
|
147
88
|
abi.encode(
|
|
148
89
|
BURN_TYPEHASH,
|
|
149
90
|
from,
|
|
150
|
-
// to,
|
|
151
91
|
value,
|
|
152
|
-
|
|
153
|
-
|
|
92
|
+
createTime,
|
|
93
|
+
expireTime,
|
|
154
94
|
nonce
|
|
155
95
|
)
|
|
156
96
|
);
|
|
157
|
-
signer = ECDSA.recover(_hashTypedDataV4(structHash),
|
|
97
|
+
signer = ECDSA.recover(_hashTypedDataV4(structHash), auth);
|
|
98
|
+
emit BurnWithAuthorize(msg.sender, from, value, createTime, expireTime, nonce, auth);
|
|
158
99
|
}
|
|
159
100
|
}
|
|
@@ -10,7 +10,6 @@ import "@openzeppelin/contracts/access/Ownable.sol";
|
|
|
10
10
|
/// @notice ERC20 extension that supports EIP-712 based `transferWithAuthorize` and `receiveWithAuthorize` flows
|
|
11
11
|
/// @dev `receiveWithAuthorize` restricts the caller to the `to` address (recipient submits the proof). `transferWithAuthorize` is open to relayers.
|
|
12
12
|
abstract contract ERC20xTransferWithAuthorize is ERC20, TransferAuthorize, ReentrancyGuard, Ownable {
|
|
13
|
-
|
|
14
13
|
constructor(
|
|
15
14
|
string memory name,
|
|
16
15
|
string memory symbol,
|
|
@@ -45,83 +44,30 @@ abstract contract ERC20xTransferWithAuthorize is ERC20, TransferAuthorize, Reent
|
|
|
45
44
|
nonce,
|
|
46
45
|
auth
|
|
47
46
|
);
|
|
48
|
-
require(signer == from, "
|
|
47
|
+
require(signer == from, "transferWithAuthorize: invalid signature");
|
|
49
48
|
_useAuthorize(from, nonce);
|
|
50
49
|
_transfer(from, to, value);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
54
|
-
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
55
|
-
function transferFromWithAuthorize(
|
|
56
|
-
address from,
|
|
57
|
-
address to,
|
|
58
|
-
uint256 value,
|
|
59
|
-
uint256 validAfter,
|
|
60
|
-
uint256 validBefore,
|
|
61
|
-
bytes32 nonce,
|
|
62
|
-
bytes calldata signature
|
|
63
|
-
) external override nonReentrant {
|
|
64
|
-
address signer = _verifyTransferFrom(
|
|
65
|
-
from,
|
|
66
|
-
to,
|
|
67
|
-
value,
|
|
68
|
-
validAfter,
|
|
69
|
-
validBefore,
|
|
70
|
-
nonce,
|
|
71
|
-
signature
|
|
72
|
-
);
|
|
73
|
-
require(signer == from, "ERC20TransferAuthorize: invalid signature");
|
|
74
|
-
_useAuthorize(from, nonce);
|
|
75
|
-
_spendAllowance(from, to, value);
|
|
76
|
-
_transfer(from, to, value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
80
|
-
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
81
|
-
function approveWithAuthorize(
|
|
82
|
-
address from,
|
|
83
|
-
address to,
|
|
84
|
-
uint256 value,
|
|
85
|
-
uint256 validAfter,
|
|
86
|
-
uint256 validBefore,
|
|
87
|
-
bytes32 nonce,
|
|
88
|
-
bytes calldata signature
|
|
89
|
-
) external override nonReentrant {
|
|
90
|
-
address signer = _verifyApprove(
|
|
91
|
-
from,
|
|
92
|
-
to,
|
|
93
|
-
value,
|
|
94
|
-
validAfter,
|
|
95
|
-
validBefore,
|
|
96
|
-
nonce,
|
|
97
|
-
signature
|
|
98
|
-
);
|
|
99
|
-
require(signer == from, "ERC20TransferAuthorize: invalid signature");
|
|
100
|
-
_useAuthorize(from, nonce);
|
|
101
|
-
_approve(from, to, value);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
52
|
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
105
53
|
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
106
54
|
function burnWithAuthorize(
|
|
107
55
|
address from,
|
|
108
|
-
// address to,
|
|
109
56
|
uint256 value,
|
|
110
|
-
uint256
|
|
111
|
-
uint256
|
|
57
|
+
uint256 createTime,
|
|
58
|
+
uint256 expireTime,
|
|
112
59
|
bytes32 nonce,
|
|
113
|
-
bytes calldata
|
|
60
|
+
bytes calldata auth
|
|
114
61
|
) external override nonReentrant {
|
|
115
62
|
address signer = _verifyBurn(
|
|
116
63
|
from,
|
|
117
|
-
// to,
|
|
118
64
|
value,
|
|
119
|
-
|
|
120
|
-
|
|
65
|
+
createTime,
|
|
66
|
+
expireTime,
|
|
121
67
|
nonce,
|
|
122
|
-
|
|
68
|
+
auth
|
|
123
69
|
);
|
|
124
|
-
require(signer == from, "
|
|
70
|
+
require(signer == from, "burnWithAuthorize: invalid signature");
|
|
125
71
|
_useAuthorize(from, nonce);
|
|
126
72
|
_burn(from, value);
|
|
127
73
|
}
|