Skip to main content

LSP0ERC725Account

Solidity contract

The LSP0ERC725Account contract is an implementation for the LSP0-ERC725Account Standard. This contract forms a Universal Profile when combined with LSP3-UniversalProfile-Metadata Standard.

This contract could be used as a blockchain-based account by humans, machines, organizations, or even other smart contracts. It has all the basic functionalities of an Externally Owned Account (EOA), as well as the following functions that give the contract additional features:

note

LSP0ERC725Account contract also contains the method from ERC165:

function supportsInterface(bytes4 interfaceId) public view returns (bool)

Functions​

constructor​

constructor(address initialOwner)

Sets the initial owner of the contract.

Parameters:​

NameTypeDescription
initialOwneraddressThe address to set as the owner of the contract.

owner​

function owner() public view returns (address owner)

Returns the address of the current owner of the contract.

Return Values:​

NameTypeDescription
owneraddressThe current owner of the contract.

pendingOwner​

function pendingOwner() public view returns (address)

Return the address of the pending owner that was initiated by transferOwnership(address).

NB: if no ownership transfer is in progress, the pendingOwner MUST be address(0).

Return Values:​

NameTypeDescription
pendingOwneraddressThe address of the pending owner

transferOwnership​

function transferOwnership(address newOwner) public

Initiate an ownership transfer by setting the newOwner as pendingOwner.

Requirements:

  • Can only be called by the current owner.
  • The newOwner to be set as the pendingOwner cannot be address(this).

Parameters:​

NameTypeDescription
newOwneraddressThe address to set as pendingOwner.

claimOwnership​

function claimOwnership() public

Transfers ownership of the contract to the pendingOwner address. Can only be called by the pendingOwner.

Triggers the OwnershipTransferred event once the new owner has claimed ownership.

renounceOwnership​

function renounceOwnership() public

Since renouncing ownership is a sensitive operation, it is done as a two-step process by calling renounceOwnership(..) twice. First to initiate the process, second as a confirmation.

The current block number is saved as a part of initiation because the following behaviour is wanted:

  • The first 100 blocks after the saved block is the pending period, if you call renounceOwnership(..) during this period, the transaction will be reverted.
  • the following 100 blocks is the period when you can confirm the renouncement of the contract by calling renounceOwnership(..) the second time.

Triggers the RenounceOwnershipInitiated event in the first call.

Triggers the OwnershipTransferred event after successfully renouncing ownership.

danger

Leaves the contract without an owner. Once ownership of the contract is renounced, it won't be possible to call the functions restricted to the owner only.

fallback​

fallback() external payable

Executed when value is transferred to the contract or when function identifier doesn't match any of the available functions.

Triggers the ValueReceived event when a native token is received.

execute​

function execute(
uint256 operationType,
address to,
uint256 value,
bytes memory data
) public payable returns (bytes memory result)

Executes a call on any other smart contracts, transfers value, or deploys a new smart contract.

The operationType can be the following:

  • 0 for CALL
  • 1 for CREATE
  • 2 for CREATE2
  • 3 for STATICCALL
  • 4 for DELEGATECALL

Triggers the Executed event when a call is successfully executed using CALL/STATICCALL/DELEGATECALL operations.

Triggers the ContractCreated event when a smart contract is created using CREATE/CREATE2 operations.

note

The execute(...) function can only be called by the current owner of the contract.

The operation types staticcall (3) and delegatecall (4) do not allow to transfer value.

Parameters:​

NameTypeDescription
operationTypeuint256The type of operation that needs to be executed.
toaddressThe address to interact with. The address to will be unused if a contract is created (operations 1 & 2).
valueuint256The amount of native tokens to transfer with the transaction (in Wei).
databytesThe calldata (ABI-encoded payload of a function to run on an other contract), or the bytecode of the contract to deploy.

Return Values:​

NameTypeDescription
resultbytesThe data that was returned by the function called on the external contract, or the address of the contract created (operations 1 & 2).

setData​

function setData(
bytes32 dataKey,
bytes memory dataValue
) public

Sets data in the account storage for a particular data key.

Triggers the DataChanged event when successfully setting the data.

note

The setData(...) function can only be called by the current owner of the contract.

Parameters:​

NameTypeDescription
dataKeybytes32The data key for which the data will be set.
dataValuebytesThe data to be set.

getData​

function getData(bytes32 dataKey) public view returns (bytes memory dataValue)

Retrieves the data set for the given data key.

Parameters:​

NameTypeDescription
dataKeybytes32The data key to retrieve data from.

Return Values:​

NameTypeDescription
dataValuebytesThe data for the requested data key.

setData (Array)​

function setData(
bytes32[] memory dataKeys,
bytes[] memory dataValues
) public

Sets an array of data at multiple data keys in the account storage.

Triggers the DataChanged event when successfully setting each data key/value pair.

note

The setData(...) function can only be called by the current owner of the contract.

Parameters:​

NameTypeDescription
dataKeysbytes32[ ]The data keys for which to set data.
dataValuesbytes[ ]The array of data to set.

getData (Array)​

function getData(bytes32[] memory dataKeys) public view returns (bytes[] memory dataValues)

Retrieves an array of data for multiple given data keys.

Parameters:​

NameTypeDescription
dataKeysbytes32[ ]The data keys to retrieve data from.

Return Values:​

NameTypeDescription
dataValuesbytes[ ]An array of the data for the requested data keys.

universalReceiver​

function universalReceiver(
bytes32 typeId,
bytes memory data
) public payable returns (bytes memory result)

Forwards the call to the UniversalReceiverDelegate contract if its address is stored at the LSP1UniversalReceiverDelegate data Key. The contract being called is expected to be an LSP1UniversalReceiverDelegateUP, supporting LSP1UniversalReceiverDelegate InterfaceId using ERC165.

Triggers the UniversalReceiver event when this function gets successfully executed.

Parameters:​

NameTypeDescription
typeIdbytes32The type of transfer received.
databytesThe data received.

Return Values:​

NameTypeDescription
resultbytesCan be used to encode response values.

isValidSignature​

function isValidSignature(
bytes32 hash,
bytes memory signature
) public view returns (bytes4 magicValue)

Checks if a signature was signed by the owner of the contract, according to EIP-1271. If the owner is a contract itself, it will call the isValidsignature(..) function on the owner contract, if it supports EIP-1271. Otherwise it will return the failure value.

Parameters:​

NameTypeDescription
hashbytes32The hash of the data signed on the behalf of address.
signaturebytesThe Owner's signature(s) of the data.

Return Values:​

NameTypeDescription
magicValuebytes4The magicValue either 0x1626ba7e on success or 0xffffffff failure.

Events​

OwnershipTransferred​

event OwnershipTransferred(
address previousOwner,
address newOwner,
)

MUST be fired when transferOwnership(...) function is successfully executed.

Values:​

NameTypeDescription
previousOwneraddressThe previous owner of the contract.
newOwneraddressThe new owner of the contract.

RenounceOwnershipInitiated​

event RenounceOwnershipInitiated()

MUST be fired when the renounceOwnership() function's first phase is complete.

ValueReceived​

event ValueReceived(
address sender,
uint256 value
)

MUST be fired when when a native token is received via fallback(...) function.

Values:​

NameTypeDescription
senderaddressThe address of the sender.
valueuint256The amount sent.

Executed​

event Executed(
uint256 operation,
address to,
uint256 value,
bytes4 selector
)

MUST be fired when execute(...) function creates a new call using the CALL, STATICCALL, or DELEGATECALL operation.

Values:​

NameTypeDescription
operationuint256The operation executed.
toaddressThe smart contract or address interacted with.
valueuint256The value transferred.
selectorbytes4The bytes4 selector of the function executed at the to address

ContractCreated​

event ContractCreated(
uint256 operation,
address contractAddress,
uint256 value
)

MUST be fired when the execute(...) function creates a new contract using the CREATE or CREATE2 operation.

Values:​

NameTypeDescription
operationuint256The operation executed.
toaddressThe address of the created contract.
valueuint256The value sent to the contract.

DataChanged​

event DataChanged(bytes32 dataKey, bytes dataValue)

MUST be fired when the setData(...) function is successfully executed.

Values:​

NameTypeDescription
dataKeybytes32The data key which data value is set.
dataValuebytesThe data value to set.
info

The DataChanged event will emit only the first 256 bytes of dataValue (for large values set in the ERC725Y storage).

UniversalReceiver​

event UniversalReceiver(
address from,
uint256 value,
bytes32 typeId,
bytes receivedData
bytes returnedValue,
)

MUST be fired when the universalReceiver(...) function is successfully executed.

Values:​

NameTypeDescription
fromaddressThe address calling the universalReceiver function.
valueuint256The amount of value sent to the universalReceiver function.
typeIdbytes32The hash of a specific standard or a hook.
receivedDatabytesThe arbitrary data passed to universalReceiver function.
returnedValuebytesThe value returned by the universalReceiver function.

References​