-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathIPermit2.sol
More file actions
192 lines (160 loc) · 6.26 KB
/
IPermit2.sol
File metadata and controls
192 lines (160 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title IPermit2
/// @notice Interface for Uniswap's Permit2 contract
/// @dev Enables gasless token approvals via signatures
interface IPermit2 {
// ============================================================
// STRUCTS
// ============================================================
/// @notice Token and amount for a single permit
struct TokenPermissions {
address token;
uint256 amount;
}
/// @notice Data for a single token permit
struct PermitDetails {
address token;
uint160 amount;
uint48 expiration;
uint48 nonce;
}
/// @notice Data for a batch of token permits
struct PermitBatch {
PermitDetails[] details;
address spender;
uint256 sigDeadline;
}
/// @notice A single permit for transferFrom
struct PermitSingle {
PermitDetails details;
address spender;
uint256 sigDeadline;
}
/// @notice Transfer details for permitTransferFrom
struct SignatureTransferDetails {
address to;
uint256 requestedAmount;
}
/// @notice Permit data for signature-based transfers
struct PermitTransferFrom {
TokenPermissions permitted;
uint256 nonce;
uint256 deadline;
}
/// @notice Batch permit data for signature-based transfers
struct PermitBatchTransferFrom {
TokenPermissions[] permitted;
uint256 nonce;
uint256 deadline;
}
/// @notice Allowance data stored in Permit2
struct PackedAllowance {
uint160 amount;
uint48 expiration;
uint48 nonce;
}
// ============================================================
// ERRORS
// ============================================================
error AllowanceExpired(uint256 deadline);
error InsufficientAllowance(uint256 amount);
error InvalidAmount(uint256 maxAmount);
error InvalidContractSignature();
error InvalidNonce();
error InvalidSignature();
error InvalidSignatureLength();
error InvalidSigner();
error LengthMismatch();
error SignatureExpired(uint256 signatureDeadline);
// ============================================================
// EVENTS
// ============================================================
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
event Lockdown(address indexed owner, address token, address spender);
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
// ============================================================
// ALLOWANCE TRANSFER FUNCTIONS
// ============================================================
/// @notice Approve a spender to access a token
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender via signature
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender for multiple tokens via signature
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer tokens using allowance
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Batch transfer using allowances
struct AllowanceTransferDetails {
address from;
address to;
uint160 amount;
address token;
}
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Get allowance info
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
// ============================================================
// SIGNATURE TRANSFER FUNCTIONS
// ============================================================
/// @notice Transfer tokens via signature (one-time use nonce)
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Batch transfer tokens via signature
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfer with witness data
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Batch transfer with witness data
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
// ============================================================
// NONCE MANAGEMENT
// ============================================================
/// @notice Invalidate nonces to cancel pending permits
function invalidateNonces(address token, address spender, uint48 newNonce) external;
/// @notice Revoke all allowances for a token/spender pair
function lockdown(TokenPermissions[] calldata approvals) external;
// ============================================================
// VIEW FUNCTIONS
// ============================================================
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice Check if a nonce has been used (for signature transfers)
function nonceBitmap(address owner, uint256 wordPos) external view returns (uint256);
}