difftreelog
Merge pull request #954 from UniqueNetwork/feature/update_market_v2_contract
in: master
4 files changed
tests/package.jsondiffbeforeafterboth1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/typegen": "10.7.2",8 "@types/chai": "^4.3.3",9 "@types/chai-as-promised": "^7.1.5",10 "@types/chai-like": "^1.1.1",11 "@types/chai-subset": "^1.3.3",12 "@types/mocha": "^10.0.0",13 "@types/node": "^20.2.3",14 "@typescript-eslint/eslint-plugin": "^5.47.0",15 "@typescript-eslint/parser": "^5.47.0",16 "@zombienet/orchestrator": "https://gitpkg.now.sh/UniqueNetwork/zombienet/javascript/packages/orchestrator?2476ea76a368f1b1e94038dbfec29c27f114288e",17 "@zombienet/utils": "https://gitpkg.now.sh/UniqueNetwork/zombienet/javascript/packages/utils?2476ea76a368f1b1e94038dbfec29c27f114288e",18 "chai": "^4.3.6",19 "chai-subset": "^1.6.0",20 "eslint": "^8.25.0",21 "eslint-plugin-mocha": "^10.1.0",22 "mocha": "^10.1.0",23 "ts-node": "^10.9.1",24 "typescript": "^5.0.4"25 },26 "mocha": {27 "timeout": 9999999,28 "require": [29 "ts-node/register"30 ]31 },32 "scripts": {33 "lint": "eslint --ext .ts,.js src/",34 "fix": "yarn lint --fix",35 "setup": "ts-node --esm ./src/util/globalSetup.ts",36 "setIdentities": "ts-node --esm ./src/util/identitySetter.ts",37 "checkRelayIdentities": "ts-node --esm ./src/util/relayIdentitiesChecker.ts",38 "frankenstein": "ts-node --esm ./src/util/frankenstein.ts",39 "_test": "yarn setup && mocha --timeout 9999999 --loader=ts-node/esm.mjs",40 "_testParallel": "yarn setup && mocha --timeout 9999999 --parallel --loader=ts-node/esm.mjs",41 "test": "yarn _test './src/**/*.*test.ts'",42 "testParallelFull": "yarn testParallel && yarn testSequential",43 "testParallel": "yarn _testParallel './src/**/*.test.ts'",44 "testSequential": "yarn _test './src/**/*.seqtest.ts'",45 "testStructure": "yarn _test ./**/nesting/*.*test.ts",46 "testEth": "yarn _test './**/eth/**/*.*test.ts'",47 "testEthNesting": "yarn _test './**/eth/nesting/**/*.*test.ts'",48 "testEthFractionalizer": "yarn _test './**/eth/fractionalizer/**/*.*test.ts'",49 "testEthMarketplace": "yarn _test './**/eth/marketplace/**/*.*test.ts'",50 "testSub": "yarn _test './**/sub/**/*.*test.ts'",51 "testSubNesting": "yarn _test './**/sub/nesting/**/*.*test.ts'",52 "testEvent": "yarn _test ./src/check-event/*.*test.ts",53 "testEthPayable": "yarn _test './**/eth/payable.test.ts'",54 "testEvmCoder": "yarn _test './**/eth/evmCoder.test.ts'",55 "testNesting": "yarn _test ./**/nest.test.ts",56 "testUnnesting": "yarn _test ./**/unnest.test.ts",57 "testProperties": "yarn _test ./**/collectionProperties.*test.ts ./**/tokenProperties.*test.ts ./**/getPropertiesRpc.test.ts",58 "testCollectionProperties": "yarn _test ./**/collectionProperties.*test.ts",59 "testTokenProperties": "yarn _test ./**/tokenProperties.*test.ts",60 "testMigration": "yarn _test ./**/nesting/migration-check.test.ts",61 "testAddCollectionAdmin": "yarn _test ./**/addCollectionAdmin.test.ts",62 "testSetCollectionLimits": "yarn _test ./**/setCollectionLimits.test.ts",63 "testChangeCollectionOwner": "yarn _test ./**/change-collection-owner.test.ts",64 "testSetCollectionSponsor": "yarn _test ./**/setCollectionSponsor.test.ts",65 "testConfirmSponsorship": "yarn _test ./**/confirmSponsorship.test.ts",66 "testRemoveCollectionAdmin": "yarn _test ./**/removeCollectionAdmin.test.ts",67 "testRemoveCollectionSponsor": "yarn _test ./**/removeCollectionSponsor.test.ts",68 "testAllowLists": "yarn _test ./**/allowLists.test.ts",69 "testConnection": "yarn _test ./**/connection.test.ts",70 "testContracts": "yarn _test ./**/contracts.test.ts",71 "testCreateItem": "yarn _test ./**/createItem.test.ts",72 "testCreateMultipleItems": "yarn _test ./**/createMultipleItems.test.ts",73 "testCreateMultipleItemsEx": "yarn _test ./**/createMultipleItemsEx.test.ts",74 "testApprove": "yarn _test ./**/approve.test.ts",75 "testTransferFrom": "yarn _test ./**/transferFrom.test.ts",76 "testCreateCollection": "yarn _test ./**/createCollection.test.ts",77 "testDestroyCollection": "yarn _test ./**/destroyCollection.test.ts",78 "testToggleContractAllowList": "yarn _test ./**/toggleContractAllowList.test.ts",79 "testAddToContractAllowList": "yarn _test ./**/addToContractAllowList.test.ts",80 "testTransfer": "yarn _test ./**/transfer.test.ts",81 "testBurnItem": "yarn _test ./**/burnItem.test.ts",82 "testAdminTransferAndBurn": "yarn _test ./**/adminTransferAndBurn.test.ts",83 "testSetPermissions": "yarn _test ./**/setPermissions.test.ts",84 "testCreditFeesToTreasury": "yarn _test ./**/creditFeesToTreasury.seqtest.ts",85 "testContractSponsoring": "yarn _test ./**/eth/contractSponsoring.test.ts",86 "testEnableContractSponsoring": "yarn _test ./**/enableContractSponsoring.test.ts",87 "testRemoveFromContractAllowList": "yarn _test ./**/removeFromContractAllowList.test.ts",88 "testSetContractSponsoringRateLimit": "yarn _test ./**/setContractSponsoringRateLimit.test.ts",89 "testSetOffchainSchema": "yarn _test ./**/setOffchainSchema.test.ts",90 "testNextSponsoring": "yarn _test ./**/nextSponsoring.test.ts",91 "testOverflow": "yarn _test ./**/overflow.test.ts",92 "testMaintenance": "yarn _test ./**/maintenance.seqtest.ts",93 "testInflation": "yarn _test ./**/inflation.seqtest.ts",94 "testScheduler": "yarn _test ./**/scheduler.seqtest.ts",95 "testSchedulingEVM": "yarn _test ./**/eth/scheduling.test.ts",96 "testPalletPresence": "yarn _test ./**/pallet-presence.test.ts",97 "testEnableDisableTransfers": "yarn _test ./**/enableDisableTransfer.test.ts",98 "testLimits": "yarn _test ./**/limits.test.ts",99 "testEthCreateNFTCollection": "yarn _test ./**/eth/createNFTCollection.test.ts",100 "testEthCreateRFTCollection": "yarn _test ./**/eth/createRFTCollection.test.ts",101 "testEthNFT": "yarn _test ./**/eth/nonFungible.test.ts",102 "testRFT": "yarn _test ./**/refungible.test.ts",103 "testEthRFT": "yarn _test ./**/eth/reFungible.test.ts ./**/eth/reFungibleToken.test.ts",104 "testFT": "yarn _test ./**/fungible.test.ts",105 "testEthFT": "yarn _test ./**/eth/fungible.test.ts",106 "testRPC": "yarn _test ./**/rpc.test.ts",107 "testPromotion": "yarn _test ./**/appPromotion/*test.ts",108 "testApiConsts": "yarn _test ./**/apiConsts.test.ts",109 "testCollators": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collator-selection/**.*test.ts --timeout 49999999",110 "testCollatorSelection": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collatorSelection.*test.ts --timeout 49999999",111 "testIdentity": "RUN_COLLATOR_TESTS=1 yarn _test ./**/identity.*test.ts --timeout 49999999",112 "testXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmUnique.test.ts",113 "testXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmQuartz.test.ts",114 "testXcmOpal": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmOpal.test.ts",115 "testXcmTransferAcala": "yarn _test ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",116 "testXcmTransferStatemine": "yarn _test ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",117 "testXcmTransferMoonbeam": "yarn _test ./**/xcm/xcmTransferMoonbeam.test.ts",118 "benchMintingFee": "ts-node src/benchmarks/mintFee/benchmark.ts",119 "load": "yarn _test './**/*.load.ts'",120 "loadTransfer": "ts-node src/transfer.nload.ts",121 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",122 "polkadot-types-from-defs": "ts-node --esm ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",123 "polkadot-types-from-chain": "ts-node --esm ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",124 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain",125 "generateEnv": "ts-node --esm ./src/generateEnv.ts"126 },127 "author": "",128 "license": "SEE LICENSE IN ../LICENSE",129 "homepage": "",130 "dependencies": {131 "@openzeppelin/contracts": "^4.9.0",132 "@polkadot/api": "10.7.2",133 "@polkadot/rpc-core": "^10.7.2",134 "@polkadot/util": "12.2.1",135 "@polkadot/util-crypto": "12.2.1",136 "@polkadot/wasm-crypto-asmjs": "^7.2.1",137 "@polkadot/wasm-crypto-wasm": "^7.2.1",138 "chai-as-promised": "^7.1.1",139 "chai-like": "^1.1.1",140 "csv-writer": "^1.6.0",141 "find-process": "^1.4.7",142 "lossless-json": "^2.0.9",143 "solc": "0.8.17",144 "web3": "1.10.0"145 },146 "resolutions": {147 "decode-uri-component": "^0.2.1"148 },149 "type": "module"150}1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/typegen": "10.7.2",8 "@types/chai": "^4.3.3",9 "@types/chai-as-promised": "^7.1.5",10 "@types/chai-like": "^1.1.1",11 "@types/chai-subset": "^1.3.3",12 "@types/mocha": "^10.0.0",13 "@types/node": "^20.2.3",14 "@typescript-eslint/eslint-plugin": "^5.47.0",15 "@typescript-eslint/parser": "^5.47.0",16 "@zombienet/orchestrator": "https://gitpkg.now.sh/UniqueNetwork/zombienet/javascript/packages/orchestrator?2476ea76a368f1b1e94038dbfec29c27f114288e",17 "@zombienet/utils": "https://gitpkg.now.sh/UniqueNetwork/zombienet/javascript/packages/utils?2476ea76a368f1b1e94038dbfec29c27f114288e",18 "chai": "^4.3.6",19 "chai-subset": "^1.6.0",20 "eslint": "^8.25.0",21 "eslint-plugin-mocha": "^10.1.0",22 "mocha": "^10.1.0",23 "ts-node": "^10.9.1",24 "typescript": "^5.0.4"25 },26 "mocha": {27 "timeout": 9999999,28 "require": [29 "ts-node/register"30 ]31 },32 "scripts": {33 "lint": "eslint --ext .ts,.js src/",34 "fix": "yarn lint --fix",35 "setup": "ts-node --esm ./src/util/globalSetup.ts",36 "setIdentities": "ts-node --esm ./src/util/identitySetter.ts",37 "checkRelayIdentities": "ts-node --esm ./src/util/relayIdentitiesChecker.ts",38 "frankenstein": "ts-node --esm ./src/util/frankenstein.ts",39 "_test": "yarn setup && mocha --timeout 9999999 --loader=ts-node/esm.mjs",40 "_testParallel": "yarn setup && mocha --timeout 9999999 --parallel --loader=ts-node/esm.mjs",41 "test": "yarn _test './src/**/*.*test.ts'",42 "testParallelFull": "yarn testParallel && yarn testSequential",43 "testParallel": "yarn _testParallel './src/**/*.test.ts'",44 "testSequential": "yarn _test './src/**/*.seqtest.ts'",45 "testStructure": "yarn _test ./**/nesting/*.*test.ts",46 "testEth": "yarn _test './**/eth/**/*.*test.ts'",47 "testEthNesting": "yarn _test './**/eth/nesting/**/*.*test.ts'",48 "testEthFractionalizer": "yarn _test './**/eth/fractionalizer/**/*.*test.ts'",49 "testEthMarketplace": "yarn _test './**/eth/marketplace/**/*.*test.ts'",50 "testEthMarket": "yarn _test './**/eth/marketplace-v2/**/*.*test.ts'",51 "testSub": "yarn _test './**/sub/**/*.*test.ts'",52 "testSubNesting": "yarn _test './**/sub/nesting/**/*.*test.ts'",53 "testEvent": "yarn _test ./src/check-event/*.*test.ts",54 "testEthPayable": "yarn _test './**/eth/payable.test.ts'",55 "testEvmCoder": "yarn _test './**/eth/evmCoder.test.ts'",56 "testNesting": "yarn _test ./**/nest.test.ts",57 "testUnnesting": "yarn _test ./**/unnest.test.ts",58 "testProperties": "yarn _test ./**/collectionProperties.*test.ts ./**/tokenProperties.*test.ts ./**/getPropertiesRpc.test.ts",59 "testCollectionProperties": "yarn _test ./**/collectionProperties.*test.ts",60 "testTokenProperties": "yarn _test ./**/tokenProperties.*test.ts",61 "testMigration": "yarn _test ./**/nesting/migration-check.test.ts",62 "testAddCollectionAdmin": "yarn _test ./**/addCollectionAdmin.test.ts",63 "testSetCollectionLimits": "yarn _test ./**/setCollectionLimits.test.ts",64 "testChangeCollectionOwner": "yarn _test ./**/change-collection-owner.test.ts",65 "testSetCollectionSponsor": "yarn _test ./**/setCollectionSponsor.test.ts",66 "testConfirmSponsorship": "yarn _test ./**/confirmSponsorship.test.ts",67 "testRemoveCollectionAdmin": "yarn _test ./**/removeCollectionAdmin.test.ts",68 "testRemoveCollectionSponsor": "yarn _test ./**/removeCollectionSponsor.test.ts",69 "testAllowLists": "yarn _test ./**/allowLists.test.ts",70 "testConnection": "yarn _test ./**/connection.test.ts",71 "testContracts": "yarn _test ./**/contracts.test.ts",72 "testCreateItem": "yarn _test ./**/createItem.test.ts",73 "testCreateMultipleItems": "yarn _test ./**/createMultipleItems.test.ts",74 "testCreateMultipleItemsEx": "yarn _test ./**/createMultipleItemsEx.test.ts",75 "testApprove": "yarn _test ./**/approve.test.ts",76 "testTransferFrom": "yarn _test ./**/transferFrom.test.ts",77 "testCreateCollection": "yarn _test ./**/createCollection.test.ts",78 "testDestroyCollection": "yarn _test ./**/destroyCollection.test.ts",79 "testToggleContractAllowList": "yarn _test ./**/toggleContractAllowList.test.ts",80 "testAddToContractAllowList": "yarn _test ./**/addToContractAllowList.test.ts",81 "testTransfer": "yarn _test ./**/transfer.test.ts",82 "testBurnItem": "yarn _test ./**/burnItem.test.ts",83 "testAdminTransferAndBurn": "yarn _test ./**/adminTransferAndBurn.test.ts",84 "testSetPermissions": "yarn _test ./**/setPermissions.test.ts",85 "testCreditFeesToTreasury": "yarn _test ./**/creditFeesToTreasury.seqtest.ts",86 "testContractSponsoring": "yarn _test ./**/eth/contractSponsoring.test.ts",87 "testEnableContractSponsoring": "yarn _test ./**/enableContractSponsoring.test.ts",88 "testRemoveFromContractAllowList": "yarn _test ./**/removeFromContractAllowList.test.ts",89 "testSetContractSponsoringRateLimit": "yarn _test ./**/setContractSponsoringRateLimit.test.ts",90 "testSetOffchainSchema": "yarn _test ./**/setOffchainSchema.test.ts",91 "testNextSponsoring": "yarn _test ./**/nextSponsoring.test.ts",92 "testOverflow": "yarn _test ./**/overflow.test.ts",93 "testMaintenance": "yarn _test ./**/maintenance.seqtest.ts",94 "testInflation": "yarn _test ./**/inflation.seqtest.ts",95 "testScheduler": "yarn _test ./**/scheduler.seqtest.ts",96 "testSchedulingEVM": "yarn _test ./**/eth/scheduling.test.ts",97 "testPalletPresence": "yarn _test ./**/pallet-presence.test.ts",98 "testEnableDisableTransfers": "yarn _test ./**/enableDisableTransfer.test.ts",99 "testLimits": "yarn _test ./**/limits.test.ts",100 "testEthCreateNFTCollection": "yarn _test ./**/eth/createNFTCollection.test.ts",101 "testEthCreateRFTCollection": "yarn _test ./**/eth/createRFTCollection.test.ts",102 "testEthNFT": "yarn _test ./**/eth/nonFungible.test.ts",103 "testRFT": "yarn _test ./**/refungible.test.ts",104 "testEthRFT": "yarn _test ./**/eth/reFungible.test.ts ./**/eth/reFungibleToken.test.ts",105 "testFT": "yarn _test ./**/fungible.test.ts",106 "testEthFT": "yarn _test ./**/eth/fungible.test.ts",107 "testRPC": "yarn _test ./**/rpc.test.ts",108 "testPromotion": "yarn _test ./**/appPromotion/*test.ts",109 "testApiConsts": "yarn _test ./**/apiConsts.test.ts",110 "testCollators": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collator-selection/**.*test.ts --timeout 49999999",111 "testCollatorSelection": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collatorSelection.*test.ts --timeout 49999999",112 "testIdentity": "RUN_COLLATOR_TESTS=1 yarn _test ./**/identity.*test.ts --timeout 49999999",113 "testXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmUnique.test.ts",114 "testXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmQuartz.test.ts",115 "testXcmOpal": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmOpal.test.ts",116 "testXcmTransferAcala": "yarn _test ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",117 "testXcmTransferStatemine": "yarn _test ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",118 "testXcmTransferMoonbeam": "yarn _test ./**/xcm/xcmTransferMoonbeam.test.ts",119 "benchMintingFee": "ts-node src/benchmarks/mintFee/benchmark.ts",120 "load": "yarn _test './**/*.load.ts'",121 "loadTransfer": "ts-node src/transfer.nload.ts",122 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",123 "polkadot-types-from-defs": "ts-node --esm ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",124 "polkadot-types-from-chain": "ts-node --esm ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",125 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain",126 "generateEnv": "ts-node --esm ./src/generateEnv.ts"127 },128 "author": "",129 "license": "SEE LICENSE IN ../LICENSE",130 "homepage": "",131 "dependencies": {132 "@openzeppelin/contracts": "^4.9.0",133 "@polkadot/api": "10.7.2",134 "@polkadot/rpc-core": "^10.7.2",135 "@polkadot/util": "12.2.1",136 "@polkadot/util-crypto": "12.2.1",137 "@polkadot/wasm-crypto-asmjs": "^7.2.1",138 "@polkadot/wasm-crypto-wasm": "^7.2.1",139 "chai-as-promised": "^7.1.1",140 "chai-like": "^1.1.1",141 "csv-writer": "^1.6.0",142 "find-process": "^1.4.7",143 "lossless-json": "^2.0.9",144 "solc": "0.8.17",145 "web3": "1.10.0"146 },147 "resolutions": {148 "decode-uri-component": "^0.2.1"149 },150 "type": "module"151}tests/src/eth/marketplace-v2/Market.soldiffbeforeafterboth--- a/tests/src/eth/marketplace-v2/Market.sol
+++ b/tests/src/eth/marketplace-v2/Market.sol
@@ -1,13 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
+import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
+import "@openzeppelin/contracts/access/Ownable.sol";
import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";
+import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";
import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
import "./royalty/UniqueRoyaltyHelper.sol";
-contract Market {
+contract Market is Ownable, ReentrancyGuard {
using ERC165Checker for address;
struct Order {
@@ -20,6 +23,7 @@
}
uint32 public constant version = 0;
+ uint32 public constant buildVersion = 3;
bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;
bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;
CollectionHelpers private constant collectionHelpers =
@@ -29,7 +33,6 @@
uint32 private idCount = 1;
uint32 public marketFee;
uint64 public ctime;
- address selfAddress;
address public ownerAddress;
mapping(address => bool) public admins;
@@ -55,15 +58,11 @@
error OrderNotFound();
error TooManyAmountRequested();
error NotEnoughMoneyError();
+ error InvalidRoyaltiesError(uint256 totalRoyalty);
error FailTransferToken(string reason);
-
- modifier onlyOwner() {
- require(msg.sender == ownerAddress, "Only owner can");
- _;
- }
modifier onlyAdmin() {
- require(msg.sender == ownerAddress || admins[msg.sender], "Only admin can");
+ require(msg.sender == this.owner() || admins[msg.sender], "Only admin can");
_;
}
@@ -83,13 +82,22 @@
marketFee = fee;
ctime = timestamp;
- if (marketFee == 0 || marketFee >= 100) {
+ if (marketFee >= 100) {
revert InvalidMarketFee();
}
+ }
+
+ /**
+ * Fallback that allows this contract to receive native token.
+ * We need this for self-sponsoring
+ */
+ fallback() external payable {}
- ownerAddress = msg.sender;
- selfAddress = address(this);
- }
+ /**
+ * Receive also allows this contract to receive native token.
+ * We need this for self-sponsoring
+ */
+ receive() external payable {}
function getErc721(uint32 collectionId) private view returns (IERC721) {
address collectionAddress = collectionHelpers.collectionAddress(
@@ -110,36 +118,35 @@
}
return IERC721(collectionAddress);
- }
-
- // ################################################################
- // Set new contract owner #
- // ################################################################
-
- function setOwner() public onlyOwner {
- ownerAddress = msg.sender;
}
-
- // ################################################################
- // Add new admin #
- // ################################################################
+ /**
+ * Add new admin. Only owner or an existing admin can add admins.
+ *
+ * @param admin: Address of a new admin to add
+ */
function addAdmin(address admin) public onlyAdmin {
admins[admin] = true;
}
- // ################################################################
- // Remove admin #
- // ################################################################
-
+ /**
+ * Remove an admin. Only owner or an existing admin can remove admins.
+ *
+ * @param admin: Address of a new admin to add
+ */
function removeAdmin(address admin) public onlyAdmin {
delete admins[admin];
}
- // ################################################################
- // Place a token for sale #
- // ################################################################
-
+ /**
+ * Place an NFT or RFT token for sale. It must be pre-approved for transfers by this contract address.
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ * @param price: Price (with proper network currency decimals)
+ * @param amount: Number of token fractions to list (must always be 1 for NFT)
+ * @param seller: The seller cross-address (the beneficiary account to receive payment, may be different from transaction sender)
+ */
function put(
uint32 collectionId,
uint32 tokenId,
@@ -164,7 +171,7 @@
revert SellerIsNotOwner();
}
- if (erc721.getApproved(tokenId) != selfAddress) {
+ if (erc721.getApproved(tokenId) != address(this)) {
revert TokenIsNotApproved();
}
@@ -182,11 +189,14 @@
emit TokenIsUpForSale(version, order);
}
-
- // ################################################################
- // Get order #
- // ################################################################
+ /**
+ * Get information about the listed token order
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ * @return The order information
+ */
function getOrder(
uint32 collectionId,
uint32 tokenId
@@ -194,10 +204,13 @@
return orders[collectionId][tokenId];
}
- // ################################################################
- // Revoke the token from the sale #
- // ################################################################
-
+ /**
+ * Revoke the token from the sale. Only the original lister can use this method.
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ * @param amount: Number of token fractions to de-list (must always be 1 for NFT)
+ */
function revoke(
uint32 collectionId,
uint32 tokenId,
@@ -239,10 +252,12 @@
emit TokenRevoke(version, order, amount);
}
- // ################################################################
- // Check approved #
- // ################################################################
-
+ /**
+ * Test if the token is still approved to be transferred by this contract and delete the order if not.
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ */
function checkApproved(uint32 collectionId, uint32 tokenId) public onlyAdmin {
Order memory order = orders[collectionId][tokenId];
if (order.price == 0) {
@@ -251,7 +266,7 @@
IERC721 erc721 = getErc721(collectionId);
- if (erc721.getApproved(tokenId) != selfAddress) {
+ if (erc721.getApproved(tokenId) != address(this) || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {
uint32 amount = order.amount;
order.amount = 0;
emit TokenRevoke(version, order, amount);
@@ -262,16 +277,47 @@
}
}
- // ################################################################
- // Buy a token #
- // ################################################################
+ function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {
+ if (account.eth != address(0)) {
+ return account.eth;
+ } else {
+ return address(uint160(account.sub >> 96));
+ }
+ }
+
+ /**
+ * Revoke the token from the sale. Only the contract admin can use this method.
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ */
+ function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {
+ Order memory order = orders[collectionId][tokenId];
+ if (order.price == 0) {
+ revert OrderNotFound();
+ }
+ uint32 amount = order.amount;
+ order.amount = 0;
+ emit TokenRevoke(version, order, amount);
+
+ delete orders[collectionId][tokenId];
+ }
+
+ /**
+ * Buy a token (partially for an RFT).
+ *
+ * @param collectionId: ID of the token collection
+ * @param tokenId: ID of the token
+ * @param amount: Number of token fractions to buy (must always be 1 for NFT)
+ * @param buyer: Cross-address of the buyer, eth part must be equal to the transaction signer address
+ */
function buy(
uint32 collectionId,
uint32 tokenId,
uint32 amount,
CrossAddress memory buyer
- ) public payable validCrossAddress(buyer.eth, buyer.sub) {
+ ) public payable validCrossAddress(buyer.eth, buyer.sub) nonReentrant {
if (msg.value == 0) {
revert InvalidArgument("msg.value must not be zero");
}
@@ -296,7 +342,7 @@
}
IERC721 erc721 = getErc721(order.collectionId);
- if (erc721.getApproved(tokenId) != selfAddress) {
+ if (erc721.getApproved(tokenId) != address(this)) {
revert TokenIsNotApproved();
}
@@ -316,26 +362,30 @@
order.tokenId
);
- (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue);
+ (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue - feeValue);
+ if (totalRoyalty >= totalValue - feeValue) {
+ revert InvalidRoyaltiesError(totalRoyalty);
+ }
+
sendMoney(order.seller, totalValue - feeValue - totalRoyalty);
if (msg.value > totalValue) {
- // todo, send money to signer or buyer ?
- payable(msg.sender).transfer(msg.value - totalValue);
+ sendMoney(buyer, msg.value - totalValue);
}
emit TokenIsPurchased(version, order, amount, buyer, royalties);
}
function sendMoney(CrossAddress memory to, uint256 money) private {
- address payable eth;
- if (to.eth != address(0)) {
- eth = payable(to.eth);
- } else {
- eth = payable(address(uint160(to.sub >> 96)));
- }
- eth.transfer(money);
+ address collectionAddress = collectionHelpers.collectionAddress(0);
+
+ UniqueFungible fungible = UniqueFungible(collectionAddress);
+
+ CrossAddressF memory fromF = CrossAddressF(address(this), 0);
+ CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);
+
+ fungible.transferFromCross(fromF, toF, money);
}
function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {
@@ -355,7 +405,7 @@
}
function withdraw(address transferTo) public onlyOwner {
- uint256 balance = selfAddress.balance;
+ uint256 balance = address(this).balance;
if (balance > 0) {
payable(transferTo).transfer(balance);
tests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth--- a/tests/src/eth/marketplace-v2/marketplace.test.ts
+++ b/tests/src/eth/marketplace-v2/marketplace.test.ts
@@ -16,13 +16,15 @@
import {IKeyringPair} from '@polkadot/types/types';
import {readFile} from 'fs/promises';
-import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';
+import {EthUniqueHelper, SponsoringMode, itEth, usingEthPlaygrounds} from '../util';
import {makeNames} from '../../util';
import {expect} from 'chai';
import Web3 from 'web3';
const {dirname} = makeNames(import.meta.url);
+const MARKET_FEE = 1;
+
describe('Market V2 Contract', () => {
let donor: IKeyringPair;
@@ -43,10 +45,26 @@
fsPath: `${dirname}/../api/UniqueNFT.sol`,
},
{
+ solPath: '@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol',
+ fsPath: `${dirname}/../api/UniqueFungible.sol`,
+ },
+ {
solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',
fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,
},
{
+ solPath: '@openzeppelin/contracts/access/Ownable.sol',
+ fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/access/Ownable.sol`,
+ },
+ {
+ solPath: '@openzeppelin/contracts/utils/Context.sol',
+ fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/Context.sol`,
+ },
+ {
+ solPath: '@openzeppelin/contracts/security/ReentrancyGuard.sol',
+ fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol`,
+ },
+ {
solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',
fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,
},
@@ -72,7 +90,7 @@
},
],
15000000,
- [1, 0],
+ [MARKET_FEE, 0],
);
}
@@ -90,63 +108,135 @@
});
itEth('Put + Buy [eth]', async ({helper}) => {
- const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);
+ const ONE_TOKEN = helper.balance.getOneTokenNominal();
+ const PRICE = 2n * ONE_TOKEN; // 2 UNQ
+ const marketOwner = await helper.eth.createAccountWithBalance(donor, 60000n);
const market = await deployMarket(helper, marketOwner);
+ const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);
+
+ // Set external sponsoring
+ await contractHelpers.methods.setSponsor(market.options.address, marketOwner).send({from: marketOwner});
+ await contractHelpers.methods.confirmSponsorship(market.options.address).send({from: marketOwner});
+ // Configure sponsoring
+ await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});
+ await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});
+
const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);
+
+ // Set collection sponsoring
+ await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});
+ await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});
- const sellerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);
+ const sellerCross = helper.ethCrossAccount.createAccount();
const result = await collection.methods.mintCross(sellerCross, []).send();
const tokenId = result.events.Transfer.returnValues.tokenId;
await collection.methods.approve(market.options.address, tokenId).send({from: sellerCross.eth});
- const putResult = await market.methods.put(collectionId, tokenId, 1, 1, sellerCross).send({from: sellerCross.eth});
+ // Seller has no funds at all, his transactions are sponsored
+ const sellerBalance = await helper.balance.getEthereum(sellerCross.eth);
+ expect(sellerBalance).to.be.eq(0n);
+
+ const putResult = await market.methods.put(collectionId, tokenId, PRICE.toString(), 1, sellerCross).send({
+ from: sellerCross.eth, gasLimit: 1_000_000,
+ });
expect(putResult.events.TokenIsUpForSale).is.not.undefined;
+
+ // Seller balance are still 0
+ const sellerBalanceAfter = await helper.balance.getEthereum(sellerCross.eth);
+ expect(sellerBalanceAfter).to.be.eq(0n);
+
let ownerCross = await collection.methods.ownerOfCross(tokenId).call();
expect(ownerCross.eth).to.be.eq(sellerCross.eth);
expect(ownerCross.sub).to.be.eq(sellerCross.sub);
- const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);
- const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: 1});
+ const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 10n);
+
+ // Buyer has only 10 UNQ
+ const buyerBalance = await helper.balance.getEthereum(buyerCross.eth);
+ expect(buyerBalance).to.be.eq(10n * ONE_TOKEN);
+
+ const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: PRICE.toString(), gasLimit: 1_000_000});
expect(buyResult.events.TokenIsPurchased).is.not.undefined;
+
+ // Buyer pays only value, transaction use sponsoring
+ const buyerBalanceAfter = await helper.balance.getEthereum(buyerCross.eth);
+ expect(buyerBalanceAfter).to.be.eq(10n * ONE_TOKEN - PRICE);
+
ownerCross = await collection.methods.ownerOfCross(tokenId).call();
expect(ownerCross.eth).to.be.eq(buyerCross.eth);
expect(ownerCross.sub).to.be.eq(buyerCross.sub);
});
itEth('Put + Buy [sub]', async ({helper}) => {
- const PRICE = 1n;
+ const ONE_TOKEN = helper.balance.getOneTokenNominal();
+ const PRICE = 2n * ONE_TOKEN; // 2 UNQ
const web3 = helper.getWeb3();
const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);
const market = await deployMarket(helper, marketOwner);
+ const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);
+
+ // Set self sponsoring from contract balance
+ await contractHelpers.methods.selfSponsoredEnable(market.options.address).send({from: marketOwner});
+ await helper.eth.transferBalanceFromSubstrate(donor, market.options.address, 10n);
+
+ // Configure sponsoring
+ await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});
+ await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});
const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');
- const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);
+
+ // Set collection sponsoring
+ await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});
+ await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});
- const [seller] = await helper.arrange.createAccounts([600n], donor);
- const sellerMirror = helper.address.substrateToEth(seller.address);
+ const seller = helper.util.fromSeed(`//Market-seller-${(new Date()).getTime()}`);
const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);
+
+ // Seller has no funds at all, his transactions are sponsored
+ {
+ const sellerBalance = await helper.balance.getSubstrate(seller.address);
+ expect(sellerBalance).to.be.eq(0n);
+ }
+
const result = await collection.methods.mintCross(sellerCross, []).send();
const tokenId = result.events.Transfer.returnValues.tokenId;
- await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address}, 1n);
+ await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address});
await helper.eth.sendEVM(seller, market.options.address, market.methods.put(collectionId, tokenId, PRICE, 1, sellerCross).encodeABI(), '0');
+ // Seller balance is still zero
+ {
+ const sellerBalance = await helper.balance.getSubstrate(seller.address);
+ expect(sellerBalance).to.be.eq(0n);
+ }
let ownerCross = await collection.methods.ownerOfCross(tokenId).call();
expect(ownerCross.eth).to.be.eq(sellerCross.eth);
expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(sellerCross.sub, web3));
const [buyer] = await helper.arrange.createAccounts([600n], donor);
+ // Buyer has only expected balance
+ {
+ const buyerBalance = await helper.balance.getSubstrate(buyer.address);
+ expect(buyerBalance).to.be.eq(600n * ONE_TOKEN);
+ }
const buyerMirror = helper.address.substrateToEth(buyer.address);
const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);
- await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, 1n);
- //TODO: change balance check to helper.balance.getSubstrate when implementation of sendMoney will be fixed in contract
- const sellerBalance = BigInt(await web3.eth.getBalance(sellerMirror));
+ await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, PRICE, false);
+
+ const buyerBalanceBefore = await helper.balance.getSubstrate(buyer.address);
await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());
- const sellerBalanceAfterBuy = BigInt(await web3.eth.getBalance(sellerMirror));
+ const buyerBalanceAfter = await helper.balance.getSubstrate(buyer.address);
+ // Buyer balance not changed: transaction is sponsored
+ expect(buyerBalanceBefore).to.be.eq(buyerBalanceAfter);
+
+ const sellerBalanceAfterBuy = BigInt(await helper.balance.getSubstrate(seller.address));
ownerCross = await collection.methods.ownerOfCross(tokenId).call();
expect(ownerCross.eth).to.be.eq(buyerCross.eth);
expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));
- expect(sellerBalance + PRICE).to.be.equal(sellerBalanceAfterBuy);
+
+ // Seller got only PRICE - MARKET_FEE
+ expect(sellerBalanceAfterBuy).to.be.eq(PRICE * BigInt(100 - MARKET_FEE) / 100n);
});
});
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -561,10 +561,10 @@
itEth.ifWithPallets(`[${testCase.mode}] Can't be multiple set/read for non-existent token`, testCase.requiredPallets, async({helper}) => {
const caller = await helper.eth.createAccountWithBalance(donor);
- const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
+ const properties = Array(5).fill(0).map((_, i) => ({key: `key_${i}`, value: Buffer.from(`value_${i}`)}));
+ const permissions: ITokenPropertyPermission[] = properties.map(p => ({key: p.key, permission: {tokenOwner: true,
collectionAdmin: true,
- mutable: true}}; });
+ mutable: true}}));
const collection = await helper[testCase.mode].mintCollection(alice, {
tokenPrefix: 'ethp',