t-isol 0.0.7 → 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,19 +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
|
|
15
|
-
|
|
16
|
-
/// @notice Emitted when a transferFrom with authorization is executed
|
|
17
|
-
event TransferFromWithAuthorize(address indexed from, address indexed to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 indexed nonce);
|
|
18
|
-
|
|
19
|
-
/// @notice Emitted when a approve with authorization is executed
|
|
20
|
-
event ApproveWithAuthorize(address indexed from, address indexed to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 indexed nonce);
|
|
14
|
+
event TransferWithAuthorize(address sender, address from, address to, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth);
|
|
21
15
|
|
|
22
16
|
/// @notice Emitted when a burn with authorization is executed
|
|
23
|
-
event BurnWithAuthorize(address
|
|
17
|
+
event BurnWithAuthorize(address sender, address from, uint256 value, uint256 createTime, uint256 expireTime, bytes32 nonce, bytes auth);
|
|
24
18
|
|
|
25
19
|
/// @notice Returns whether a nonce has been used for a given authorizer
|
|
26
20
|
/// @param authorizer the account that signed the authorization
|
|
@@ -41,30 +35,6 @@ interface ITransferAuthorize {
|
|
|
41
35
|
bytes32 nonce,
|
|
42
36
|
bytes calldata auth
|
|
43
37
|
) external;
|
|
44
|
-
|
|
45
|
-
// ++
|
|
46
|
-
/// @notice Execute a "transfer with authorization" - typically any relayer may submit
|
|
47
|
-
function transferFromWithAuthorize(
|
|
48
|
-
address from,
|
|
49
|
-
address to,
|
|
50
|
-
uint256 value,
|
|
51
|
-
uint256 validAfter,
|
|
52
|
-
uint256 validBefore,
|
|
53
|
-
bytes32 nonce,
|
|
54
|
-
bytes calldata signature
|
|
55
|
-
) external;
|
|
56
|
-
|
|
57
|
-
// ++
|
|
58
|
-
/// @notice Execute a "approve with authorization" - typically any relayer may submit
|
|
59
|
-
function approveWithAuthorize(
|
|
60
|
-
address from,
|
|
61
|
-
address to,
|
|
62
|
-
uint256 value,
|
|
63
|
-
uint256 validAfter,
|
|
64
|
-
uint256 validBefore,
|
|
65
|
-
bytes32 nonce,
|
|
66
|
-
bytes calldata signature
|
|
67
|
-
) external;
|
|
68
38
|
|
|
69
39
|
/// @notice Execute a "approve with authorization" - typically any relayer may submit
|
|
70
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(
|
|
@@ -76,84 +70,31 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
|
|
|
76
70
|
)
|
|
77
71
|
);
|
|
78
72
|
signer = ECDSA.recover(_hashTypedDataV4(structHash), auth);
|
|
79
|
-
emit TransferWithAuthorize(from, to, value, createTime, expireTime, nonce, auth);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/// @dev Verify an EIP-712 typed signature for TransferFromWithAuthorize and return the recovered signer
|
|
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);
|
|
73
|
+
emit TransferWithAuthorize(msg.sender, from, to, value, createTime, expireTime, nonce, auth);
|
|
132
74
|
}
|
|
133
75
|
|
|
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,84 +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
|
-
// emit TransferWithAuthorize(from, to, value, createTime, expireTime, nonce, auth);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
55
|
-
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
56
|
-
function transferFromWithAuthorize(
|
|
57
|
-
address from,
|
|
58
|
-
address to,
|
|
59
|
-
uint256 value,
|
|
60
|
-
uint256 validAfter,
|
|
61
|
-
uint256 validBefore,
|
|
62
|
-
bytes32 nonce,
|
|
63
|
-
bytes calldata signature
|
|
64
|
-
) external override nonReentrant {
|
|
65
|
-
address signer = _verifyTransferFrom(
|
|
66
|
-
from,
|
|
67
|
-
to,
|
|
68
|
-
value,
|
|
69
|
-
validAfter,
|
|
70
|
-
validBefore,
|
|
71
|
-
nonce,
|
|
72
|
-
signature
|
|
73
|
-
);
|
|
74
|
-
require(signer == from, "ERC20TransferAuthorize: invalid signature");
|
|
75
|
-
_useAuthorize(from, nonce);
|
|
76
|
-
_spendAllowance(from, to, value);
|
|
77
|
-
_transfer(from, to, value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
81
|
-
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
82
|
-
function approveWithAuthorize(
|
|
83
|
-
address from,
|
|
84
|
-
address to,
|
|
85
|
-
uint256 value,
|
|
86
|
-
uint256 validAfter,
|
|
87
|
-
uint256 validBefore,
|
|
88
|
-
bytes32 nonce,
|
|
89
|
-
bytes calldata signature
|
|
90
|
-
) external override nonReentrant {
|
|
91
|
-
address signer = _verifyApprove(
|
|
92
|
-
from,
|
|
93
|
-
to,
|
|
94
|
-
value,
|
|
95
|
-
validAfter,
|
|
96
|
-
validBefore,
|
|
97
|
-
nonce,
|
|
98
|
-
signature
|
|
99
|
-
);
|
|
100
|
-
require(signer == from, "ERC20TransferAuthorize: invalid signature");
|
|
101
|
-
_useAuthorize(from, nonce);
|
|
102
|
-
_approve(from, to, value);
|
|
103
50
|
}
|
|
104
51
|
|
|
105
52
|
/// @notice Relayer-triggered transfer using an off-chain signature by `from`.
|
|
106
53
|
/// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
|
|
107
54
|
function burnWithAuthorize(
|
|
108
55
|
address from,
|
|
109
|
-
// address to,
|
|
110
56
|
uint256 value,
|
|
111
|
-
uint256
|
|
112
|
-
uint256
|
|
57
|
+
uint256 createTime,
|
|
58
|
+
uint256 expireTime,
|
|
113
59
|
bytes32 nonce,
|
|
114
|
-
bytes calldata
|
|
60
|
+
bytes calldata auth
|
|
115
61
|
) external override nonReentrant {
|
|
116
62
|
address signer = _verifyBurn(
|
|
117
63
|
from,
|
|
118
|
-
// to,
|
|
119
64
|
value,
|
|
120
|
-
|
|
121
|
-
|
|
65
|
+
createTime,
|
|
66
|
+
expireTime,
|
|
122
67
|
nonce,
|
|
123
|
-
|
|
68
|
+
auth
|
|
124
69
|
);
|
|
125
|
-
require(signer == from, "
|
|
70
|
+
require(signer == from, "burnWithAuthorize: invalid signature");
|
|
126
71
|
_useAuthorize(from, nonce);
|
|
127
72
|
_burn(from, value);
|
|
128
73
|
}
|