difftreelog
misk: add prettier configuration for solidity files
in: master
7 files changed
.maintain/scripts/generate_sol.shdiffbeforeafterboth--- a/.maintain/scripts/generate_sol.sh
+++ b/.maintain/scripts/generate_sol.sh
@@ -1,11 +1,16 @@
#!/bin/sh
set -eu
+PRETTIER_CONFIG="$(pwd)""/.prettierrc"
+
tmp=$(mktemp)
cargo test --package $PACKAGE -- $NAME --exact --nocapture --ignored | tee $tmp
raw=$(mktemp --suffix .sol)
sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw
+
formatted=$(mktemp)
-prettier --use-tabs $raw > $formatted
+echo $raw
+echo $formatted
+prettier --config $PRETTIER_CONFIG $raw > $formatted
mv $formatted $OUTPUT
.prettierignorediffbeforeafterboth--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1 @@
+!**/*.sol
.prettierrcdiffbeforeafterboth--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,16 @@
+{
+ "useTabs": true,
+ "tabWidth": 2,
+ "singleQuote": true,
+ "trailingComma": "all",
+ "overrides": [
+ {
+ "files": "*.sol",
+ "options": {
+ "singleQuote": false,
+ "printWidth": 120,
+ "explicitTypes": "always"
+ }
+ }
+ ]
+}
\ No newline at end of file
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8 uint8 dummy;9 string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13 function supportsInterface(bytes4 interfaceID)14 external15 view16 returns (bool)17 {18 require(false, stub_error);19 interfaceID;20 return true;21 }22}2324/// @dev inlined interface25contract CollectionHelpersEvents {26 event CollectionCreated(27 address indexed owner,28 address indexed collectionId29 );30}3132/// @title Contract, which allows users to operate with collections33/// @dev the ERC-165 identifier for this interface is 0x88ee8ef134contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {35 /// Create an NFT collection36 /// @param name Name of the collection37 /// @param description Informative description of the collection38 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications39 /// @return address Address of the newly created collection40 /// @dev EVM selector for this function is: 0xe34a6844,41 /// or in textual repr: createNonfungibleCollection(string,string,string)42 function createNonfungibleCollection(43 string memory name,44 string memory description,45 string memory tokenPrefix46 ) public returns (address) {47 require(false, stub_error);48 name;49 description;50 tokenPrefix;51 dummy = 0;52 return 0x0000000000000000000000000000000000000000;53 }5455 /// @dev EVM selector for this function is: 0xa634a5f9,56 /// or in textual repr: createERC721MetadataCompatibleCollection(string,string,string,string)57 function createERC721MetadataCompatibleCollection(58 string memory name,59 string memory description,60 string memory tokenPrefix,61 string memory baseUri62 ) public returns (address) {63 require(false, stub_error);64 name;65 description;66 tokenPrefix;67 baseUri;68 dummy = 0;69 return 0x0000000000000000000000000000000000000000;70 }7172 /// @dev EVM selector for this function is: 0xab173450,73 /// or in textual repr: createRFTCollection(string,string,string)74 function createRFTCollection(75 string memory name,76 string memory description,77 string memory tokenPrefix78 ) public returns (address) {79 require(false, stub_error);80 name;81 description;82 tokenPrefix;83 dummy = 0;84 return 0x0000000000000000000000000000000000000000;85 }8687 /// @dev EVM selector for this function is: 0xa5596388,88 /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)89 function createERC721MetadataCompatibleRFTCollection(90 string memory name,91 string memory description,92 string memory tokenPrefix,93 string memory baseUri94 ) public returns (address) {95 require(false, stub_error);96 name;97 description;98 tokenPrefix;99 baseUri;100 dummy = 0;101 return 0x0000000000000000000000000000000000000000;102 }103104 /// Check if a collection exists105 /// @param collectionAddress Address of the collection in question106 /// @return bool Does the collection exist?107 /// @dev EVM selector for this function is: 0xc3de1494,108 /// or in textual repr: isCollectionExist(address)109 function isCollectionExist(address collectionAddress)110 public111 view112 returns (bool)113 {114 require(false, stub_error);115 collectionAddress;116 dummy;117 return false;118 }119}1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8 uint8 dummy;9 string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13 function supportsInterface(bytes4 interfaceID) external view returns (bool) {14 require(false, stub_error);15 interfaceID;16 return true;17 }18}1920/// @dev inlined interface21contract CollectionHelpersEvents {22 event CollectionCreated(address indexed owner, address indexed collectionId);23}2425/// @title Contract, which allows users to operate with collections26/// @dev the ERC-165 identifier for this interface is 0x88ee8ef127contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {28 /// Create an NFT collection29 /// @param name Name of the collection30 /// @param description Informative description of the collection31 /// @param tokenPrefix Token prefix to represent the collection tokens in UI and user applications32 /// @return address Address of the newly created collection33 /// @dev EVM selector for this function is: 0xe34a6844,34 /// or in textual repr: createNonfungibleCollection(string,string,string)35 function createNonfungibleCollection(36 string memory name,37 string memory description,38 string memory tokenPrefix39 ) public returns (address) {40 require(false, stub_error);41 name;42 description;43 tokenPrefix;44 dummy = 0;45 return 0x0000000000000000000000000000000000000000;46 }4748 /// @dev EVM selector for this function is: 0xa634a5f9,49 /// or in textual repr: createERC721MetadataCompatibleCollection(string,string,string,string)50 function createERC721MetadataCompatibleCollection(51 string memory name,52 string memory description,53 string memory tokenPrefix,54 string memory baseUri55 ) public returns (address) {56 require(false, stub_error);57 name;58 description;59 tokenPrefix;60 baseUri;61 dummy = 0;62 return 0x0000000000000000000000000000000000000000;63 }6465 /// @dev EVM selector for this function is: 0xab173450,66 /// or in textual repr: createRFTCollection(string,string,string)67 function createRFTCollection(68 string memory name,69 string memory description,70 string memory tokenPrefix71 ) public returns (address) {72 require(false, stub_error);73 name;74 description;75 tokenPrefix;76 dummy = 0;77 return 0x0000000000000000000000000000000000000000;78 }7980 /// @dev EVM selector for this function is: 0xa5596388,81 /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)82 function createERC721MetadataCompatibleRFTCollection(83 string memory name,84 string memory description,85 string memory tokenPrefix,86 string memory baseUri87 ) public returns (address) {88 require(false, stub_error);89 name;90 description;91 tokenPrefix;92 baseUri;93 dummy = 0;94 return 0x0000000000000000000000000000000000000000;95 }9697 /// Check if a collection exists98 /// @param collectionAddress Address of the collection in question99 /// @return bool Does the collection exist?100 /// @dev EVM selector for this function is: 0xc3de1494,101 /// or in textual repr: isCollectionExist(address)102 function isCollectionExist(address collectionAddress) public view returns (bool) {103 require(false, stub_error);104 collectionAddress;105 dummy;106 return false;107 }108}tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -14,10 +14,7 @@
/// @dev inlined interface
interface CollectionHelpersEvents {
- event CollectionCreated(
- address indexed owner,
- address indexed collectionId
- );
+ event CollectionCreated(address indexed owner, address indexed collectionId);
}
/// @title Contract, which allows users to operate with collections
@@ -67,8 +64,5 @@
/// @return bool Does the collection exist?
/// @dev EVM selector for this function is: 0xc3de1494,
/// or in textual repr: isCollectionExist(address)
- function isCollectionExist(address collectionAddress)
- external
- view
- returns (bool);
+ function isCollectionExist(address collectionAddress) external view returns (bool);
}
tests/src/eth/fractionalizer/Fractionalizer.soldiffbeforeafterboth--- a/tests/src/eth/fractionalizer/Fractionalizer.sol
+++ b/tests/src/eth/fractionalizer/Fractionalizer.sol
@@ -10,201 +10,158 @@
/// stores allowlist of NFT tokens available for fractionalization, has methods
/// for fractionalization and defractionalization of NFT tokens.
contract Fractionalizer {
- struct Token {
- address _collection;
- uint256 _tokenId;
- }
- address rftCollection;
- mapping(address => bool) nftCollectionAllowList;
- mapping(address => mapping(uint256 => uint256)) public nft2rftMapping;
- mapping(address => Token) public rft2nftMapping;
- bytes32 refungibleCollectionType = keccak256(bytes("ReFungible"));
+ struct Token {
+ address _collection;
+ uint256 _tokenId;
+ }
+ address rftCollection;
+ mapping(address => bool) nftCollectionAllowList;
+ mapping(address => mapping(uint256 => uint256)) public nft2rftMapping;
+ mapping(address => Token) public rft2nftMapping;
+ bytes32 refungibleCollectionType = keccak256(bytes("ReFungible"));
- receive() external payable onlyOwner {}
+ receive() external payable onlyOwner {}
- /// @dev Method modifier to only allow contract owner to call it.
- modifier onlyOwner() {
- address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;
- ContractHelpers contractHelpers = ContractHelpers(
- contracthelpersAddress
- );
- address contractOwner = contractHelpers.contractOwner(address(this));
- require(msg.sender == contractOwner, "Only owner can");
- _;
- }
+ /// @dev Method modifier to only allow contract owner to call it.
+ modifier onlyOwner() {
+ address contracthelpersAddress = 0x842899ECF380553E8a4de75bF534cdf6fBF64049;
+ ContractHelpers contractHelpers = ContractHelpers(contracthelpersAddress);
+ address contractOwner = contractHelpers.contractOwner(address(this));
+ require(msg.sender == contractOwner, "Only owner can");
+ _;
+ }
- /// @dev This emits when RFT collection setting is changed.
- event RFTCollectionSet(address _collection);
+ /// @dev This emits when RFT collection setting is changed.
+ event RFTCollectionSet(address _collection);
- /// @dev This emits when NFT collection is allowed or disallowed.
- event AllowListSet(address _collection, bool _status);
+ /// @dev This emits when NFT collection is allowed or disallowed.
+ event AllowListSet(address _collection, bool _status);
- /// @dev This emits when NFT token is fractionalized by contract.
- event Fractionalized(
- address _collection,
- uint256 _tokenId,
- address _rftToken,
- uint128 _amount
- );
+ /// @dev This emits when NFT token is fractionalized by contract.
+ event Fractionalized(address _collection, uint256 _tokenId, address _rftToken, uint128 _amount);
- /// @dev This emits when NFT token is defractionalized by contract.
- event Defractionalized(
- address _rftToken,
- address _nftCollection,
- uint256 _nftTokenId
- );
+ /// @dev This emits when NFT token is defractionalized by contract.
+ event Defractionalized(address _rftToken, address _nftCollection, uint256 _nftTokenId);
- /// Set RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
- /// would be created in this collection.
- /// @dev Throws if RFT collection is already configured for this contract.
- /// Throws if collection of wrong type (NFT, Fungible) is provided instead
- /// of RFT collection.
- /// Throws if `msg.sender` is not owner or admin of provided RFT collection.
- /// Can only be called by contract owner.
- /// @param _collection address of RFT collection.
- function setRFTCollection(address _collection) public onlyOwner {
- require(rftCollection == address(0), "RFT collection is already set");
- UniqueRefungible refungibleContract = UniqueRefungible(_collection);
- string memory collectionType = refungibleContract
- .uniqueCollectionType();
+ /// Set RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
+ /// would be created in this collection.
+ /// @dev Throws if RFT collection is already configured for this contract.
+ /// Throws if collection of wrong type (NFT, Fungible) is provided instead
+ /// of RFT collection.
+ /// Throws if `msg.sender` is not owner or admin of provided RFT collection.
+ /// Can only be called by contract owner.
+ /// @param _collection address of RFT collection.
+ function setRFTCollection(address _collection) public onlyOwner {
+ require(rftCollection == address(0), "RFT collection is already set");
+ UniqueRefungible refungibleContract = UniqueRefungible(_collection);
+ string memory collectionType = refungibleContract.uniqueCollectionType();
- require(
- keccak256(bytes(collectionType)) == refungibleCollectionType,
- "Wrong collection type. Collection is not refungible."
- );
- require(
- refungibleContract.isOwnerOrAdmin(address(this)),
- "Fractionalizer contract should be an admin of the collection"
- );
- rftCollection = _collection;
- emit RFTCollectionSet(rftCollection);
- }
+ require(
+ keccak256(bytes(collectionType)) == refungibleCollectionType,
+ "Wrong collection type. Collection is not refungible."
+ );
+ require(
+ refungibleContract.isOwnerOrAdmin(address(this)),
+ "Fractionalizer contract should be an admin of the collection"
+ );
+ rftCollection = _collection;
+ emit RFTCollectionSet(rftCollection);
+ }
- /// Creates and sets RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
- /// would be created in this collection.
- /// @dev Throws if RFT collection is already configured for this contract.
- /// Can only be called by contract owner.
- /// @param _name name for created RFT collection.
- /// @param _description description for created RFT collection.
- /// @param _tokenPrefix token prefix for created RFT collection.
- function createAndSetRFTCollection(
- string calldata _name,
- string calldata _description,
- string calldata _tokenPrefix
- ) public onlyOwner {
- require(rftCollection == address(0), "RFT collection is already set");
- address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;
- rftCollection = CollectionHelpers(collectionHelpers)
- .createRFTCollection(_name, _description, _tokenPrefix);
- emit RFTCollectionSet(rftCollection);
- }
+ /// Creates and sets RFT collection that contract will work with. RFT tokens for fractionalized NFT tokens
+ /// would be created in this collection.
+ /// @dev Throws if RFT collection is already configured for this contract.
+ /// Can only be called by contract owner.
+ /// @param _name name for created RFT collection.
+ /// @param _description description for created RFT collection.
+ /// @param _tokenPrefix token prefix for created RFT collection.
+ function createAndSetRFTCollection(
+ string calldata _name,
+ string calldata _description,
+ string calldata _tokenPrefix
+ ) public onlyOwner {
+ require(rftCollection == address(0), "RFT collection is already set");
+ address collectionHelpers = 0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F;
+ rftCollection = CollectionHelpers(collectionHelpers).createRFTCollection(_name, _description, _tokenPrefix);
+ emit RFTCollectionSet(rftCollection);
+ }
- /// Allow or disallow NFT collection tokens from being fractionalized by this contract.
- /// @dev Can only be called by contract owner.
- /// @param collection NFT token address.
- /// @param status `true` to allow and `false` to disallow NFT token.
- function setNftCollectionIsAllowed(address collection, bool status)
- public
- onlyOwner
- {
- nftCollectionAllowList[collection] = status;
- emit AllowListSet(collection, status);
- }
+ /// Allow or disallow NFT collection tokens from being fractionalized by this contract.
+ /// @dev Can only be called by contract owner.
+ /// @param collection NFT token address.
+ /// @param status `true` to allow and `false` to disallow NFT token.
+ function setNftCollectionIsAllowed(address collection, bool status) public onlyOwner {
+ nftCollectionAllowList[collection] = status;
+ emit AllowListSet(collection, status);
+ }
- /// Fractionilize NFT token.
- /// @dev Takes NFT token from `msg.sender` and transfers RFT token to `msg.sender`
- /// instead. Creates new RFT token if provided NFT token never was fractionalized
- /// by this contract or existing RFT token if it was.
- /// Throws if RFT collection isn't configured for this contract.
- /// Throws if fractionalization of provided NFT token is not allowed
- /// Throws if `msg.sender` is not owner of provided NFT token
- /// @param _collection NFT collection address
- /// @param _token id of NFT token to be fractionalized
- /// @param _pieces number of pieces new RFT token would have
- function nft2rft(
- address _collection,
- uint256 _token,
- uint128 _pieces
- ) public {
- require(rftCollection != address(0), "RFT collection is not set");
- UniqueRefungible rftCollectionContract = UniqueRefungible(
- rftCollection
- );
- require(
- nftCollectionAllowList[_collection] == true,
- "Fractionalization of this collection is not allowed by admin"
- );
- require(
- UniqueNFT(_collection).ownerOf(_token) == msg.sender,
- "Only token owner could fractionalize it"
- );
- UniqueNFT(_collection).transferFrom(msg.sender, address(this), _token);
- uint256 rftTokenId;
- address rftTokenAddress;
- UniqueRefungibleToken rftTokenContract;
- if (nft2rftMapping[_collection][_token] == 0) {
- rftTokenId = rftCollectionContract.nextTokenId();
- rftCollectionContract.mint(address(this), rftTokenId);
- rftTokenAddress = rftCollectionContract.tokenContractAddress(
- rftTokenId
- );
- nft2rftMapping[_collection][_token] = rftTokenId;
- rft2nftMapping[rftTokenAddress] = Token(_collection, _token);
+ /// Fractionilize NFT token.
+ /// @dev Takes NFT token from `msg.sender` and transfers RFT token to `msg.sender`
+ /// instead. Creates new RFT token if provided NFT token never was fractionalized
+ /// by this contract or existing RFT token if it was.
+ /// Throws if RFT collection isn't configured for this contract.
+ /// Throws if fractionalization of provided NFT token is not allowed
+ /// Throws if `msg.sender` is not owner of provided NFT token
+ /// @param _collection NFT collection address
+ /// @param _token id of NFT token to be fractionalized
+ /// @param _pieces number of pieces new RFT token would have
+ function nft2rft(
+ address _collection,
+ uint256 _token,
+ uint128 _pieces
+ ) public {
+ require(rftCollection != address(0), "RFT collection is not set");
+ UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);
+ require(
+ nftCollectionAllowList[_collection] == true,
+ "Fractionalization of this collection is not allowed by admin"
+ );
+ require(UniqueNFT(_collection).ownerOf(_token) == msg.sender, "Only token owner could fractionalize it");
+ UniqueNFT(_collection).transferFrom(msg.sender, address(this), _token);
+ uint256 rftTokenId;
+ address rftTokenAddress;
+ UniqueRefungibleToken rftTokenContract;
+ if (nft2rftMapping[_collection][_token] == 0) {
+ rftTokenId = rftCollectionContract.nextTokenId();
+ rftCollectionContract.mint(address(this), rftTokenId);
+ rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);
+ nft2rftMapping[_collection][_token] = rftTokenId;
+ rft2nftMapping[rftTokenAddress] = Token(_collection, _token);
- rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
- } else {
- rftTokenId = nft2rftMapping[_collection][_token];
- rftTokenAddress = rftCollectionContract.tokenContractAddress(
- rftTokenId
- );
- rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
- }
- rftTokenContract.repartition(_pieces);
- rftTokenContract.transfer(msg.sender, _pieces);
- emit Fractionalized(_collection, _token, rftTokenAddress, _pieces);
- }
+ rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
+ } else {
+ rftTokenId = nft2rftMapping[_collection][_token];
+ rftTokenAddress = rftCollectionContract.tokenContractAddress(rftTokenId);
+ rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
+ }
+ rftTokenContract.repartition(_pieces);
+ rftTokenContract.transfer(msg.sender, _pieces);
+ emit Fractionalized(_collection, _token, rftTokenAddress, _pieces);
+ }
- /// Defrationalize NFT token.
- /// @dev Takes RFT token from `msg.sender` and transfers corresponding NFT token
- /// to `msg.sender` instead.
- /// Throws if RFT collection isn't configured for this contract.
- /// Throws if provided RFT token is no from configured RFT collection.
- /// Throws if RFT token was not created by this contract.
- /// Throws if `msg.sender` isn't owner of all RFT token pieces.
- /// @param _collection RFT collection address
- /// @param _token id of RFT token
- function rft2nft(address _collection, uint256 _token) public {
- require(rftCollection != address(0), "RFT collection is not set");
- require(rftCollection == _collection, "Wrong RFT collection");
- UniqueRefungible rftCollectionContract = UniqueRefungible(
- rftCollection
- );
- address rftTokenAddress = rftCollectionContract.tokenContractAddress(
- _token
- );
- Token memory nftToken = rft2nftMapping[rftTokenAddress];
- require(
- nftToken._collection != address(0),
- "No corresponding NFT token found"
- );
- UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(
- rftTokenAddress
- );
- require(
- rftTokenContract.balanceOf(msg.sender) ==
- rftTokenContract.totalSupply(),
- "Not all pieces are owned by the caller"
- );
- rftCollectionContract.transferFrom(msg.sender, address(this), _token);
- UniqueNFT(nftToken._collection).transferFrom(
- address(this),
- msg.sender,
- nftToken._tokenId
- );
- emit Defractionalized(
- rftTokenAddress,
- nftToken._collection,
- nftToken._tokenId
- );
- }
+ /// Defrationalize NFT token.
+ /// @dev Takes RFT token from `msg.sender` and transfers corresponding NFT token
+ /// to `msg.sender` instead.
+ /// Throws if RFT collection isn't configured for this contract.
+ /// Throws if provided RFT token is no from configured RFT collection.
+ /// Throws if RFT token was not created by this contract.
+ /// Throws if `msg.sender` isn't owner of all RFT token pieces.
+ /// @param _collection RFT collection address
+ /// @param _token id of RFT token
+ function rft2nft(address _collection, uint256 _token) public {
+ require(rftCollection != address(0), "RFT collection is not set");
+ require(rftCollection == _collection, "Wrong RFT collection");
+ UniqueRefungible rftCollectionContract = UniqueRefungible(rftCollection);
+ address rftTokenAddress = rftCollectionContract.tokenContractAddress(_token);
+ Token memory nftToken = rft2nftMapping[rftTokenAddress];
+ require(nftToken._collection != address(0), "No corresponding NFT token found");
+ UniqueRefungibleToken rftTokenContract = UniqueRefungibleToken(rftTokenAddress);
+ require(
+ rftTokenContract.balanceOf(msg.sender) == rftTokenContract.totalSupply(),
+ "Not all pieces are owned by the caller"
+ );
+ rftCollectionContract.transferFrom(msg.sender, address(this), _token);
+ UniqueNFT(nftToken._collection).transferFrom(address(this), msg.sender, nftToken._tokenId);
+ emit Defractionalized(rftTokenAddress, nftToken._collection, nftToken._tokenId);
+ }
}