Skip to content

Commit 63c1a0f

Browse files
authored
refactor!: Optional LSP1 Notification on revokeOperator(..) (#763)
* refactor!: make notification optional in revokeOperator * test: adjust the tests accordingly * docs: generate docs * chore: add override keyword * chore: fix lsp7compatibleERC20 * refactor: include authorization status bool in lsp1 data in LSP8 * refactor!: allow increase allowance only when allowance > 0 * test: adjust the tests accoridngly * docs: generate docs * docs: generate docs
1 parent d0543fb commit 63c1a0f

31 files changed

+753
-853
lines changed

constants.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export const INTERFACE_IDS = {
2929
LSP1UniversalReceiver: '0x6bb56a14',
3030
LSP1UniversalReceiverDelegate: '0xa245bbda',
3131
LSP6KeyManager: '0x23f34c62',
32-
LSP7DigitalAsset: '0x05519512',
33-
LSP8IdentifiableDigitalAsset: '0x1ae9ba1f',
32+
LSP7DigitalAsset: '0xdaa746b7',
33+
LSP8IdentifiableDigitalAsset: '0x30dc5278',
3434
LSP9Vault: '0x28af17e6',
3535
LSP11BasicSocialRecovery: '0x049a28f1',
3636
LSP14Ownable2Step: '0x94be5999',

contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol

+60
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
5050
* @dev Emitted when `tokenOwner` disables `operator` for `amount` tokens and set its {`authorizedAmountFor(...)`} to `0`.
5151
* @param operator The address revoked from operating
5252
* @param tokenOwner The token owner
53+
* @param notified Bool indicating whether the operator has been notified or not
5354
* @param operatorNotificationData The data to notify the operator about via LSP1.
5455
*/
5556
event RevokedOperator(
5657
address indexed operator,
5758
address indexed tokenOwner,
59+
bool notified,
5860
bytes operatorNotificationData
5961
);
6062

@@ -101,6 +103,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
101103

102104
/**
103105
* @dev Sets an `amount` of tokens that an `operator` has access from the caller's balance (allowance). See {authorizedAmountFor}.
106+
* Notify the operator based on the LSP1-UniversalReceiver standard
104107
*
105108
* @param operator The address to authorize as an operator.
106109
* @param amount The allowance amount of tokens operator has access to.
@@ -123,6 +126,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
123126
* on behalf of the token owner (the caller of the function `msg.sender`). See also {authorizedAmountFor}.
124127
*
125128
* @param operator The address to revoke as an operator.
129+
* @param notify Boolean indicating whether to notify the operator or not
126130
* @param operatorNotificationData The data to notify the operator about via LSP1.
127131
*
128132
* @custom:requirements
@@ -133,6 +137,62 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
133137
*/
134138
function revokeOperator(
135139
address operator,
140+
bool notify,
141+
bytes memory operatorNotificationData
142+
) external;
143+
144+
/**
145+
* @custom:info This function in the LSP7 contract can be used as a prevention mechanism
146+
* against double spending allowance vulnerability.
147+
*
148+
* @notice Increase the allowance of `operator` by +`addedAmount`
149+
*
150+
* @dev Atomically increases the allowance granted to `operator` by the caller.
151+
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
152+
* for the double spending allowance problem.
153+
* Notify the operator based on the LSP1-UniversalReceiver standard
154+
*
155+
* @param operator The operator to increase the allowance for `msg.sender`
156+
* @param addedAmount The additional amount to add on top of the current operator's allowance
157+
*
158+
* @custom:requirements
159+
* - `operator` cannot be the same address as `msg.sender`
160+
* - `operator` cannot be the zero address.
161+
*
162+
* @custom:events {AuthorizedOperator} indicating the updated allowance
163+
*/
164+
function increaseAllowance(
165+
address operator,
166+
uint256 addedAmount,
167+
bytes memory operatorNotificationData
168+
) external;
169+
170+
/**
171+
* @custom:info This function in the LSP7 contract can be used as a prevention mechanism
172+
* against the double spending allowance vulnerability.
173+
*
174+
* @notice Decrease the allowance of `operator` by -`subtractedAmount`
175+
*
176+
* @dev Atomically decreases the allowance granted to `operator` by the caller.
177+
* This is an alternative approach to {authorizeOperator} that can be used as a mitigation
178+
* for the double spending allowance problem.
179+
* Notify the operator based on the LSP1-UniversalReceiver standard
180+
*
181+
* @custom:events
182+
* - {AuthorizedOperator} event indicating the updated allowance after decreasing it.
183+
* - {RevokeOperator} event if `subtractedAmount` is the full allowance,
184+
* indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
185+
*
186+
* @param operator The operator to decrease allowance for `msg.sender`
187+
* @param subtractedAmount The amount to decrease by in the operator's allowance.
188+
*
189+
* @custom:requirements
190+
* - `operator` cannot be the zero address.
191+
* - `operator` must have allowance for the caller of at least `subtractedAmount`.
192+
*/
193+
function decreaseAllowance(
194+
address operator,
195+
uint256 subtractedAmount,
136196
bytes memory operatorNotificationData
137197
) external;
138198

contracts/LSP7DigitalAsset/LSP7Constants.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.4;
33

44
// --- ERC165 interface ids
5-
bytes4 constant _INTERFACEID_LSP7 = 0x05519512;
5+
bytes4 constant _INTERFACEID_LSP7 = 0xdaa746b7;
66

77
// --- Token Hooks
88

0 commit comments

Comments
 (0)