Skip to content

Commit

Permalink
docs: update LSP1 natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Jul 23, 2023
1 parent 32ad32f commit 92f894b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ abstract contract LSP0ERC725AccountCore is
}

/**
* @notice Achieves the goal of [LSP1-UniversalReceiver] by allowing the account to be notified about incoming/outgoing
* @notice Achieves the goal of [LSP-1-UniversalReceiver] by allowing the account to be notified about incoming/outgoing
* transactions and enabling reactions to these actions.
*
* The reaction is achieved by having two external contracts (UniversalReceiverDelegates) that react on the whole transaction
Expand Down
33 changes: 22 additions & 11 deletions contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@ pragma solidity ^0.8.4;

/**
* @title Interface of the LSP1 - Universal Receiver standard, an entry function for a contract to receive arbitrary information.
* @dev LSP1UniversalReceiver allows to receive arbitrary messages and to be informed when assets are sent or received
* @dev LSP1UniversalReceiver allows to receive arbitrary messages and to be informed when assets are sent or received.
*/
interface ILSP1UniversalReceiver {
/**
* @notice Emitted when the universalReceiver function is succesfully executed
* @param from The address calling the universalReceiver function
* @param value The amount sent to the universalReceiver function
* @param typeId The hash of a specific standard or a hook
* @param receivedData The arbitrary data passed to universalReceiver function
* @param returnedValue The value returned by the universalReceiver function
* @dev The event is emitted when `universalReceiver(...)` reacted successfully on all of the following inputs:
*
* - A valid notifier: `from`
* - A valid amount of native tokens are sent: `value`
* - A supported type ID: `typeId`
* - Arbitrary data which may or may not be used: `receivedData`
*
* And returned a valid result: `returnedValue` based on the inputs.
* @notice `from` sent `value` native tokens and a notification using `typeId` and `receivedData`.
*
* @param from The address calling the {universalReceiver(...)} function.
* @param value The amount sent to the {universalReceiver(...)} function.
* @param typeId The hash of a specific standard or a hook.
* @param receivedData The arbitrary data passed to {universalReceiver(...)} function.
* @param returnedValue The value returned by the {universalReceiver(...)} function.
*/
event UniversalReceiver(
address indexed from,
Expand All @@ -23,11 +32,13 @@ interface ILSP1UniversalReceiver {
);

/**
* @param typeId The hash of a specific standard or a hook
* @param data The arbitrary data received with the call
* @dev Emits an event when it's succesfully executed
* @dev Allows for custom on-chain reactions based on the `typeId` and `data`.
* @notice Reacted on received notification with `typeId` & `data`.
*
* @param typeId The hash of a specific standard or a hook.
* @param data The arbitrary data received with the call.
*
* Emits a {UniversalReceiver} event
* @custom:events {UniversalReceiver} event when it's succesfully executed.
*/
function universalReceiver(
bytes32 typeId,
Expand Down
15 changes: 5 additions & 10 deletions contracts/LSP1UniversalReceiver/LSP1Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
pragma solidity ^0.8.4;

/**
* @dev reverts when EOA calls the `universalReceiver(..)` function with an asset/vault typeId
* @dev Reverts when EOA calls the {universalReceiver(..)} function with an asset/vault typeId.
* @notice EOA: `caller` cannot be registered as an asset.
*
* @param caller The address of the EOA
*/
error CannotRegisterEOAsAsAssets(address caller);

/**
* @dev reverts when the account calling the UniversalReceiverDelegate is not the same account
* linked as target in the KeyManager -- Security Check
* @param account The address of the account implementing the `universalReceiver(..)` function
* @param target The address of the target linked to the KeyManager
*/
error CallerNotLSP6LinkedTarget(address account, address target);

/**
* @dev reverts when `universalReceiver(...)` is called with a value different than 0
* @dev Reverts when {universalReceiver(...)} function in the delegated contract is called with a value different than 0.
* @notice Cannot send native tokens to {universalReceiver(...)} function of the delegated contract.
*/
error NativeTokensNotAccepted();
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,35 @@ import "../../LSP14Ownable2Step/LSP14Constants.sol";
import "../LSP1Errors.sol";

/**
* @title Implementation of a UniversalReceiverDelegate for LSP0ERC725Account
* @title Implementation of a UniversalReceiverDelegate for the [LSP-0-ERC725Account]
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
* @dev This UniversalReceiverDelegate follows the {LSP1-UniversalReceiver} standards and is designed
* for LSP0ERC725Account contracts.
* @dev The {LSP1UniversalReceiverDelegateUP} follows the [LSP-1-UniversalReceiver] standard and is designed
* for [LSP-0-ERC725Account] contracts.
*
* @dev Handles two cases:
* - Registers the address of received assets (exclusively LSP7 and LSP8) and vaults (exclusively LSP9) according
* to {LSP5-ReceivedAssets} and {LSP10-ReceivedVaults} respectively
* The {LSP1UniversalReceiverDelegateUP} is a contract called by the {universalReceiver(...)} function of the [LSP-0-ERC725Account] contract that:
*
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-5-ReceivedAssets.md
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-10-ReceivedVaults.md
* - Writes the data keys representing assets received from type [LSP-7-DigitalAsset] and [LSP-8-IdentifiableDigitalAsset] into the account storage, and removes them when the balance is zero according to the [LSP-5-ReceivedAssets] Standard.
* - Writes the data keys representing the owned vaults from type [LSP-9-Vault] into your account storage, and removes them when transferring ownership to other accounts according to the [LSP-10-ReceivedVaults] Standard.
*
* - Removes the address of registered assets and vaults when the full balance is sent from the LSP0ERC725Account contract
*
* Requirements:
* - The contract should be able to setData the LSP5 and LSP10 data Keys according to the logic of the owner
* of the LSP0ERC725Account.
*
* For example, for contracts that are owned by an LSP6KeyManager, this contract should be granted
* the SUPER/SETDATA and REENTRANCY Permission.
*
* Assets and Vaults that are compliant with this version of the UniversalReceiverDelegate are:
*
* - LSP7-DigitalAsset: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-7-DigitalAsset.md
* - LSP8-IdentifiableDigitalAsset: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md
* - LSP9-Vault: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-9-Vault.md
*/
contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
using ERC165Checker for address;

/**
* @dev Handles two cases:
* - Registers the address of received assets (exclusively LSP7 and LSP8) and vaults (exclusively LSP9) according
* to {LSP5-ReceivedAssets} and {LSP10-ReceivedVaults} respectively
* @dev
* 1. Writes the data keys of the received [LSP-7-DigitalAsset], [LSP-8-IdentifiableDigitalAsset] and [LSP-9-Vault] contract addresses into the account storage according to the [LSP-5-ReceivedAssets] and [LSP-10-ReceivedVaults] Standard.
* 2. The data keys representing an asset/vault are cleared when the asset/vault is no longer owned by the account.
*
* - Removes the address of registered assets and vaults when the full balance is sent from the LSP0ERC725Account contract
* @notice Reacted on received notification with `typeId`.
*
* Requirements:
* - The contract should be able to setData the LSP5 and LSP10 data Keys according to the logic of the owner
* of the LSP0ERC725Account.
* @custom:warning In case when the data registered is corrupted such as not stored correctly with standard length ([LSP5ReceivedAssets]), or when the token received is already registered or when the token being sent is not sent as full balance, the function call will pass and return and not modify any data key on the account.
*
* @custom:requirements
* - This contract should be allowed to use the {setDataBatch(...)} function in order to update the LSP5 and LSP10 Data Keys.
* - Cannot accept native tokens
*
* @param typeId Unique identifier for a specific notification.
* @return result The result of the reaction for `typeId`.
*/
function universalReceiver(
bytes32 typeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@ import "../../LSP9Vault/LSP9Constants.sol";
import "../LSP1Errors.sol";

/**
* @title Core Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
* the LSP5-ReceivedAsset standard and removing the sent assets.
*
* @title Implementation of a UniversalReceiverDelegate for the [LSP9Vault]
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
* @dev Delegate contract of the initial universal receiver
* @dev The {LSP1UniversalReceiverDelegateVault} follows the [LSP-1-UniversalReceiver] standard and is designed
* for [LSP9Vault] contracts.
*
* The {LSP1UniversalReceiverDelegateVault} is a contract called by the {universalReceiver(...)} function of the [LSP-9-Vault] contract that:
*
* - Writes the data keys representing assets received from type [LSP-7-DigitalAsset] and [LSP-8-IdentifiableDigitalAsset] into the account storage, and removes them when the balance is zero according to the [LSP-5-ReceivedAssets] Standard.
*/
contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
/**
* @inheritdoc ILSP1UniversalReceiver
* @dev allows to register arrayKeys and Map of incoming assets and remove after being sent
* @return result The return value
* @dev Handles two cases:
*
* Writes the received [LSP-7-DigitalAsset] or [LSP-8-IdentifiableDigitalAsset] assets into the vault storage according to the [LSP-5-ReceivedAssets] standard.
*
* @notice Reacted on received notification with `typeId`.
*
* @custom:requirements Cannot accept native tokens.
*
* @param typeId Unique identifier for a specific notification.
* @return result The result of the reaction for `typeId`.
*/
function universalReceiver(
bytes32 typeId,
Expand Down

0 comments on commit 92f894b

Please sign in to comment.