pragmasolidity^0.8.21;/**
* @notice Struct encapsulating fields required to by the ERC-7578 standard to represent the physical asset
* @param tokenIssuer The network or entity minting the token
* @param assetHolder The legal owner of the physical asset
* @param storageLocation The physical location where the asset is stored
* @param terms Link to IPFS contract, agreement or terms
* @param jurisdiction The legal justification set out in the terms
* @param declaredValue The declared value at time of token minting
*/structProperties{stringtokenIssuer;stringassetHolder;stringstorageLocation;stringterms;stringjurisdiction;AmountdeclaredValue;}/**
* @notice Struct encapsulating fields describing the declared value of the physical asset
* @param currency The currency of the amount
* @param value The value of the amount
*/structAmount{stringcurrency;uint256value;}/**
* @notice Required interface of an ERC-7578 compliant contract
*/interfaceIERC7578{/**
* @notice Emitted when the properties of the `tokenId` token are set
* @param tokenId The ID of the token
* @param properties The properties of the token
*/eventPropertiesSet(uint256indexedtokenId,Propertiesproperties);/**
* @notice Emitted when the properties of the `tokenId` token are removed
* @param tokenId The ID of the token
*/eventPropertiesRemoved(uint256indexedtokenId);/**
* @notice Retrieves all properties of the `tokenId` token
* @dev Does NOT revert if token doesn't exist
* @param tokenId The token ID of the minted token
*/functiongetPropertiesOf(uint256tokenId)externalviewreturns(Propertiesmemoryproperties);}
pragmasolidity^0.8.21;import{ERC721}from"@openzeppelin/contracts/token/ERC721/ERC721.sol";import{IERC7578,Properties,Amount}from"./interfaces/IERC7578.sol";/**
* @title ERC7578
* @author DESAT
* @notice Implementation of the ERC-7578: Physical Asset Redemption standard
**/contractERC7578isERC721,IERC7578{/**
* @notice Thrown when the properties of a token are not initialized
*/errorPropertiesUninitialized();/**
* @notice Retrieves the properties of the `tokenId` token
*/mapping(uint256tokenId=>Properties)private_properties;/**
* @notice Initializes the name and symbol of the ERC-721 collection
*/constructor(stringmemory_name,stringmemory_symbol)ERC721(_name,_symbol){}/**
* @inheritdoc IERC7578
*/functiongetPropertiesOf(uint256tokenId)publicviewoverridereturns(Propertiesmemoryproperties){properties=_properties[tokenId];}/**
* @notice Initializes the ERC-7578 properties of the `tokenId` token
*
* WARNING: This method should only be called within a function that has appropriate access control
* It is recommended to restrict access to trusted Externally Owned Accounts (EOAs),
* authorized contracts, or implement a Role-Based Access Control (RBAC) mechanism
* Failure to properly secure this method could lead to unauthorized modification of token properties
*
* Emits a {PropertiesSet} event
*/function_setPropertiesOf(uint256tokenId,Propertiescalldataproperties)internal{_properties[tokenId]=Properties({tokenIssuer:properties.tokenIssuer,assetHolder:properties.assetHolder,storageLocation:properties.storageLocation,terms:properties.terms,jurisdiction:properties.jurisdiction,declaredValue:Amount({currency:properties.declaredValue.currency,value:properties.declaredValue.value})});emitPropertiesSet(tokenId,_properties[tokenId]);}/**
* @notice Removes the properties of the `tokenId` token
* @param tokenId The unique identifier of the token whose properties are to be removed
*
* Emits a {PropertiesRemoved} event
*/function_removePropertiesOf(uint256tokenId)internal{delete_properties[tokenId];emitPropertiesRemoved(tokenId);}/**
* @notice Override of the {_update} function to remove the properties of the `tokenId` token or
* to check if they are set before minting
* @param tokenId The unique identifier of the token being minted or burned
*/function_update(addressto,uint256tokenId,addressauth)internalvirtualoverridereturns(address){addressfrom=_ownerOf(tokenId);if(to==address(0)){_removePropertiesOf(tokenId);}elseif(from==address(0)){if(bytes(_properties[tokenId].tokenIssuer).length==0)revertPropertiesUninitialized();}returnsuper._update(to,tokenId,auth);}}
Lee Vidor (@V1d0r), David Tan <david@emergentx.org>, Lee Smith <lee@emergentx.org>, Gabriel Stoica (@gabrielstoica), "ERC-7578: 物理资产赎回," Ethereum Improvement Proposals, no. 7578, August 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7578.