git.delta.rocks / unique-network / refs/commits / 1913bf6018fe

difftreelog

Merge pull request #954 from UniqueNetwork/feature/update_market_v2_contract

Yaroslav Bolyukin2023-06-29parents: #ef738f7 #54a7967.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -47,6 +47,7 @@
     "testEthNesting": "yarn _test './**/eth/nesting/**/*.*test.ts'",
     "testEthFractionalizer": "yarn _test './**/eth/fractionalizer/**/*.*test.ts'",
     "testEthMarketplace": "yarn _test './**/eth/marketplace/**/*.*test.ts'",
+    "testEthMarket": "yarn _test './**/eth/marketplace-v2/**/*.*test.ts'",
     "testSub": "yarn _test './**/sub/**/*.*test.ts'",
     "testSubNesting": "yarn _test './**/sub/nesting/**/*.*test.ts'",
     "testEvent": "yarn _test ./src/check-event/*.*test.ts",
modifiedtests/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);
modifiedtests/src/eth/marketplace-v2/marketplace.test.tsdiffbeforeafterboth
before · tests/src/eth/marketplace-v2/marketplace.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {readFile} from 'fs/promises';19import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util';20import {makeNames} from '../../util';21import {expect} from 'chai';22import Web3 from 'web3';2324const {dirname} = makeNames(import.meta.url);2526describe('Market V2 Contract', () => {27  let donor: IKeyringPair;2829  before(async () => {30    await usingEthPlaygrounds(async (_helper, privateKey) => {31      donor = await privateKey({url: import.meta.url});32    });33  });3435  async function deployMarket(helper: EthUniqueHelper, marketOwner: string) {36    return await helper.ethContract.deployByCode(37      marketOwner,38      'Market',39      (await readFile(`${dirname}/Market.sol`)).toString(),40      [41        {42          solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',43          fsPath: `${dirname}/../api/UniqueNFT.sol`,44        },45        {46          solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',47          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,48        },49        {50          solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',51          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,52        },53        {54          solPath: '@openzeppelin/contracts/token/ERC721/IERC721.sol',55          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol`,56        },57        {58          solPath: '@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol',59          fsPath: `${dirname}/../api/CollectionHelpers.sol`,60        },61        {62          solPath: 'royalty/UniqueRoyaltyHelper.sol',63          fsPath: `${dirname}/royalty/UniqueRoyaltyHelper.sol`,64        },65        {66          solPath: 'royalty/UniqueRoyalty.sol',67          fsPath: `${dirname}/royalty/UniqueRoyalty.sol`,68        },69        {70          solPath: 'royalty/LibPart.sol',71          fsPath: `${dirname}/royalty/LibPart.sol`,72        },73      ],74      15000000,75      [1, 0],76    );77  }7879  function substrateAddressToHex(sub: Uint8Array| string, web3: Web3) {80    if(typeof sub === 'string')81      return web3.utils.padLeft(web3.utils.toHex(web3.utils.toBN(sub)), 64);82    else if(sub instanceof Uint8Array)83      return web3.utils.padLeft(web3.utils.bytesToHex(Array.from(sub)), 64);84  }8586  itEth('Deploy', async ({helper}) => {87    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);8889    await deployMarket(helper, marketOwner);90  });9192  itEth('Put + Buy [eth]', async ({helper}) => {93    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);94    const market = await deployMarket(helper, marketOwner);9596    const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');97    const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);9899    const sellerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);100    const result = await collection.methods.mintCross(sellerCross, []).send();101    const tokenId = result.events.Transfer.returnValues.tokenId;102    await collection.methods.approve(market.options.address, tokenId).send({from: sellerCross.eth});103104    const putResult = await market.methods.put(collectionId, tokenId, 1, 1, sellerCross).send({from: sellerCross.eth});105    expect(putResult.events.TokenIsUpForSale).is.not.undefined;106    let ownerCross = await collection.methods.ownerOfCross(tokenId).call();107    expect(ownerCross.eth).to.be.eq(sellerCross.eth);108    expect(ownerCross.sub).to.be.eq(sellerCross.sub);109110    const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 600n);111    const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: 1});112    expect(buyResult.events.TokenIsPurchased).is.not.undefined;113    ownerCross = await collection.methods.ownerOfCross(tokenId).call();114    expect(ownerCross.eth).to.be.eq(buyerCross.eth);115    expect(ownerCross.sub).to.be.eq(buyerCross.sub);116  });117118  itEth('Put + Buy [sub]', async ({helper}) => {119    const PRICE = 1n;120    const web3 = helper.getWeb3();121    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);122    const market = await deployMarket(helper, marketOwner);123124    const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');125    const collection = await helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner);126127    const [seller] = await helper.arrange.createAccounts([600n], donor);128    const sellerMirror = helper.address.substrateToEth(seller.address);129    const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);130    const result = await collection.methods.mintCross(sellerCross, []).send();131    const tokenId = result.events.Transfer.returnValues.tokenId;132    await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address}, 1n);133134    await helper.eth.sendEVM(seller, market.options.address, market.methods.put(collectionId, tokenId, PRICE, 1, sellerCross).encodeABI(), '0');135    let ownerCross = await collection.methods.ownerOfCross(tokenId).call();136    expect(ownerCross.eth).to.be.eq(sellerCross.eth);137    expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(sellerCross.sub, web3));138139    const [buyer] = await helper.arrange.createAccounts([600n], donor);140    const buyerMirror = helper.address.substrateToEth(buyer.address);141    const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);142    await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, 1n);143    //TODO: change balance check to helper.balance.getSubstrate when implementation of sendMoney will be fixed in contract144    const sellerBalance = BigInt(await web3.eth.getBalance(sellerMirror));145    await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());146    const sellerBalanceAfterBuy = BigInt(await web3.eth.getBalance(sellerMirror));147    ownerCross = await collection.methods.ownerOfCross(tokenId).call();148    expect(ownerCross.eth).to.be.eq(buyerCross.eth);149    expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));150    expect(sellerBalance + PRICE).to.be.equal(sellerBalanceAfterBuy);151  });152});
after · tests/src/eth/marketplace-v2/marketplace.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {readFile} from 'fs/promises';19import {EthUniqueHelper, SponsoringMode, itEth, usingEthPlaygrounds} from '../util';20import {makeNames} from '../../util';21import {expect} from 'chai';22import Web3 from 'web3';2324const {dirname} = makeNames(import.meta.url);2526const MARKET_FEE = 1;2728describe('Market V2 Contract', () => {29  let donor: IKeyringPair;3031  before(async () => {32    await usingEthPlaygrounds(async (_helper, privateKey) => {33      donor = await privateKey({url: import.meta.url});34    });35  });3637  async function deployMarket(helper: EthUniqueHelper, marketOwner: string) {38    return await helper.ethContract.deployByCode(39      marketOwner,40      'Market',41      (await readFile(`${dirname}/Market.sol`)).toString(),42      [43        {44          solPath: '@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol',45          fsPath: `${dirname}/../api/UniqueNFT.sol`,46        },47        {48          solPath: '@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol',49          fsPath: `${dirname}/../api/UniqueFungible.sol`,50        },51        {52          solPath: '@openzeppelin/contracts/utils/introspection/IERC165.sol',53          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol`,54        },55        {56          solPath: '@openzeppelin/contracts/access/Ownable.sol',57          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/access/Ownable.sol`,58        },59        {60          solPath: '@openzeppelin/contracts/utils/Context.sol',61          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/Context.sol`,62        },63        {64          solPath: '@openzeppelin/contracts/security/ReentrancyGuard.sol',65          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol`,66        },67        {68          solPath: '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol',69          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol`,70        },71        {72          solPath: '@openzeppelin/contracts/token/ERC721/IERC721.sol',73          fsPath: `${dirname}/../../../node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol`,74        },75        {76          solPath: '@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol',77          fsPath: `${dirname}/../api/CollectionHelpers.sol`,78        },79        {80          solPath: 'royalty/UniqueRoyaltyHelper.sol',81          fsPath: `${dirname}/royalty/UniqueRoyaltyHelper.sol`,82        },83        {84          solPath: 'royalty/UniqueRoyalty.sol',85          fsPath: `${dirname}/royalty/UniqueRoyalty.sol`,86        },87        {88          solPath: 'royalty/LibPart.sol',89          fsPath: `${dirname}/royalty/LibPart.sol`,90        },91      ],92      15000000,93      [MARKET_FEE, 0],94    );95  }9697  function substrateAddressToHex(sub: Uint8Array| string, web3: Web3) {98    if(typeof sub === 'string')99      return web3.utils.padLeft(web3.utils.toHex(web3.utils.toBN(sub)), 64);100    else if(sub instanceof Uint8Array)101      return web3.utils.padLeft(web3.utils.bytesToHex(Array.from(sub)), 64);102  }103104  itEth('Deploy', async ({helper}) => {105    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);106107    await deployMarket(helper, marketOwner);108  });109110  itEth('Put + Buy [eth]', async ({helper}) => {111    const ONE_TOKEN = helper.balance.getOneTokenNominal();112    const PRICE = 2n * ONE_TOKEN;  // 2 UNQ113    const marketOwner = await helper.eth.createAccountWithBalance(donor, 60000n);114    const market = await deployMarket(helper, marketOwner);115    const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);116117    // Set external sponsoring118    await contractHelpers.methods.setSponsor(market.options.address, marketOwner).send({from: marketOwner});119    await contractHelpers.methods.confirmSponsorship(market.options.address).send({from: marketOwner});120121    // Configure sponsoring122    await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});123    await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});124125    const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');126    const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);127128    // Set collection sponsoring129    await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});130    await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});131132    const sellerCross = helper.ethCrossAccount.createAccount();133    const result = await collection.methods.mintCross(sellerCross, []).send();134    const tokenId = result.events.Transfer.returnValues.tokenId;135    await collection.methods.approve(market.options.address, tokenId).send({from: sellerCross.eth});136137    // Seller has no funds at all, his transactions are sponsored138    const sellerBalance = await helper.balance.getEthereum(sellerCross.eth);139    expect(sellerBalance).to.be.eq(0n);140141    const putResult = await market.methods.put(collectionId, tokenId, PRICE.toString(), 1, sellerCross).send({142      from: sellerCross.eth, gasLimit: 1_000_000,143    });144    expect(putResult.events.TokenIsUpForSale).is.not.undefined;145146    // Seller balance are still 0147    const sellerBalanceAfter = await helper.balance.getEthereum(sellerCross.eth);148    expect(sellerBalanceAfter).to.be.eq(0n);149150    let ownerCross = await collection.methods.ownerOfCross(tokenId).call();151    expect(ownerCross.eth).to.be.eq(sellerCross.eth);152    expect(ownerCross.sub).to.be.eq(sellerCross.sub);153154    const buyerCross = await helper.ethCrossAccount.createAccountWithBalance(donor, 10n);155156    // Buyer has only 10 UNQ157    const buyerBalance = await helper.balance.getEthereum(buyerCross.eth);158    expect(buyerBalance).to.be.eq(10n * ONE_TOKEN);159160    const buyResult = await market.methods.buy(collectionId, tokenId, 1, buyerCross).send({from: buyerCross.eth, value: PRICE.toString(), gasLimit: 1_000_000});161    expect(buyResult.events.TokenIsPurchased).is.not.undefined;162163    // Buyer pays only value, transaction use sponsoring164    const buyerBalanceAfter = await helper.balance.getEthereum(buyerCross.eth);165    expect(buyerBalanceAfter).to.be.eq(10n * ONE_TOKEN - PRICE);166167    ownerCross = await collection.methods.ownerOfCross(tokenId).call();168    expect(ownerCross.eth).to.be.eq(buyerCross.eth);169    expect(ownerCross.sub).to.be.eq(buyerCross.sub);170  });171172  itEth('Put + Buy [sub]', async ({helper}) => {173    const ONE_TOKEN = helper.balance.getOneTokenNominal();174    const PRICE = 2n * ONE_TOKEN;  // 2 UNQ175    const web3 = helper.getWeb3();176    const marketOwner = await helper.eth.createAccountWithBalance(donor, 600n);177    const market = await deployMarket(helper, marketOwner);178    const contractHelpers = helper.ethNativeContract.contractHelpers(marketOwner);179180    // Set self sponsoring from contract balance181    await contractHelpers.methods.selfSponsoredEnable(market.options.address).send({from: marketOwner});182    await helper.eth.transferBalanceFromSubstrate(donor, market.options.address, 10n);183184    // Configure sponsoring185    await contractHelpers.methods.setSponsoringMode(market.options.address, SponsoringMode.Generous).send({from: marketOwner});186    await contractHelpers.methods.setSponsoringRateLimit(market.options.address, 0).send({from: marketOwner});187188    const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(marketOwner, 'Sponsor', 'absolutely anything', 'ROC');189    const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', marketOwner, true);190191    // Set collection sponsoring192    await collection.methods.setCollectionSponsor(marketOwner).send({from: marketOwner});193    await collection.methods.confirmCollectionSponsorship().send({from: marketOwner});194195    const seller = helper.util.fromSeed(`//Market-seller-${(new Date()).getTime()}`);196    const sellerCross = helper.ethCrossAccount.fromKeyringPair(seller);197198    // Seller has no funds at all, his transactions are sponsored199    {200      const sellerBalance = await helper.balance.getSubstrate(seller.address);201      expect(sellerBalance).to.be.eq(0n);202    }203204    const result = await collection.methods.mintCross(sellerCross, []).send();205    const tokenId = result.events.Transfer.returnValues.tokenId;206    await helper.nft.approveToken(seller, collectionId, tokenId, {Ethereum: market.options.address});207208    await helper.eth.sendEVM(seller, market.options.address, market.methods.put(collectionId, tokenId, PRICE, 1, sellerCross).encodeABI(), '0');209    // Seller balance is still zero210    {211      const sellerBalance = await helper.balance.getSubstrate(seller.address);212      expect(sellerBalance).to.be.eq(0n);213    }214    let ownerCross = await collection.methods.ownerOfCross(tokenId).call();215    expect(ownerCross.eth).to.be.eq(sellerCross.eth);216    expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(sellerCross.sub, web3));217218    const [buyer] = await helper.arrange.createAccounts([600n], donor);219    // Buyer has only expected balance220    {221      const buyerBalance = await helper.balance.getSubstrate(buyer.address);222      expect(buyerBalance).to.be.eq(600n * ONE_TOKEN);223    }224    const buyerMirror = helper.address.substrateToEth(buyer.address);225    const buyerCross = helper.ethCrossAccount.fromKeyringPair(buyer);226    await helper.eth.transferBalanceFromSubstrate(donor, buyerMirror, PRICE, false);227228    const buyerBalanceBefore = await helper.balance.getSubstrate(buyer.address);229    await helper.eth.sendEVM(buyer, market.options.address, market.methods.buy(collectionId, tokenId, 1, buyerCross).encodeABI(), PRICE.toString());230    const buyerBalanceAfter = await helper.balance.getSubstrate(buyer.address);231    // Buyer balance not changed: transaction is sponsored232    expect(buyerBalanceBefore).to.be.eq(buyerBalanceAfter);233234    const sellerBalanceAfterBuy = BigInt(await helper.balance.getSubstrate(seller.address));235    ownerCross = await collection.methods.ownerOfCross(tokenId).call();236    expect(ownerCross.eth).to.be.eq(buyerCross.eth);237    expect(substrateAddressToHex(ownerCross.sub, web3)).to.be.eq(substrateAddressToHex(buyerCross.sub, web3));238239    // Seller got only PRICE - MARKET_FEE240    expect(sellerBalanceAfterBuy).to.be.eq(PRICE * BigInt(100 - MARKET_FEE) / 100n);241  });242});
modifiedtests/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',