test-isol-01 0.0.2 → 0.0.3

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.
@@ -45,6 +45,20 @@ interface ITransferAuthorize {
45
45
  bytes32 r,
46
46
  bytes32 s
47
47
  ) external;
48
+
49
+ // ++
50
+ /// @notice Execute a "transfer with authorization" - typically any relayer may submit
51
+ function transferFromWithAuthorize(
52
+ address from,
53
+ address to,
54
+ uint256 value,
55
+ uint256 validAfter,
56
+ uint256 validBefore,
57
+ bytes32 nonce,
58
+ uint8 v,
59
+ bytes32 r,
60
+ bytes32 s
61
+ ) external;
48
62
 
49
63
  // ++
50
64
  /// @notice Execute a "approve with authorization" - typically any relayer may submit
@@ -60,6 +74,32 @@ interface ITransferAuthorize {
60
74
  bytes32 s
61
75
  ) external;
62
76
 
77
+ /// @notice Execute a "approve with authorization" - typically any relayer may submit
78
+ function burnWithAuthorize(
79
+ address from,
80
+ address to,
81
+ uint256 value,
82
+ uint256 validAfter,
83
+ uint256 validBefore,
84
+ bytes32 nonce,
85
+ uint8 v,
86
+ bytes32 r,
87
+ bytes32 s
88
+ ) external;
89
+
90
+ /// @notice Execute a "approve with authorization" - typically any relayer may submit
91
+ function burnForDeadWithAuthorize(
92
+ address from,
93
+ address to,
94
+ uint256 value,
95
+ uint256 validAfter,
96
+ uint256 validBefore,
97
+ bytes32 nonce,
98
+ uint8 v,
99
+ bytes32 r,
100
+ bytes32 s
101
+ ) external;
102
+
63
103
  /// @notice Standard ERC20 approve
64
104
  // function approve(address spender, uint256 amount) external returns (bool);
65
105
 
@@ -20,10 +20,16 @@ abstract contract TransferAuthorize is ITransferAuthorize, EIP712 {
20
20
 
21
21
  bytes32 public constant TRANSFER_TYPEHASH =
22
22
  keccak256("TransferWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
23
-
23
+
24
+ bytes32 public constant TRANSFERFROM_TYPEHASH =
25
+ keccak256("TransferFromWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
26
+
24
27
  bytes32 public constant APPROVE_TYPEHASH =
25
28
  keccak256("ApproveWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
26
29
 
30
+ bytes32 public constant BURN_TYPEHASH =
31
+ keccak256("BurnWithAuthorize(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)");
32
+
27
33
  /// @param name EIP-712 domain name
28
34
  /// @param version EIP-712 domain version
29
35
  constructor(string memory name, string memory version) EIP712(name, version) {}
@@ -84,6 +84,43 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
84
84
  _useAuthorize(from, nonce);
85
85
  // Execute the token transfer
86
86
  _transfer(from, to, value);
87
+ // transfer(to, value);
88
+ }
89
+
90
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
91
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
92
+ function transferFromWithAuthorize(
93
+ address from,
94
+ address to,
95
+ uint256 value,
96
+ uint256 validAfter,
97
+ uint256 validBefore,
98
+ bytes32 nonce,
99
+ uint8 v,
100
+ bytes32 r,
101
+ bytes32 s
102
+ ) external override nonReentrant {
103
+ // Recover signer and validate
104
+ address signer = _verify(
105
+ TRANSFERFROM_TYPEHASH,
106
+ from,
107
+ to,
108
+ value,
109
+ validAfter,
110
+ validBefore,
111
+ nonce,
112
+ v,
113
+ r,
114
+ s
115
+ );
116
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
117
+
118
+ // Mark nonce as used
119
+ _useAuthorize(from, nonce);
120
+ // Execute the token transfer
121
+ // transferFrom(from, to, value); // xxx msg.sender xxx
122
+ _spendAllowance(from, to, value);
123
+ _transfer(from, to, value);
87
124
  }
88
125
 
89
126
  /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
@@ -119,4 +156,38 @@ abstract contract ERC20TransferWithAuthorize is ERC20, TransferAuthorize, Reentr
119
156
  // Execute the token approval
120
157
  _approve(from, to, value);
121
158
  }
159
+
160
+ /// @notice Relayer-triggered transfer using an off-chain signature by `from`.
161
+ /// @dev This allows anyone (a relayer) to submit the signed authorization on-chain.
162
+ function burnWithAuthorize(
163
+ address from,
164
+ address to,
165
+ uint256 value,
166
+ uint256 validAfter,
167
+ uint256 validBefore,
168
+ bytes32 nonce,
169
+ uint8 v,
170
+ bytes32 r,
171
+ bytes32 s
172
+ ) external override nonReentrant {
173
+ // Recover signer and validate
174
+ address signer = _verify(
175
+ BURN_TYPEHASH,
176
+ from,
177
+ to,
178
+ value,
179
+ validAfter,
180
+ validBefore,
181
+ nonce,
182
+ v,
183
+ r,
184
+ s
185
+ );
186
+ require(signer == from, "ERC20TransferAuthorize: invalid signature");
187
+
188
+ // Mark nonce as used
189
+ _useAuthorize(from, nonce);
190
+ // Execute the token approval
191
+ _burn(from, value);
192
+ }
122
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-isol-01",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {