git.delta.rocks / unique-network / refs/commits / e041df2412cb

difftreelog

Test for market sponsoring

Andy Smith2023-06-26parent: #71175e3.patch.diff
in: master

3 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
before · tests/src/eth/marketplace-v2/Market.sol
1// SPDX-License-Identifier: UNLICENSED2pragma solidity 0.8.17;34import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";5import "@openzeppelin/contracts/token/ERC721/IERC721.sol";6import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";7import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";8import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";9import "./royalty/UniqueRoyaltyHelper.sol";1011contract Market {12    using ERC165Checker for address;1314    struct Order {15      uint32 id;16      uint32 collectionId;17      uint32 tokenId;18      uint32 amount;19      uint256 price;20      CrossAddress seller;21    }2223    uint32 public constant version = 0;24    uint32 public constant buildVersion = 1;25    bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;26    bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;27    CollectionHelpers private constant collectionHelpers =28        CollectionHelpers(0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F);2930    mapping(uint32 => mapping(uint32 => Order)) orders;31    uint32 private idCount = 1;32    uint32 public marketFee;33    uint64 public ctime;34    address selfAddress;35    address public ownerAddress;36    mapping(address => bool) public admins;3738    event TokenIsUpForSale(uint32 version, Order item);39    event TokenRevoke(uint32 version, Order item, uint32 amount);40    event TokenIsApproved(uint32 version, Order item);41    event TokenIsPurchased(42      uint32 version,43      Order item,44      uint32 salesAmount,45      CrossAddress buyer,46      RoyaltyAmount[] royalties47    );48    event Log(string message);4950    error InvalidArgument(string info);51    error InvalidMarketFee();52    error SellerIsNotOwner();53    error TokenIsAlreadyOnSale();54    error TokenIsNotApproved();55    error CollectionNotFound();56    error CollectionNotSupportedERC721();57    error OrderNotFound();58    error TooManyAmountRequested();59    error NotEnoughMoneyError();60    error FailTransferToken(string reason);6162    modifier onlyOwner() {63      require(msg.sender == ownerAddress, "Only owner can");64      _;65    }6667    modifier onlyAdmin() {68      require(msg.sender == ownerAddress || admins[msg.sender], "Only admin can");69      _;70    }7172    modifier validCrossAddress(address eth, uint256 sub) {73      if (eth == address(0) && sub == 0) {74        revert InvalidArgument("Ethereum and Substrate addresses cannot be null at the same time");75      }7677      if (eth != address(0) && sub != 0) {78        revert InvalidArgument("Ethereum and Substrate addresses cannot be not null at the same time");79      }8081      _;82    }8384    constructor(uint32 fee, uint64 timestamp) {85        marketFee = fee;86        ctime = timestamp;8788        if (marketFee == 0 || marketFee >= 100) {89            revert InvalidMarketFee();90        }9192        ownerAddress = msg.sender;93        selfAddress = address(this);94    }9596    function getErc721(uint32 collectionId) private view returns (IERC721) {97        address collectionAddress = collectionHelpers.collectionAddress(98            collectionId99        );100101        uint size;102        assembly {103            size := extcodesize(collectionAddress)104        }105106        if (size == 0) {107            revert CollectionNotFound();108        }109110        if (!collectionAddress.supportsInterface(InterfaceId_ERC721)) {111            revert CollectionNotSupportedERC721();112        }113114        return IERC721(collectionAddress);115    }116117    // ################################################################118    // Set new contract owner                                         #119    // ################################################################120121    function setOwner() public onlyOwner {122        ownerAddress = msg.sender;123    }124125    // ################################################################126    // Add new admin                                                  #127    // ################################################################128129    function addAdmin(address admin) public onlyAdmin {130      admins[admin] = true;131    }132133    // ################################################################134    // Remove admin                                                  #135    // ################################################################136137    function removeAdmin(address admin) public onlyAdmin {138      delete admins[admin];139    }140141    // ################################################################142    // Place a token for sale                                         #143    // ################################################################144145    function put(146        uint32 collectionId,147        uint32 tokenId,148        uint256 price,149        uint32 amount,150        CrossAddress memory seller151    ) public validCrossAddress(seller.eth, seller.sub) {152        if (price == 0) {153          revert InvalidArgument("price must not be zero");154        }155        if (amount == 0) {156          revert InvalidArgument("amount must not be zero");157        }158159        if (orders[collectionId][tokenId].price > 0) {160            revert TokenIsAlreadyOnSale();161        }162163        IERC721 erc721 = getErc721(collectionId);164165        if (erc721.ownerOf(tokenId) != msg.sender) {166          revert SellerIsNotOwner();167        }168169        if (erc721.getApproved(tokenId) != selfAddress) {170          revert TokenIsNotApproved();171        }172173        Order memory order = Order(174            0,175            collectionId,176            tokenId,177            amount,178            price,179            seller180        );181182        order.id = idCount++;183        orders[collectionId][tokenId] = order;184185        emit TokenIsUpForSale(version, order);186    }187188    // ################################################################189    // Get order                                                      #190    // ################################################################191192    function getOrder(193        uint32 collectionId,194        uint32 tokenId195    ) external view returns (Order memory) {196        return orders[collectionId][tokenId];197    }198199    // ################################################################200    // Revoke the token from the sale                                 #201    // ################################################################202203    function revoke(204        uint32 collectionId,205        uint32 tokenId,206        uint32 amount207    ) external {208        if (amount == 0) {209          revert InvalidArgument("amount must not be zero");210        }211212        Order memory order = orders[collectionId][tokenId];213214        if (order.price == 0) {215          revert OrderNotFound();216        }217218        if (amount > order.amount) {219          revert TooManyAmountRequested();220        }221222        IERC721 erc721 = getErc721(collectionId);223224        address ethAddress;225        if (order.seller.eth != address(0)) {226          ethAddress = order.seller.eth;227        } else {228          ethAddress = payable(address(uint160(order.seller.sub >> 96)));229        }230        if (erc721.ownerOf(tokenId) != ethAddress) {231          revert SellerIsNotOwner();232        }233234        order.amount -= amount;235        if (order.amount == 0) {236            delete orders[collectionId][tokenId];237        } else {238            orders[collectionId][tokenId] = order;239        }240241        emit TokenRevoke(version, order, amount);242    }243244    // ################################################################245    // Check approved                                                 #246    // ################################################################247248    function checkApproved(uint32 collectionId, uint32 tokenId) public onlyAdmin {249        Order memory order = orders[collectionId][tokenId];250        if (order.price == 0) {251            revert OrderNotFound();252        }253254        IERC721 erc721 = getErc721(collectionId);255256        if (erc721.getApproved(tokenId) != selfAddress || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {257          uint32 amount = order.amount;258          order.amount = 0;259          emit TokenRevoke(version, order, amount);260261          delete orders[collectionId][tokenId];262        } else {263          emit TokenIsApproved(version, order);264        }265    }266267    function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {268        if (account.eth != address(0)) {269            return account.eth;270        } else {271            return address(uint160(account.sub >> 96));272        }273    }274275    function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {276        Order memory order = orders[collectionId][tokenId];277        if (order.price == 0) {278          revert OrderNotFound();279        }280281        uint32 amount = order.amount;282        order.amount = 0;283        emit TokenRevoke(version, order, amount);284285        delete orders[collectionId][tokenId];286    }287288    // ################################################################289    // Buy a token                                                    #290    // ################################################################291292    function buy(293        uint32 collectionId,294        uint32 tokenId,295        uint32 amount,296        CrossAddress memory buyer297    ) public payable validCrossAddress(buyer.eth, buyer.sub) {298        if (msg.value == 0) {299          revert InvalidArgument("msg.value must not be zero");300        }301        if (amount == 0) {302          revert InvalidArgument("amount must not be zero");303        }304305        Order memory order = orders[collectionId][tokenId];306        if (order.price == 0) {307            revert OrderNotFound();308        }309310        if (amount > order.amount) {311            revert TooManyAmountRequested();312        }313314        uint256 totalValue = order.price * amount;315        uint256 feeValue = (totalValue * marketFee) / 100;316317        if (msg.value < totalValue) {318            revert NotEnoughMoneyError();319        }320321        IERC721 erc721 = getErc721(order.collectionId);322        if (erc721.getApproved(tokenId) != selfAddress) {323          revert TokenIsNotApproved();324        }325326        order.amount -= amount;327        if (order.amount == 0) {328            delete orders[collectionId][tokenId];329        } else {330            orders[collectionId][tokenId] = order;331        }332333        address collectionAddress = collectionHelpers.collectionAddress(collectionId);334        UniqueNFT nft = UniqueNFT(collectionAddress);335336        nft.transferFromCross(337          order.seller,338          buyer,339          order.tokenId340        );341342        (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue);343344        sendMoney(order.seller, totalValue - feeValue - totalRoyalty);345346        if (msg.value > totalValue) {347            // todo, send money to signer or buyer ?348            payable(msg.sender).transfer(msg.value - totalValue);349        }350351        emit TokenIsPurchased(version, order, amount, buyer, royalties);352    }353354    function sendMoney(CrossAddress memory to, uint256 money) private {355      address collectionAddress = collectionHelpers.collectionAddress(0);356357      UniqueFungible fungible = UniqueFungible(collectionAddress);358359      CrossAddressF memory fromF = CrossAddressF(selfAddress, 0);360      CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);361362      fungible.transferFromCross(fromF, toF, money);363    }364365    function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {366      RoyaltyAmount[] memory royalties = UniqueRoyaltyHelper.calculate(collection, tokenId, sellPrice);367368      uint256 totalRoyalty = 0;369370      for (uint256 i=0; i<royalties.length; i++) {371        RoyaltyAmount memory royalty = royalties[i];372373        totalRoyalty += royalty.amount;374375        sendMoney(royalty.crossAddress, royalty.amount);376      }377378      return (totalRoyalty, royalties);379    }380381    function withdraw(address transferTo) public onlyOwner {382        uint256 balance = selfAddress.balance;383384        if (balance > 0) {385            payable(transferTo).transfer(balance);386        }387    }388}
after · tests/src/eth/marketplace-v2/Market.sol
1// SPDX-License-Identifier: UNLICENSED2pragma solidity 0.8.17;34import "@openzeppelin/contracts/security/ReentrancyGuard.sol";5import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";6import "@openzeppelin/contracts/token/ERC721/IERC721.sol";7import "@openzeppelin/contracts/access/Ownable.sol";8import { UniqueNFT, CrossAddress } from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";9import { UniqueFungible, CrossAddress as CrossAddressF } from "@unique-nft/solidity-interfaces/contracts/UniqueFungible.sol";10import "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";11import "./royalty/UniqueRoyaltyHelper.sol";1213contract Market is Ownable, ReentrancyGuard {14    using ERC165Checker for address;1516    struct Order {17      uint32 id;18      uint32 collectionId;19      uint32 tokenId;20      uint32 amount;21      uint256 price;22      CrossAddress seller;23    }2425    uint32 public constant version = 0;26    uint32 public constant buildVersion = 3;27    bytes4 private constant InterfaceId_ERC721 = 0x80ac58cd;28    bytes4 private constant InterfaceId_ERC165 = 0x5755c3f2;29    CollectionHelpers private constant collectionHelpers =30        CollectionHelpers(0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F);3132    mapping(uint32 => mapping(uint32 => Order)) orders;33    uint32 private idCount = 1;34    uint32 public marketFee;35    uint64 public ctime;36    address public ownerAddress;37    mapping(address => bool) public admins;3839    event TokenIsUpForSale(uint32 version, Order item);40    event TokenRevoke(uint32 version, Order item, uint32 amount);41    event TokenIsApproved(uint32 version, Order item);42    event TokenIsPurchased(43      uint32 version,44      Order item,45      uint32 salesAmount,46      CrossAddress buyer,47      RoyaltyAmount[] royalties48    );49    event Log(string message);5051    error InvalidArgument(string info);52    error InvalidMarketFee();53    error SellerIsNotOwner();54    error TokenIsAlreadyOnSale();55    error TokenIsNotApproved();56    error CollectionNotFound();57    error CollectionNotSupportedERC721();58    error OrderNotFound();59    error TooManyAmountRequested();60    error NotEnoughMoneyError();61    error InvalidRoyaltiesError(uint256 totalRoyalty);62    error FailTransferToken(string reason);6364    modifier onlyAdmin() {65      require(msg.sender == this.owner() || admins[msg.sender], "Only admin can");66      _;67    }6869    modifier validCrossAddress(address eth, uint256 sub) {70      if (eth == address(0) && sub == 0) {71        revert InvalidArgument("Ethereum and Substrate addresses cannot be null at the same time");72      }7374      if (eth != address(0) && sub != 0) {75        revert InvalidArgument("Ethereum and Substrate addresses cannot be not null at the same time");76      }7778      _;79    }8081    constructor(uint32 fee, uint64 timestamp) {82        marketFee = fee;83        ctime = timestamp;8485        if (marketFee >= 100) {86            revert InvalidMarketFee();87        }88    }8990    function getErc721(uint32 collectionId) private view returns (IERC721) {91        address collectionAddress = collectionHelpers.collectionAddress(92            collectionId93        );9495        uint size;96        assembly {97            size := extcodesize(collectionAddress)98        }99100        if (size == 0) {101            revert CollectionNotFound();102        }103104        if (!collectionAddress.supportsInterface(InterfaceId_ERC721)) {105            revert CollectionNotSupportedERC721();106        }107108        return IERC721(collectionAddress);109    }110111    /**112     * Add new admin. Only owner or an existing admin can add admins.113     *114     * @param admin: Address of a new admin to add115     */116    function addAdmin(address admin) public onlyAdmin {117      admins[admin] = true;118    }119120    /**121     * Remove an admin. Only owner or an existing admin can remove admins.122     *123     * @param admin: Address of a new admin to add124     */125    function removeAdmin(address admin) public onlyAdmin {126      delete admins[admin];127    }128129    /**130     * Place an NFT or RFT token for sale. It must be pre-approved for transfers by this contract address.131     *132     * @param collectionId: ID of the token collection133     * @param tokenId: ID of the token134     * @param price: Price (with proper network currency decimals)135     * @param amount: Number of token fractions to list (must always be 1 for NFT)136     * @param seller: The seller cross-address (the beneficiary account to receive payment, may be different from transaction sender)137     */138    function put(139        uint32 collectionId,140        uint32 tokenId,141        uint256 price,142        uint32 amount,143        CrossAddress memory seller144    ) public validCrossAddress(seller.eth, seller.sub) {145        if (price == 0) {146          revert InvalidArgument("price must not be zero");147        }148        if (amount == 0) {149          revert InvalidArgument("amount must not be zero");150        }151152        if (orders[collectionId][tokenId].price > 0) {153            revert TokenIsAlreadyOnSale();154        }155156        IERC721 erc721 = getErc721(collectionId);157158        if (erc721.ownerOf(tokenId) != msg.sender) {159          revert SellerIsNotOwner();160        }161162        if (erc721.getApproved(tokenId) != address(this)) {163          revert TokenIsNotApproved();164        }165166        Order memory order = Order(167            0,168            collectionId,169            tokenId,170            amount,171            price,172            seller173        );174175        order.id = idCount++;176        orders[collectionId][tokenId] = order;177178        emit TokenIsUpForSale(version, order);179    }180181    /**182     * Get information about the listed token order183     *184     * @param collectionId: ID of the token collection185     * @param tokenId: ID of the token186     * @return The order information187     */188    function getOrder(189        uint32 collectionId,190        uint32 tokenId191    ) external view returns (Order memory) {192        return orders[collectionId][tokenId];193    }194195    /**196     * Revoke the token from the sale. Only the original lister can use this method.197     *198     * @param collectionId: ID of the token collection199     * @param tokenId: ID of the token200     * @param amount: Number of token fractions to de-list (must always be 1 for NFT)201     */202    function revoke(203        uint32 collectionId,204        uint32 tokenId,205        uint32 amount206    ) external {207        if (amount == 0) {208          revert InvalidArgument("amount must not be zero");209        }210211        Order memory order = orders[collectionId][tokenId];212213        if (order.price == 0) {214          revert OrderNotFound();215        }216217        if (amount > order.amount) {218          revert TooManyAmountRequested();219        }220221        IERC721 erc721 = getErc721(collectionId);222223        address ethAddress;224        if (order.seller.eth != address(0)) {225          ethAddress = order.seller.eth;226        } else {227          ethAddress = payable(address(uint160(order.seller.sub >> 96)));228        }229        if (erc721.ownerOf(tokenId) != ethAddress) {230          revert SellerIsNotOwner();231        }232233        order.amount -= amount;234        if (order.amount == 0) {235            delete orders[collectionId][tokenId];236        } else {237            orders[collectionId][tokenId] = order;238        }239240        emit TokenRevoke(version, order, amount);241    }242243    /**244     * Test if the token is still approved to be transferred by this contract and delete the order if not.245     *246     * @param collectionId: ID of the token collection247     * @param tokenId: ID of the token248     */249    function checkApproved(uint32 collectionId, uint32 tokenId) public onlyAdmin {250        Order memory order = orders[collectionId][tokenId];251        if (order.price == 0) {252            revert OrderNotFound();253        }254255        IERC721 erc721 = getErc721(collectionId);256257        if (erc721.getApproved(tokenId) != address(this) || erc721.ownerOf(tokenId) != getAddressFromCrossAccount(order.seller)) {258          uint32 amount = order.amount;259          order.amount = 0;260          emit TokenRevoke(version, order, amount);261262          delete orders[collectionId][tokenId];263        } else {264          emit TokenIsApproved(version, order);265        }266    }267268    function getAddressFromCrossAccount(CrossAddress memory account) private pure returns (address) {269        if (account.eth != address(0)) {270            return account.eth;271        } else {272            return address(uint160(account.sub >> 96));273        }274    }275276    /**277     * Revoke the token from the sale. Only the contract admin can use this method.278     *279     * @param collectionId: ID of the token collection280     * @param tokenId: ID of the token281     */282    function revokeAdmin(uint32 collectionId, uint32 tokenId) public onlyAdmin {283        Order memory order = orders[collectionId][tokenId];284        if (order.price == 0) {285          revert OrderNotFound();286        }287288        uint32 amount = order.amount;289        order.amount = 0;290        emit TokenRevoke(version, order, amount);291292        delete orders[collectionId][tokenId];293    }294295    /**296     * Buy a token (partially for an RFT).297     *298     * @param collectionId: ID of the token collection299     * @param tokenId: ID of the token300     * @param amount: Number of token fractions to buy (must always be 1 for NFT)301     * @param buyer: Cross-address of the buyer, eth part must be equal to the transaction signer address302     */303    function buy(304        uint32 collectionId,305        uint32 tokenId,306        uint32 amount,307        CrossAddress memory buyer308    ) public payable validCrossAddress(buyer.eth, buyer.sub) nonReentrant {309        if (msg.value == 0) {310          revert InvalidArgument("msg.value must not be zero");311        }312        if (amount == 0) {313          revert InvalidArgument("amount must not be zero");314        }315316        Order memory order = orders[collectionId][tokenId];317        if (order.price == 0) {318            revert OrderNotFound();319        }320321        if (amount > order.amount) {322            revert TooManyAmountRequested();323        }324325        uint256 totalValue = order.price * amount;326        uint256 feeValue = (totalValue * marketFee) / 100;327328        if (msg.value < totalValue) {329            revert NotEnoughMoneyError();330        }331332        IERC721 erc721 = getErc721(order.collectionId);333        if (erc721.getApproved(tokenId) != address(this)) {334          revert TokenIsNotApproved();335        }336337        order.amount -= amount;338        if (order.amount == 0) {339            delete orders[collectionId][tokenId];340        } else {341            orders[collectionId][tokenId] = order;342        }343344        address collectionAddress = collectionHelpers.collectionAddress(collectionId);345        UniqueNFT nft = UniqueNFT(collectionAddress);346347        nft.transferFromCross(348          order.seller,349          buyer,350          order.tokenId351        );352353        (uint256 totalRoyalty, RoyaltyAmount[] memory royalties) = sendRoyalties(collectionAddress, tokenId, totalValue - feeValue);354355        if (totalRoyalty >= totalValue - feeValue) {356          revert InvalidRoyaltiesError(totalRoyalty);357        }358359        sendMoney(order.seller, totalValue - feeValue - totalRoyalty);360361        if (msg.value > totalValue) {362            sendMoney(buyer, msg.value - totalValue);363        }364365        emit TokenIsPurchased(version, order, amount, buyer, royalties);366    }367368    function sendMoney(CrossAddress memory to, uint256 money) private {369      address collectionAddress = collectionHelpers.collectionAddress(0);370371      UniqueFungible fungible = UniqueFungible(collectionAddress);372373      CrossAddressF memory fromF = CrossAddressF(address(this), 0);374      CrossAddressF memory toF = CrossAddressF(to.eth, to.sub);375376      fungible.transferFromCross(fromF, toF, money);377    }378379    function sendRoyalties(address collection, uint tokenId, uint sellPrice) private returns (uint256, RoyaltyAmount[] memory) {380      RoyaltyAmount[] memory royalties = UniqueRoyaltyHelper.calculate(collection, tokenId, sellPrice);381382      uint256 totalRoyalty = 0;383384      for (uint256 i=0; i<royalties.length; i++) {385        RoyaltyAmount memory royalty = royalties[i];386387        totalRoyalty += royalty.amount;388389        sendMoney(royalty.crossAddress, royalty.amount);390      }391392      return (totalRoyalty, royalties);393    }394395    function withdraw(address transferTo) public onlyOwner {396        uint256 balance = address(this).balance;397398        if (balance > 0) {399            payable(transferTo).transfer(balance);400        }401    }402}
modifiedtests/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,7 +16,7 @@
 
 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';
@@ -51,6 +51,18 @@
           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`,
         },
@@ -94,26 +106,62 @@
   });
 
   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);
+    await contractHelpers.methods.selfSponsoredEnable(market.options.address).send({from: marketOwner});
+    await helper.eth.transferBalanceFromSubstrate(donor, market.options.address, 10n);
 
+    // TODO: this should work too, instead of selfSponsoring!
+    // await contractHelpers.methods.setSponsor(market.options.address, marketOwner).send({from: marketOwner})
+    // await contractHelpers.methods.confirmSponsorship(market.options.address);
+    
+    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);
+    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});
+    
+    // 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, 1, 1, sellerCross).send({from: sellerCross.eth});
+    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);
+    console.log('before buy');
+
+    // 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);