Skip to content

Commit a12b30c

Browse files
xaler5ernestognw
andauthored
Update IERC7943, ERC20uRWA and ERC20Restricted (#227)
Co-authored-by: ernestognw <ernestognw@gmail.com>
1 parent 813f155 commit a12b30c

6 files changed

Lines changed: 151 additions & 119 deletions

File tree

contracts/interfaces/IERC7943.sol

Lines changed: 103 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,57 @@ interface IERC7943Fungible is IERC165 {
1111
/// @param amount The amount seized.
1212
event ForcedTransfer(address indexed from, address indexed to, uint256 amount);
1313

14-
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen `amount` of tokens for `user`.
15-
/// @param user The address of the user whose tokens are being frozen.
14+
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen `amount` of tokens for `account`.
15+
/// @param account The address of the account whose tokens are being frozen.
1616
/// @param amount The amount of tokens frozen after the change.
17-
event Frozen(address indexed user, uint256 amount);
17+
event Frozen(address indexed account, uint256 amount);
1818

19-
/// @notice Error reverted when a user is not allowed to interact.
20-
/// @param account The address of the user which is not allowed for interactions.
21-
error ERC7943NotAllowedUser(address account);
19+
/// @notice Error reverted when an account is not allowed to transact.
20+
/// @param account The address of the account which is not allowed for transfers.
21+
error ERC7943CannotTransact(address account);
2222

23-
/// @notice Error reverted when a transfer is attempted from `user` with an `amount` less or equal than its balance, but greater than its unfrozen balance.
24-
/// @param user The address holding the tokens.
23+
/// @notice Error reverted when a transfer is not allowed according to internal rules.
24+
/// @param from The address from which tokens are being sent.
25+
/// @param to The address to which tokens are being sent.
26+
/// @param amount The amount sent.
27+
error ERC7943CannotTransfer(address from, address to, uint256 amount);
28+
29+
/// @notice Error reverted when a transfer is attempted from `account` with an `amount` less than or equal to its balance, but greater than its unfrozen balance.
30+
/// @param account The address holding the tokens.
2531
/// @param amount The amount being transferred.
2632
/// @param unfrozen The amount of tokens that are unfrozen and available to transfer.
27-
error ERC7943InsufficientUnfrozenBalance(address user, uint256 amount, uint256 unfrozen);
33+
error ERC7943InsufficientUnfrozenBalance(address account, uint256 amount, uint256 unfrozen);
2834

2935
/// @notice Takes tokens from one address and transfers them to another.
3036
/// @dev Requires specific authorization. Used for regulatory compliance or recovery scenarios.
3137
/// @param from The address from which `amount` is taken.
3238
/// @param to The address that receives `amount`.
3339
/// @param amount The amount to force transfer.
34-
function forcedTransfer(address from, address to, uint256 amount) external;
40+
/// @return result True if the transfer executed correctly, false otherwise.
41+
function forcedTransfer(address from, address to, uint256 amount) external returns (bool result);
3542

36-
/// @notice Changes the frozen status of `amount` tokens belonging to a `user`.
43+
/// @notice Changes the frozen status of `amount` tokens belonging to `account`.
3744
/// This overwrites the current value, similar to an `approve` function.
38-
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the user.
39-
/// @param user The address of the user whose tokens are to be frozen/unfrozen.
40-
/// @param amount The amount of tokens to freeze/unfreeze.
41-
function setFrozenTokens(address user, uint256 amount) external;
45+
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the account.
46+
/// @param account The address of the account whose tokens are to be frozen.
47+
/// @param amount The amount of tokens to freeze. It can be greater than account balance.
48+
/// @return result True if the freezing executed correctly, false otherwise.
49+
function setFrozenTokens(address account, uint256 amount) external returns (bool result);
4250

43-
/// @notice Checks if a specific user is allowed to interact according to token rules.
51+
/// @notice Checks if a specific account is allowed to transact according to token rules.
4452
/// @dev This is often used for allowlist/KYC/KYB/AML checks.
45-
/// @param user The address to check.
46-
/// @return allowed True if the user is allowed, false otherwise.
47-
function isUserAllowed(address user) external view returns (bool allowed);
53+
/// @param account The address to check.
54+
/// @return allowed True if the account is allowed, false otherwise.
55+
function canTransact(address account) external view returns (bool allowed);
4856

4957
/// @notice Checks the frozen status/amount.
50-
/// @param user The address of the user.
51-
/// @return amount The amount of tokens currently frozen for `user`.
52-
function getFrozenTokens(address user) external view returns (uint256 amount);
58+
/// @param account The address of the account.
59+
/// @dev It could return an amount higher than the account's balance.
60+
/// @return amount The amount of tokens currently frozen for `account`.
61+
function getFrozenTokens(address account) external view returns (uint256 amount);
5362

5463
/// @notice Checks if a transfer is currently possible according to token rules. It enforces validations on the frozen tokens.
55-
/// @dev This may involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
64+
/// @dev This can involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
5665
/// @param from The address sending tokens.
5766
/// @param to The address receiving tokens.
5867
/// @param amount The amount being transferred.
@@ -68,50 +77,59 @@ interface IERC7943NonFungible is IERC165 {
6877
/// @param tokenId The ID of the token being transferred.
6978
event ForcedTransfer(address indexed from, address indexed to, uint256 indexed tokenId);
7079

71-
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen status of `tokenId` for `user`.
72-
/// @param user The address of the user whose `tokenId` is subjected to freeze/unfreeze.
80+
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen status of `tokenId` for `account`.
81+
/// @param account The address of the account whose `tokenId` is subjected to freeze/unfreeze.
7382
/// @param tokenId The ID of the token subjected to freeze/unfreeze.
7483
/// @param frozenStatus Whether `tokenId` has been frozen or unfrozen.
75-
event Frozen(address indexed user, uint256 indexed tokenId, bool indexed frozenStatus);
84+
event Frozen(address indexed account, uint256 indexed tokenId, bool indexed frozenStatus);
7685

77-
/// @notice Error reverted when a user is not allowed to interact.
78-
/// @param account The address of the user which is not allowed for interactions.
79-
error ERC7943NotAllowedUser(address account);
86+
/// @notice Error reverted when an account is not allowed to transact.
87+
/// @param account The address of the account which is not allowed for transfers.
88+
error ERC7943CannotTransact(address account);
8089

81-
/// @notice Error reverted when a transfer is attempted from `user` with a `tokenId` which has been previously frozen.
82-
/// @param user The address holding the tokens.
83-
/// @param tokenId The ID of the token being frozen.
84-
error ERC7943FrozenTokenId(address user, uint256 tokenId);
90+
/// @notice Error reverted when a transfer is not allowed according to internal rules.
91+
/// @param from The address from which tokens are being sent.
92+
/// @param to The address to which tokens are being sent.
93+
/// @param tokenId The id of the token being sent.
94+
error ERC7943CannotTransfer(address from, address to, uint256 tokenId);
95+
96+
/// @notice Error reverted when a transfer is attempted from `account` with a `tokenId` which has been previously frozen.
97+
/// @param account The address holding the token with `tokenId`.
98+
/// @param tokenId The ID of the token being frozen and unavailable to be transferred.
99+
error ERC7943InsufficientUnfrozenBalance(address account, uint256 tokenId);
85100

86101
/// @notice Takes `tokenId` from one address and transfers it to another.
87102
/// @dev Requires specific authorization. Used for regulatory compliance or recovery scenarios.
88103
/// @param from The address from which `tokenId` is taken.
89104
/// @param to The address that receives `tokenId`.
90105
/// @param tokenId The ID of the token being transferred.
91-
function forcedTransfer(address from, address to, uint256 tokenId) external;
106+
/// @return result True if the transfer executed correctly, false otherwise.
107+
function forcedTransfer(address from, address to, uint256 tokenId) external returns (bool result);
92108

93-
/// @notice Changes the frozen status of `tokenId` belonging to a `user`.
109+
/// @notice Changes the frozen status of `tokenId` belonging to an `account`.
94110
/// This overwrites the current value, similar to an `approve` function.
95-
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the user.
96-
/// @param user The address of the user whose tokens are to be frozen/unfrozen.
97-
/// @param tokenId The ID of the token to freeze/unfreeze.
98-
/// @param frozenStatus whether `tokenId` is being frozen or not.
99-
function setFrozenTokens(address user, uint256 tokenId, bool frozenStatus) external;
100-
101-
/// @notice Checks if a specific user is allowed to interact according to token rules.
111+
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the account.
112+
/// @param account The address of the account whose tokens are to be frozen.
113+
/// @param tokenId The ID of the token to freeze.
114+
/// @param frozenStatus Whether `tokenId` is being frozen or not.
115+
/// @return result True if the freezing executed correctly, false otherwise.
116+
function setFrozenTokens(address account, uint256 tokenId, bool frozenStatus) external returns (bool result);
117+
118+
/// @notice Checks if a specific account is allowed to transact according to token rules.
102119
/// @dev This is often used for allowlist/KYC/KYB/AML checks.
103-
/// @param user The address to check.
104-
/// @return allowed True if the user is allowed, false otherwise.
105-
function isUserAllowed(address user) external view returns (bool allowed);
120+
/// @param account The address to check.
121+
/// @return allowed True if the account is allowed, false otherwise.
122+
function canTransact(address account) external view returns (bool allowed);
106123

107124
/// @notice Checks the frozen status of a specific `tokenId`.
108-
/// @param user The address of the user.
125+
/// @dev It could return true even if account does not hold the token.
126+
/// @param account The address of the account.
109127
/// @param tokenId The ID of the token.
110-
/// @return frozenStatus Whether `tokenId` is currently frozen for `user`.
111-
function getFrozenTokens(address user, uint256 tokenId) external view returns (bool frozenStatus);
128+
/// @return frozenStatus Whether `tokenId` is currently frozen for `account`.
129+
function getFrozenTokens(address account, uint256 tokenId) external view returns (bool frozenStatus);
112130

113131
/// @notice Checks if a transfer is currently possible according to token rules. It enforces validations on the frozen tokens.
114-
/// @dev This may involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
132+
/// @dev This can involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
115133
/// @param from The address sending tokens.
116134
/// @param to The address receiving tokens.
117135
/// @param tokenId The ID of the token being transferred.
@@ -128,53 +146,63 @@ interface IERC7943MultiToken is IERC165 {
128146
/// @param amount The amount seized.
129147
event ForcedTransfer(address indexed from, address indexed to, uint256 indexed tokenId, uint256 amount);
130148

131-
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen `amount` of `tokenId` tokens for `user`.
132-
/// @param user The address of the user whose tokens are being frozen.
149+
/// @notice Emitted when `setFrozenTokens` is called, changing the frozen `amount` of `tokenId` tokens for `account`.
150+
/// @param account The address of the account whose tokens are being frozen.
133151
/// @param tokenId The ID of the token being frozen.
134152
/// @param amount The amount of tokens frozen after the change.
135-
event Frozen(address indexed user, uint256 indexed tokenId, uint256 amount);
153+
event Frozen(address indexed account, uint256 indexed tokenId, uint256 amount);
136154

137-
/// @notice Error reverted when a user is not allowed to interact.
138-
/// @param account The address of the user which is not allowed for interactions.
139-
error ERC7943NotAllowedUser(address account);
155+
/// @notice Error reverted when an account is not allowed to transact.
156+
/// @param account The address of the account which is not allowed for transfers.
157+
error ERC7943CannotTransact(address account);
140158

141-
/// @notice Error reverted when a transfer is attempted from `user` with an `amount` of `tokenId` less or equal than its balance, but greater than its unfrozen balance.
142-
/// @param user The address holding the tokens.
159+
/// @notice Error reverted when a transfer is not allowed according to internal rules.
160+
/// @param from The address from which tokens are being sent.
161+
/// @param to The address to which tokens are being sent.
162+
/// @param tokenId The id of the token being sent.
163+
/// @param amount The amount sent.
164+
error ERC7943CannotTransfer(address from, address to, uint256 tokenId, uint256 amount);
165+
166+
/// @notice Error reverted when a transfer is attempted from `account` with an `amount` of `tokenId` less than or equal to its balance, but greater than its unfrozen balance.
167+
/// @param account The address holding the `amount` of `tokenId` tokens.
143168
/// @param tokenId The ID of the token being transferred.
144-
/// @param amount The amount being transferred.
169+
/// @param amount The amount of `tokenId` tokens being transferred.
145170
/// @param unfrozen The amount of tokens that are unfrozen and available to transfer.
146-
error ERC7943InsufficientUnfrozenBalance(address user, uint256 tokenId, uint256 amount, uint256 unfrozen);
171+
error ERC7943InsufficientUnfrozenBalance(address account, uint256 tokenId, uint256 amount, uint256 unfrozen);
147172

148173
/// @notice Takes tokens from one address and transfers them to another.
149174
/// @dev Requires specific authorization. Used for regulatory compliance or recovery scenarios.
150175
/// @param from The address from which `amount` is taken.
151176
/// @param to The address that receives `amount`.
152177
/// @param tokenId The ID of the token being transferred.
153178
/// @param amount The amount to force transfer.
154-
function forcedTransfer(address from, address to, uint256 tokenId, uint256 amount) external;
179+
/// @return result True if the transfer executed correctly, false otherwise.
180+
function forcedTransfer(address from, address to, uint256 tokenId, uint256 amount) external returns (bool result);
155181

156-
/// @notice Changes the frozen status of `amount` of `tokenId` tokens belonging to a `user`.
182+
/// @notice Changes the frozen status of `amount` of `tokenId` tokens belonging to an `account`.
157183
/// This overwrites the current value, similar to an `approve` function.
158-
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the user.
159-
/// @param user The address of the user whose tokens are to be frozen/unfrozen.
160-
/// @param tokenId The ID of the token to freeze/unfreeze.
161-
/// @param amount The amount of tokens to freeze/unfreeze.
162-
function setFrozenTokens(address user, uint256 tokenId, uint256 amount) external;
163-
164-
/// @notice Checks if a specific user is allowed to interact according to token rules.
184+
/// @dev Requires specific authorization. Frozen tokens cannot be transferred by the account.
185+
/// @param account The address of the account whose tokens are to be frozen.
186+
/// @param tokenId The ID of the token to freeze.
187+
/// @param amount The amount of tokens to freeze. It can be greater than account balance.
188+
/// @return result True if the freezing executed correctly, false otherwise.
189+
function setFrozenTokens(address account, uint256 tokenId, uint256 amount) external returns (bool result);
190+
191+
/// @notice Checks if a specific account is allowed to transact according to token rules.
165192
/// @dev This is often used for allowlist/KYC/KYB/AML checks.
166-
/// @param user The address to check.
167-
/// @return allowed True if the user is allowed, false otherwise.
168-
function isUserAllowed(address user) external view returns (bool allowed);
193+
/// @param account The address to check.
194+
/// @return allowed True if the account is allowed, false otherwise.
195+
function canTransact(address account) external view returns (bool allowed);
169196

170197
/// @notice Checks the frozen status/amount of a specific `tokenId`.
171-
/// @param user The address of the user.
198+
/// @dev It could return an amount higher than the account's balance.
199+
/// @param account The address of the account.
172200
/// @param tokenId The ID of the token.
173-
/// @return amount The amount of `tokenId` tokens currently frozen for `user`.
174-
function getFrozenTokens(address user, uint256 tokenId) external view returns (uint256 amount);
201+
/// @return amount The amount of `tokenId` tokens currently frozen for `account`.
202+
function getFrozenTokens(address account, uint256 tokenId) external view returns (uint256 amount);
175203

176204
/// @notice Checks if a transfer is currently possible according to token rules. It enforces validations on the frozen tokens.
177-
/// @dev This may involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
205+
/// @dev This can involve checks like allowlists, blocklists, transfer limits and other policy-defined restrictions.
178206
/// @param from The address sending tokens.
179207
/// @param to The address receiving tokens.
180208
/// @param tokenId The ID of the token being transferred.

contracts/token/ERC20/extensions/ERC20Freezable.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ abstract contract ERC20Freezable is ERC20 {
2020
/// @dev Frozen amount of tokens per address.
2121
mapping(address account => uint256) private _frozenBalances;
2222

23-
/// @dev The operation failed because the user has insufficient unfrozen balance.
24-
error ERC20InsufficientUnfrozenBalance(address user, uint256 needed, uint256 available);
23+
/// @dev The operation failed because the account has insufficient unfrozen balance.
24+
error ERC20InsufficientUnfrozenBalance(address account, uint256 needed, uint256 available);
2525

2626
/// @dev Returns the frozen balance of an account.
2727
function frozen(address account) public view virtual returns (uint256) {
@@ -34,10 +34,10 @@ abstract contract ERC20Freezable is ERC20 {
3434
return success ? unfrozen : 0;
3535
}
3636

37-
/// @dev Internal function to set the frozen token amount for a user.
38-
function _setFrozen(address user, uint256 amount) internal virtual {
39-
_frozenBalances[user] = amount;
40-
emit IERC7943Fungible.Frozen(user, amount);
37+
/// @dev Internal function to set the frozen token amount for a account.
38+
function _setFrozen(address account, uint256 amount) internal virtual {
39+
_frozenBalances[account] = amount;
40+
emit IERC7943Fungible.Frozen(account, amount);
4141
}
4242

4343
/**

0 commit comments

Comments
 (0)